Skip to content

Commit d636a9b

Browse files
authored
Use DocumentSymbolProvider for tag+offset status bar item (#959)
1 parent 5c2bd2b commit d636a9b

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/commands/jumpToTagAndOffset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export async function jumpToTagAndOffset(): Promise<void> {
88
}
99
const nameMatch = file.name.match(/(.*)\.(int|mac)$/i);
1010
if (!nameMatch) {
11-
vscode.window.showWarningMessage("Jump to Tag and Offset only supports .int and .mac routines.");
11+
vscode.window.showWarningMessage("Jump to Tag and Offset only supports .int and .mac routines.", "Dismiss");
1212
return;
1313
}
1414
const document = vscode.window.activeTextEditor?.document;

src/extension.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -656,19 +656,25 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
656656
return;
657657
}
658658
const [, routine] = nameMatch;
659-
const line = event.selections[0].start.line;
660659
let label = "";
661660
let pos = 0;
662-
for (let i = line; i > 0; i--) {
663-
const labelMatch = document.lineAt(i).text.match(/^(%?\w+).*/);
664-
if (labelMatch) {
665-
[, label] = labelMatch;
666-
break;
667-
}
668-
pos++;
669-
}
670-
event.textEditor.document.getText;
671-
posPanel.text = `${label}${pos > 0 ? "+" + pos : ""}^${routine}`;
661+
vscode.commands
662+
.executeCommand<vscode.DocumentSymbol[]>("vscode.executeDocumentSymbolProvider", document.uri)
663+
.then((symbols) => {
664+
const cursor = event.selections[0].active;
665+
if (symbols.length == 0 || cursor.isBefore(symbols[0].range.start)) {
666+
pos = cursor.line - 1;
667+
} else {
668+
for (const symbol of symbols) {
669+
if (symbol.range.contains(cursor)) {
670+
label = symbol.name;
671+
pos = cursor.line - symbol.range.start.line;
672+
break;
673+
}
674+
}
675+
}
676+
posPanel.text = `${label}${pos > 0 ? "+" + pos : ""}^${routine}`;
677+
});
672678
});
673679

674680
const documentSelector = (...list) =>

0 commit comments

Comments
 (0)