11import * as vscode from "vscode" ;
22import { DocumentContentProvider } from "../providers/DocumentContentProvider" ;
3- import { currentFile , outputChannel } from "../utils" ;
3+ import { outputChannel } from "../utils" ;
44
55export async function jumpToTagAndOffset ( ) : Promise < void > {
6- const file = currentFile ( ) ;
7- if ( ! file ) {
8- return ;
9- }
10- const nameMatch = file . name . match ( / ( .* ) \. ( i n t | m a c ) $ / i) ;
11- if ( ! nameMatch ) {
6+ const editor = vscode . window . activeTextEditor ;
7+ if ( ! editor ) return ;
8+ const document = editor . document ;
9+ if ( ! [ "objectscript" , "objectscript-int" ] . includes ( document . languageId ) ) {
1210 vscode . window . showWarningMessage ( "Jump to Tag and Offset only supports .int and .mac routines." , "Dismiss" ) ;
1311 return ;
1412 }
15- const document = vscode . window . activeTextEditor ?. document ;
16- if ( ! document ) {
17- return ;
18- }
1913
2014 // Get the labels from the document symbol provider
2115 const map = new Map < string , number > ( ) ;
2216 const symbols : vscode . DocumentSymbol [ ] = await vscode . commands . executeCommand (
2317 "vscode.executeDocumentSymbolProvider" ,
2418 document . uri
2519 ) ;
20+ if ( ! Array . isArray ( symbols ) || ! symbols . length ) return ;
2621 const items : vscode . QuickPickItem [ ] = symbols
2722 . filter ( ( symbol ) => symbol . kind === vscode . SymbolKind . Method )
2823 . map ( ( symbol ) => {
@@ -35,28 +30,28 @@ export async function jumpToTagAndOffset(): Promise<void> {
3530 quickPick . title = "Jump to Tag + Offset" ;
3631 quickPick . items = items ;
3732 quickPick . canSelectMany = false ;
38- quickPick . onDidChangeSelection ( ( _ ) => {
39- quickPick . value = quickPick . selectedItems [ 0 ] . label ;
40- } ) ;
41- quickPick . onDidAccept ( ( _ ) => {
42- const editor = vscode . window . activeTextEditor ;
43- if ( ! editor ) {
44- quickPick . hide ( ) ;
33+ quickPick . onDidAccept ( ( ) => {
34+ if (
35+ quickPick . selectedItems . length &&
36+ ! new RegExp ( `^${ quickPick . selectedItems [ 0 ] . label } (\\+\\d+)?$` ) . test ( quickPick . value )
37+ ) {
38+ // Update the value to correct case and allow users to add/update the offset
39+ quickPick . value = quickPick . value . includes ( "+" )
40+ ? `${ quickPick . selectedItems [ 0 ] . label } +${ quickPick . value . split ( "+" ) [ 1 ] } `
41+ : quickPick . selectedItems [ 0 ] . label ;
4542 return ;
4643 }
47- const parts = quickPick . value . split ( "+" ) ;
44+ const parts = quickPick . value . trim ( ) . split ( "+" ) ;
4845 let offset = 0 ;
49- if ( ! map . has ( parts [ 0 ] ) ) {
50- if ( parts [ 0 ] !== "" ) {
51- return ;
52- }
53- } else {
54- offset += map . get ( parts [ 0 ] ) ;
46+ if ( parts [ 0 ] . length ) {
47+ const labelLine = map . get ( parts [ 0 ] ) ;
48+ if ( labelLine == undefined ) return ; // Not a valid label
49+ offset = labelLine ;
5550 }
5651 if ( parts . length > 1 ) {
5752 offset += parseInt ( parts [ 1 ] , 10 ) ;
5853 }
59- const line = editor . document . lineAt ( offset ) ;
54+ const line = document . lineAt ( offset ) ;
6055 const range = new vscode . Range ( line . range . start , line . range . start ) ;
6156 editor . selection = new vscode . Selection ( range . start , range . start ) ;
6257 editor . revealRange ( range , vscode . TextEditorRevealType . AtTop ) ;
0 commit comments