Skip to content

Commit

Permalink
repair signature help, hover text PUB / PRI signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed Jul 18, 2023
1 parent 573fedf commit 5643bee
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 23 deletions.
8 changes: 6 additions & 2 deletions spin2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ 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
- Add spin2 instruction templates as Snippets (_for instructions with two or more parameters_)
- 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)
Expand Down
2 changes: 1 addition & 1 deletion spin2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 20 additions & 14 deletions spin2/src/spin.semantic.findings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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))
Expand Down Expand Up @@ -181,6 +182,7 @@ export class DocumentFindings {
adjustedName: tokenName,
declarationLine: 0,
declarationComment: undefined,
signature: undefined,
relatedFilename: undefined,
relatedObjectName: undefined,
relatedMethodName: undefined,
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -272,6 +275,7 @@ export class DocumentFindings {
adjustedName: tokenName,
declarationLine: 0,
declarationComment: undefined,
signature: undefined,
relatedFilename: undefined,
relatedObjectName: undefined,
relatedMethodName: undefined,
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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!;
Expand Down Expand Up @@ -1161,7 +1167,7 @@ export class RememberedComment {
}
this._lines[idx] = trimmedLine;
}
this.clearLinesIfAllBlank();
this._clearLinesIfAllBlank();
}

public closeAsSingleLineBlock(lineNumber: number) {
Expand All @@ -1176,7 +1182,7 @@ export class RememberedComment {
}
this._lines[idx] = trimmedLine;
}
this.clearLinesIfAllBlank();
this._clearLinesIfAllBlank();
}

public closeAsSingleLine() {
Expand Down Expand Up @@ -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++) {
Expand Down
20 changes: 18 additions & 2 deletions spin2/src/spin1.hover.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDefinitionInfo | null> {
if (token) {
} // kill compiler warns for now...
Expand Down Expand Up @@ -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?!!`);
}
Expand All @@ -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];
Expand Down
14 changes: 13 additions & 1 deletion spin2/src/spin1.signature.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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[] = [];
Expand Down
20 changes: 18 additions & 2 deletions spin2/src/spin2.hover.behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDefinitionInfo | null> {
if (token) {
} // kill compiler warns for now...
Expand Down Expand Up @@ -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?!!`);
}
Expand All @@ -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];
Expand Down
14 changes: 13 additions & 1 deletion spin2/src/spin2.signature.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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[] = [];
Expand Down

0 comments on commit 5643bee

Please sign in to comment.