Skip to content

Commit 6a53a7a

Browse files
authored
Implement Open Error Location... command (#1095)
1 parent 93ad1ed commit 6a53a7a

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"onCommand:vscode-objectscript.newFile.rule",
8787
"onCommand:vscode-objectscript.newFile.businessService",
8888
"onCommand:vscode-objectscript.newFile.dtl",
89+
"onCommand:vscode-objectscript.openErrorLocation",
8990
"onLanguage:objectscript",
9091
"onLanguage:objectscript-int",
9192
"onLanguage:objectscript-class",
@@ -327,6 +328,10 @@
327328
{
328329
"command": "vscode-objectscript.showRESTDebugWebview",
329330
"when": "editorLangId =~ /^objectscript/ && vscode-objectscript.connectActive"
331+
},
332+
{
333+
"command": "vscode-objectscript.openErrorLocation",
334+
"when": "vscode-objectscript.connectActive && workspaceFolderCount != 0"
330335
}
331336
],
332337
"view/title": [
@@ -1083,6 +1088,11 @@
10831088
"category": "ObjectScript",
10841089
"command": "vscode-objectscript.showRESTDebugWebview",
10851090
"title": "Debug REST Service..."
1091+
},
1092+
{
1093+
"category": "ObjectScript",
1094+
"command": "vscode-objectscript.openErrorLocation",
1095+
"title": "Open Error Location..."
10861096
}
10871097
],
10881098
"keybindings": [

src/commands/jumpToTagAndOffset.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
2-
import { currentFile } from "../utils";
2+
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
3+
import { currentFile, outputChannel } from "../utils";
34

45
export async function jumpToTagAndOffset(): Promise<void> {
56
const file = currentFile();
@@ -63,3 +64,55 @@ export async function jumpToTagAndOffset(): Promise<void> {
6364
});
6465
quickPick.show();
6566
}
67+
68+
/** Prompt the user for an error location of the form `label+offset^routine`, then open it. */
69+
export async function openErrorLocation(): Promise<void> {
70+
// Prompt the user for a location
71+
const regex = /^(%?[\p{L}\d]+)?(?:\+(\d+))?\^(%?[\p{L}\d.]+)$/u;
72+
const location = await vscode.window.showInputBox({
73+
title: "Enter the location to open",
74+
ignoreFocusOut: true,
75+
placeHolder: "label+offset^routine",
76+
validateInput: (v) => (regex.test(v.trim()) ? undefined : "Input is not in the format 'label+offset^routine'"),
77+
});
78+
if (!location) {
79+
return;
80+
}
81+
const [, label, offset, routine] = location.trim().match(regex);
82+
// Get the uri for the routine
83+
const uri = DocumentContentProvider.getUri(`${routine}.int`);
84+
if (!uri) {
85+
return;
86+
}
87+
let selection = new vscode.Range(0, 0, 0, 0);
88+
try {
89+
if (label) {
90+
// Find the location of the tag within the document
91+
const symbols: vscode.DocumentSymbol[] = await vscode.commands.executeCommand(
92+
"vscode.executeDocumentSymbolProvider",
93+
uri
94+
);
95+
for (const symbol of symbols) {
96+
if (symbol.name == label) {
97+
selection = new vscode.Range(symbol.selectionRange.start.line, 0, symbol.selectionRange.start.line, 0);
98+
break;
99+
}
100+
}
101+
}
102+
if (offset) {
103+
// Add the offset
104+
selection = new vscode.Range(selection.start.line + Number(offset), 0, selection.start.line + Number(offset), 0);
105+
}
106+
// Show the document
107+
await vscode.window.showTextDocument(uri, { preview: false, selection });
108+
} catch (error) {
109+
outputChannel.appendLine(
110+
typeof error == "string" ? error : error instanceof Error ? error.message : JSON.stringify(error)
111+
);
112+
outputChannel.show(true);
113+
vscode.window.showErrorMessage(
114+
`Failed to open routine '${routine}.int'. Check 'ObjectScript' Output channel for details.`,
115+
"Dismiss"
116+
);
117+
}
118+
}

src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
mainSourceControlMenu,
4545
} from "./commands/studio";
4646
import { addServerNamespaceToWorkspace, pickServerAndNamespace } from "./commands/addServerNamespaceToWorkspace";
47-
import { jumpToTagAndOffset } from "./commands/jumpToTagAndOffset";
47+
import { jumpToTagAndOffset, openErrorLocation } from "./commands/jumpToTagAndOffset";
4848
import { connectFolderToServerNamespace } from "./commands/connectFolderToServerNamespace";
4949
import { DocumaticPreviewPanel } from "./commands/documaticPreviewPanel";
5050

@@ -1207,6 +1207,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12071207
return importLocalFilesToServerSideFolder(wsFolderUri);
12081208
}
12091209
}),
1210+
vscode.commands.registerCommand("vscode-objectscript.openErrorLocation", openErrorLocation),
12101211

12111212
/* Anything we use from the VS Code proposed API */
12121213
...proposed

0 commit comments

Comments
 (0)