Skip to content

Commit 2ccb953

Browse files
committed
Fix #267 support jumping to tag + offset
1 parent 76858e1 commit 2ccb953

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"onCommand:vscode-objectscript.export",
5454
"onCommand:vscode-objectscript.compile",
5555
"onCommand:vscode-objectscript.viewOthers",
56+
"onCommand:vscode-objectscript.jumpToTagAndOffset",
5657
"onCommand:vscode-objectscript.previewXml",
5758
"onCommand:vscode-objectscript.explorer.refresh",
5859
"onCommand:vscode-objectscript.explorer.open",
@@ -520,6 +521,11 @@
520521
"category": "ObjectScript",
521522
"icon": "$(refresh)"
522523
},
524+
{
525+
"category": "ObjectScript",
526+
"command": "vscode-objectscript.jumpToTagAndOffset",
527+
"title": "Jump to Tag + Offset"
528+
},
523529
{
524530
"category": "ObjectScript",
525531
"command": "vscode-objectscript.viewOthers",

src/commands/jumpToTagAndOffset.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import * as vscode from "vscode";
2+
import { config } from "../extension";
3+
import { currentFile } from "../utils";
4+
5+
export async function jumpToTagAndOffset(): Promise<void> {
6+
const file = currentFile();
7+
if (!file) {
8+
return;
9+
}
10+
if (!config("conn").active) {
11+
return;
12+
}
13+
const nameMatch = file.name.match(/(.*)\.(int|mac)$/i);
14+
if (!nameMatch) {
15+
return;
16+
}
17+
const document = vscode.window.activeTextEditor?.document;
18+
if (!document) {
19+
return;
20+
}
21+
22+
// Build map of labels in routine
23+
const map = new Map();
24+
const options = [];
25+
for (let i = 0; i < document.lineCount; i++) {
26+
const labelMatch = document.lineAt(i).text.match(/^(%?\w+).*/);
27+
if (labelMatch) {
28+
map.set(labelMatch[1], i);
29+
options.push(labelMatch[1]);
30+
}
31+
}
32+
33+
const items: vscode.QuickPickItem[] = options.map((option) => {
34+
return { label: option };
35+
});
36+
const quickPick = vscode.window.createQuickPick();
37+
quickPick.title = "Jump to Tag + Offset";
38+
quickPick.items = items;
39+
quickPick.canSelectMany = false;
40+
quickPick.onDidChangeSelection((_) => {
41+
quickPick.value = quickPick.selectedItems[0].label;
42+
});
43+
quickPick.onDidAccept((_) => {
44+
const editor = vscode.window.activeTextEditor;
45+
if (!editor) {
46+
quickPick.hide();
47+
return;
48+
}
49+
const parts = quickPick.value.split("+");
50+
let offset = 0;
51+
if (!map.has(parts[0])) {
52+
if (parts[0] !== "") {
53+
return;
54+
}
55+
} else {
56+
offset += parseInt(map.get(parts[0]), 10);
57+
}
58+
if (parts.length > 1) {
59+
offset += parseInt(parts[1], 10);
60+
}
61+
const line = editor.document.lineAt(offset);
62+
const range = new vscode.Range(line.range.start, line.range.start);
63+
editor.selection = new vscode.Selection(range.start, range.start);
64+
editor.revealRange(range, vscode.TextEditorRevealType.AtTop);
65+
quickPick.hide();
66+
});
67+
quickPick.show();
68+
}

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
mainSourceControlMenu,
4242
} from "./commands/studio";
4343
import { addServerNamespaceToWorkspace } from "./commands/addServerNamespaceToWorkspace";
44+
import { jumpToTagAndOffset } from "./commands/jumpToTagAndOffset";
4445
import { connectFolderToServerNamespace } from "./commands/connectFolderToServerNamespace";
4546

4647
import { getLanguageConfiguration } from "./languageConfiguration";
@@ -398,6 +399,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
398399
});
399400

400401
posPanel = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 0);
402+
posPanel.command = "vscode-objectscript.jumpToTagAndOffset";
401403
posPanel.show();
402404

403405
panel = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1);
@@ -613,6 +615,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
613615
if (value) return value.label;
614616
});
615617
}),
618+
vscode.commands.registerCommand("vscode-objectscript.jumpToTagAndOffset", jumpToTagAndOffset),
616619
vscode.commands.registerCommand("vscode-objectscript.viewOthers", viewOthers),
617620
vscode.commands.registerCommand("vscode-objectscript.serverCommands.sourceControl", mainSourceControlMenu),
618621
vscode.commands.registerCommand(

0 commit comments

Comments
 (0)