|
1 | 1 | import * as vscode from "vscode";
|
2 |
| -import { currentFile } from "../utils"; |
| 2 | +import { DocumentContentProvider } from "../providers/DocumentContentProvider"; |
| 3 | +import { currentFile, outputChannel } from "../utils"; |
3 | 4 |
|
4 | 5 | export async function jumpToTagAndOffset(): Promise<void> {
|
5 | 6 | const file = currentFile();
|
@@ -63,3 +64,55 @@ export async function jumpToTagAndOffset(): Promise<void> {
|
63 | 64 | });
|
64 | 65 | quickPick.show();
|
65 | 66 | }
|
| 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 | +} |
0 commit comments