From 5643bee64bfa09ae3fbe56a3aece36d031799dae Mon Sep 17 00:00:00 2001 From: Stephen M Moraco Date: Mon, 17 Jul 2023 22:30:24 -0600 Subject: [PATCH] repair signature help, hover text PUB / PRI signatures --- spin2/CHANGELOG.md | 8 +++++-- spin2/package.json | 2 +- spin2/src/spin.semantic.findings.ts | 34 +++++++++++++++++------------ spin2/src/spin1.hover.behavior.ts | 20 +++++++++++++++-- spin2/src/spin1.signature.help.ts | 14 +++++++++++- spin2/src/spin2.hover.behavior.ts | 20 +++++++++++++++-- spin2/src/spin2.signature.help.ts | 14 +++++++++++- 7 files changed, 89 insertions(+), 23 deletions(-) diff --git a/spin2/CHANGELOG.md b/spin2/CHANGELOG.md index 5c28a32..cf6b8ce 100644 --- a/spin2/CHANGELOG.md +++ b/spin2/CHANGELOG.md @@ -13,8 +13,6 @@ Work to appear in upcoming releases: Possible next additions: -- Add Signature popups for `PUB`, `PRI` and Spin2 method signatures (help text) -- Add Hover popups for pasm instructions (help text for each instruction) - Update theme to work better with a couple common languages we use near our P2 projects (e.g., Python) - Add light theme - Investigate and possibly add unique coloring for method pointers @@ -22,6 +20,12 @@ Possible next additions: - Add new-file templates as Snippets - Add additional Snippets as the community identifies them +## [1.9.9] 2023-07-17 + +General repairs to Signature Help (P1 and P2) + +- P1 & P2: Repair signature help - signatures shown for users PUB/PRI methods (ensure hover pop-ups and signature pop-ups show same for PRI/PUB signatures) + ## [1.9.8] 2023-07-17 General repairs to Hover Support and Signature Help (P1 and P2) diff --git a/spin2/package.json b/spin2/package.json index 2d663cf..13da943 100644 --- a/spin2/package.json +++ b/spin2/package.json @@ -3,7 +3,7 @@ "displayName": "Spin2", "description": "Spin2/Pasm2 Syntax/Semantic Highlighting w/Code Outline and Custom tabbing support", "icon": "images/Propeller.ico", - "version": "1.9.8", + "version": "1.9.9", "publisher": "IronSheepProductionsLLC", "repository": { "type": "git", diff --git a/spin2/src/spin.semantic.findings.ts b/spin2/src/spin.semantic.findings.ts index c194503..786e217 100644 --- a/spin2/src/spin.semantic.findings.ts +++ b/spin2/src/spin.semantic.findings.ts @@ -19,6 +19,7 @@ export interface ITokenDescription { token: RememberedToken | undefined; declarationLine: number; declarationComment: string | undefined; + signature: string | undefined; relatedFilename: string | undefined; relatedObjectName: string | undefined; relatedMethodName: string | undefined; @@ -125,7 +126,7 @@ export class DocumentFindings { for (let blockComment of this.blockComments) { // only one will match... if (blockComment.includesLine(lineNumber)) { - const canUseThisComment: boolean = this.isUsableComment(blockComment.isDocComment, eFilter); + const canUseThisComment: boolean = this._isUsableComment(blockComment.isDocComment, eFilter); if (canUseThisComment) { desiredComment = blockComment.commentAsMarkDown(); } @@ -141,7 +142,7 @@ export class DocumentFindings { if (this.fakeComments.length > 0) { for (let fakeComment of this.fakeComments) { if (fakeComment.includesLine(lineNumber)) { - const canUseThisComment: boolean = this.isUsableComment(fakeComment.isDocComment, eFilter); + const canUseThisComment: boolean = this._isUsableComment(fakeComment.isDocComment, eFilter); if (canUseThisComment) { desiredComment = fakeComment.commentAsMarkDown(); } @@ -151,7 +152,7 @@ export class DocumentFindings { } return desiredComment; } - private isUsableComment(bHaveDocComment: boolean, efilter: eCommentFilter): boolean { + private _isUsableComment(bHaveDocComment: boolean, efilter: eCommentFilter): boolean { const canUsestatus: boolean = (bHaveDocComment && (efilter == eCommentFilter.allComments || efilter == eCommentFilter.docCommentOnly)) || (!bHaveDocComment && (efilter == eCommentFilter.allComments || efilter == eCommentFilter.nondocCommentOnly)) @@ -181,6 +182,7 @@ export class DocumentFindings { adjustedName: tokenName, declarationLine: 0, declarationComment: undefined, + signature: undefined, relatedFilename: undefined, relatedObjectName: undefined, relatedMethodName: undefined, @@ -206,6 +208,7 @@ export class DocumentFindings { findings.interpretation = details.interpretation; findings.scope = details.scope; findings.adjustedName = details.name; + const bIsMethod: boolean = findings.token.type == "method"; if (declInfo) { // and decorate with declaration line number findings.declarationLine = declInfo.lineIndex; @@ -216,14 +219,14 @@ export class DocumentFindings { findings.relatedObjectName = declInfo.reference; } } - const bIsMethod: boolean = findings.token.type == "method"; - const bIsDebugDisplay: boolean = findings.token.type == "debugDisplay"; const bIsPublic: boolean = findings.token.modifiers.includes("static") ? false : true; if (bIsMethod) { const commentType: eCommentFilter = bIsPublic ? eCommentFilter.docCommentOnly : eCommentFilter.nondocCommentOnly; - const nonBlankLineNbr: number = this.locateNonBlankLineAfter(findings.declarationLine + 1); + const nonBlankLineNbr: number = this._locateNonBlankLineAfter(findings.declarationLine + 1); findings.declarationComment = this.blockCommentMDFromLine(nonBlankLineNbr, commentType); - this._logTokenMessage(` -- FND-DBGxxxTOK findings.declarationComment=[${findings.declarationComment}], declInfo.comment=[${findings.relatedFilename}]`); + this._logTokenMessage( + ` -- FND-DBGxxxTOK findings.signature=[${findings.signature}], findings.declarationComment=[${findings.declarationComment}], declInfo.comment=[${findings.relatedFilename}]` + ); // if no block doc comment then we can substitute a preceeding or trailing doc comment for method const canUseAlternateComment: boolean = bIsPublic == false || (bIsPublic == true && declInfo.isDocComment) ? true : false; if (!findings.declarationComment && canUseAlternateComment && declInfo.comment && declInfo.comment.length > 0) { @@ -272,6 +275,7 @@ export class DocumentFindings { adjustedName: tokenName, declarationLine: 0, declarationComment: undefined, + signature: undefined, relatedFilename: undefined, relatedObjectName: undefined, relatedMethodName: undefined, @@ -320,6 +324,7 @@ export class DocumentFindings { findings.interpretation = details.interpretation; findings.scope = details.scope; findings.adjustedName = details.name; + const bIsMethod: boolean = findings.token.type == "method"; if (declInfo) { // and decorate with declaration line number findings.declarationLine = declInfo.lineIndex; @@ -330,13 +335,14 @@ export class DocumentFindings { findings.relatedObjectName = declInfo.reference; } } - const bIsMethod: boolean = findings.token.type == "method"; const bIsPublic: boolean = findings.token.modifiers.includes("static") ? false : true; if (bIsMethod) { const commentType: eCommentFilter = bIsPublic ? eCommentFilter.docCommentOnly : eCommentFilter.nondocCommentOnly; - const nonBlankLineNbr: number = this.locateNonBlankLineAfter(findings.declarationLine + 1); + const nonBlankLineNbr: number = this._locateNonBlankLineAfter(findings.declarationLine + 1); findings.declarationComment = this.blockCommentMDFromLine(nonBlankLineNbr, commentType); - this._logTokenMessage(` -- FND-xxxTOK findings.declarationComment=[${findings.declarationComment}], declInfo.comment=[${findings.relatedFilename}]`); + this._logTokenMessage( + ` -- FND-xxxTOK findings.signature=[${findings.signature}], findings.declarationComment=[${findings.declarationComment}], declInfo.comment=[${findings.relatedFilename}]` + ); // if no block doc comment then we can substitute a preceeding or trailing doc comment for method const canUseAlternateComment: boolean = bIsPublic == false || (bIsPublic == true && declInfo.isDocComment) ? true : false; if (!findings.declarationComment && canUseAlternateComment && declInfo.comment && declInfo.comment.length > 0) { @@ -374,7 +380,7 @@ export class DocumentFindings { return findings; } - private locateNonBlankLineAfter(lineNbr: number): number { + private _locateNonBlankLineAfter(lineNbr: number): number { let desiredNumber: number = lineNbr; const editor = vscode?.window.activeTextEditor!; const document = editor.document!; @@ -1161,7 +1167,7 @@ export class RememberedComment { } this._lines[idx] = trimmedLine; } - this.clearLinesIfAllBlank(); + this._clearLinesIfAllBlank(); } public closeAsSingleLineBlock(lineNumber: number) { @@ -1176,7 +1182,7 @@ export class RememberedComment { } this._lines[idx] = trimmedLine; } - this.clearLinesIfAllBlank(); + this._clearLinesIfAllBlank(); } public closeAsSingleLine() { @@ -1237,7 +1243,7 @@ export class RememberedComment { return interpString; } - private clearLinesIfAllBlank() { + private _clearLinesIfAllBlank() { // emtpy our line aray if it's really nothing worthwhile let bHaveNonBlank: boolean = false; for (let idx = 0; idx < this._lines.length; idx++) { diff --git a/spin2/src/spin1.hover.behavior.ts b/spin2/src/spin1.hover.behavior.ts index ffdc775..9faebba 100644 --- a/spin2/src/spin1.hover.behavior.ts +++ b/spin2/src/spin1.hover.behavior.ts @@ -127,6 +127,15 @@ export class Spin1HoverProvider implements HoverProvider { return this.getSymbolDetails(searchDetails, token, false); } + private getSignatureWithoutLocals(line: string): string { + let desiredLinePortion: string = line; + const localOffset: number = line.indexOf("|"); + if (localOffset != -1) { + desiredLinePortion = line.substring(0, localOffset).trim(); + } + return desiredLinePortion; + } + private getSymbolDetails(input: IDefinitionInput, token: vscode.CancellationToken, useTags: boolean): Promise { if (token) { } // kill compiler warns for now... @@ -175,7 +184,7 @@ export class Spin1HoverProvider implements HoverProvider { this._logMessage( `+ Hvr: token=[${input.word}], interpRaw=(${tokenFindings.tokenRawInterp}), scope=[${tokenFindings.scope}], interp=[${tokenFindings.interpretation}], adjName=[${tokenFindings.adjustedName}]` ); - this._logMessage(`+ Hvr: file=[${tokenFindings.relatedFilename}], declCmt=(${tokenFindings.declarationComment})]`); + this._logMessage(`+ Hvr: file=[${tokenFindings.relatedFilename}], declCmt=(${tokenFindings.declarationComment})], sig=(${tokenFindings.signature})]`); } else { this._logMessage(`+ Hvr: get token failed?!!`); } @@ -198,9 +207,16 @@ export class Spin1HoverProvider implements HoverProvider { // load CODE section of hover // const isMethod: boolean = typeString.includes("method"); + if (isMethod && !isSignatureLine) { + tokenFindings.signature = this.getSignatureWithoutLocals(nonCommentDecl); + } if (isMethod) { if (tokenFindings.scope.includes("object")) { - defInfo.declarationlines = [`(${scopeString} ${typeString}) ${nameString}`]; + if (typeString.includes("method")) { + defInfo.declarationlines = [`(${scopeString} ${typeString}) ${tokenFindings.signature}`]; + } else { + defInfo.declarationlines = [`(${scopeString} ${typeString}) ${nameString}`]; + } } else if (isSignatureLine) { // for method declaration use declaration line defInfo.declarationlines = [sourceLine]; diff --git a/spin2/src/spin1.signature.help.ts b/spin2/src/spin1.signature.help.ts index 8f4eafa..5edaccb 100644 --- a/spin2/src/spin1.signature.help.ts +++ b/spin2/src/spin1.signature.help.ts @@ -81,7 +81,10 @@ export class Spin1SignatureHelpProvider implements SignatureHelpProvider { let si: SignatureInformation | undefined; if (defInfo.doc?.includes("Custom Method")) { // use this for user(custom) methods - sig = nonCommentDecl; + const methodType: string = nonCommentDecl.substring(0, 3).toUpperCase(); + const isPrivate: boolean = methodType == "PRI"; + const sigScope: string = isPrivate ? "private" : "public"; + sig = this.signatureWithOutLocals(`(object ${sigScope} method) ` + nonCommentDecl); const methDescr: string = this.getMethodDescriptionFromDoc(defInfo.doc); si = new SignatureInformation(sig, methDescr); if (si) { @@ -110,6 +113,15 @@ export class Spin1SignatureHelpProvider implements SignatureHelpProvider { } } + private signatureWithOutLocals(signature: string): string { + let trimmedSignature: string = signature; + const localIndicaPosn: number = trimmedSignature.indexOf("|"); + if (localIndicaPosn != -1) { + trimmedSignature = trimmedSignature.substring(0, localIndicaPosn).replace(/\s+$/, ""); + } + return trimmedSignature; + } + private getParametersAndReturnTypeFromParameterStringAr(paramList: string[] | undefined): vscode.ParameterInformation[] { // convert list of parameters frombuilt-in description tables to vscode ParameterInformation's let parameterDetails: vscode.ParameterInformation[] = []; diff --git a/spin2/src/spin2.hover.behavior.ts b/spin2/src/spin2.hover.behavior.ts index d8882b0..d744f09 100644 --- a/spin2/src/spin2.hover.behavior.ts +++ b/spin2/src/spin2.hover.behavior.ts @@ -127,6 +127,15 @@ export class Spin2HoverProvider implements HoverProvider { return this.getSymbolDetails(searchDetails, token, false); } + private getSignatureWithoutLocals(line: string): string { + let desiredLinePortion: string = line; + const localOffset: number = line.indexOf("|"); + if (localOffset != -1) { + desiredLinePortion = line.substring(0, localOffset).trim(); + } + return desiredLinePortion; + } + private getSymbolDetails(input: IDefinitionInput, token: vscode.CancellationToken, useTags: boolean): Promise { if (token) { } // kill compiler warns for now... @@ -188,7 +197,7 @@ export class Spin2HoverProvider implements HoverProvider { this._logMessage( `+ Hvr: token=[${input.word}], interpRaw=(${tokenFindings.tokenRawInterp}), scope=[${tokenFindings.scope}], interp=[${tokenFindings.interpretation}], adjName=[${tokenFindings.adjustedName}]` ); - this._logMessage(`+ Hvr: file=[${tokenFindings.relatedFilename}], declCmt=(${tokenFindings.declarationComment})]`); + this._logMessage(`+ Hvr: file=[${tokenFindings.relatedFilename}], declCmt=[${tokenFindings.declarationComment}], sig=[${tokenFindings.signature}]`); } else { this._logMessage(`+ Hvr: get token failed?!!`); } @@ -212,8 +221,15 @@ export class Spin2HoverProvider implements HoverProvider { // const isMethod: boolean = typeString.includes("method"); if (isMethod) { + if (isMethod && !isSignatureLine) { + tokenFindings.signature = this.getSignatureWithoutLocals(nonCommentDecl); + } if (tokenFindings.scope.includes("object")) { - defInfo.declarationlines = [`(${scopeString} ${typeString}) ${nameString}`]; + if (typeString.includes("method")) { + defInfo.declarationlines = [`(${scopeString} ${typeString}) ${tokenFindings.signature}`]; + } else { + defInfo.declarationlines = [`(${scopeString} ${typeString}) ${nameString}`]; + } } else if (isSignatureLine) { // for method declaration use declaration line defInfo.declarationlines = [sourceLine]; diff --git a/spin2/src/spin2.signature.help.ts b/spin2/src/spin2.signature.help.ts index a1d982b..d0cbff1 100644 --- a/spin2/src/spin2.signature.help.ts +++ b/spin2/src/spin2.signature.help.ts @@ -82,7 +82,10 @@ export class Spin2SignatureHelpProvider implements SignatureHelpProvider { let si: SignatureInformation | undefined; if (defInfo.doc?.includes("Custom Method")) { // use this for user(custom) methods - sig = nonCommentDecl; + const methodType: string = nonCommentDecl.substring(0, 3).toUpperCase(); + const isPrivate: boolean = methodType == "PRI"; + const sigScope: string = isPrivate ? "private" : "public"; + sig = this.signatureWithOutLocals(`(object ${sigScope} method) ` + nonCommentDecl); const methDescr: string = this.getMethodDescriptionFromDoc(defInfo.doc); si = new SignatureInformation(sig, methDescr); if (si) { @@ -111,6 +114,15 @@ export class Spin2SignatureHelpProvider implements SignatureHelpProvider { } } + private signatureWithOutLocals(signature: string): string { + let trimmedSignature: string = signature; + const localIndicaPosn: number = trimmedSignature.indexOf("|"); + if (localIndicaPosn != -1) { + trimmedSignature = trimmedSignature.substring(0, localIndicaPosn).replace(/\s+$/, ""); + } + return trimmedSignature; + } + private getParametersAndReturnTypeFromParameterStringAr(paramList: string[] | undefined): vscode.ParameterInformation[] { // convert list of parameters frombuilt-in description tables to vscode ParameterInformation's let parameterDetails: vscode.ParameterInformation[] = [];