From 7a9cab4722bcf2321e324dd1db53a1726135cca1 Mon Sep 17 00:00:00 2001 From: Andrew Nolte Date: Sun, 3 Nov 2024 13:32:47 -0500 Subject: [PATCH] improve hover on tasks/functions --- src/analysis/Symbol.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/analysis/Symbol.ts b/src/analysis/Symbol.ts index e3207c7..7f03720 100644 --- a/src/analysis/Symbol.ts +++ b/src/analysis/Symbol.ts @@ -76,6 +76,23 @@ export class Symbol { return this.idRange } + getSemicolonRange(): vscode.Range { + // leading comments + id range + to next semicolon. Used for hovers + const idRange = this.getIdRange() + const nextSemi = this.doc.getText().indexOf(';', this.doc.offsetAt(idRange.end)) + let start = idRange.start + while ( + start.line > 1 && + this.doc + .lineAt(start.line - 1) + .text.trimStart() + .startsWith('//') + ) { + start = start.translate(-1) + } + return new vscode.Range(start, this.doc.positionAt(nextSemi)) + } + getFullRange(): vscode.Range { if (this.fullRange !== undefined) { return this.fullRange @@ -123,8 +140,7 @@ export class Symbol { return this.fullRange } - getUnindented(): string { - let range = this.getFullRange() + getUnindented(range: vscode.Range): string { let leadingSpaces = this.doc.lineAt(range.start.line).text.match(/^ */)?.[0].length ?? 0 let outline = [] @@ -180,7 +196,9 @@ export class Symbol { getHoverText(): string { if (this.type === 'typedef' || this.type === 'instance' || this.isMacro()) { - return this.getUnindented() + return this.getUnindented(this.getFullRange()) + } else if (this.type === 'task' || this.type === 'function') { + return this.getUnindented(this.getSemicolonRange()) } let code = this.doc