Skip to content

Commit c69cd24

Browse files
authored
Merge pull request #351 from timleavitt/fix-267-jump-to-tag-and-offset
Jump to tag and offset
2 parents 4c978db + da7c115 commit c69cd24

File tree

3 files changed

+73
-0
lines changed

3 files changed

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

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)