Skip to content

Commit

Permalink
improve hover on tasks/functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewNolte committed Nov 3, 2024
1 parent ce5bf99 commit 7a9cab4
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/analysis/Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7a9cab4

Please sign in to comment.