1
1
import * as vscode from "vscode" ;
2
2
import { DocumentContentProvider } from "../providers/DocumentContentProvider" ;
3
- import { currentFile , outputChannel } from "../utils" ;
3
+ import { outputChannel } from "../utils" ;
4
4
5
5
export 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 ) ) {
12
10
vscode . window . showWarningMessage ( "Jump to Tag and Offset only supports .int and .mac routines." , "Dismiss" ) ;
13
11
return ;
14
12
}
15
- const document = vscode . window . activeTextEditor ?. document ;
16
- if ( ! document ) {
17
- return ;
18
- }
19
13
20
14
// Get the labels from the document symbol provider
21
15
const map = new Map < string , number > ( ) ;
22
16
const symbols : vscode . DocumentSymbol [ ] = await vscode . commands . executeCommand (
23
17
"vscode.executeDocumentSymbolProvider" ,
24
18
document . uri
25
19
) ;
20
+ if ( ! Array . isArray ( symbols ) || ! symbols . length ) return ;
26
21
const items : vscode . QuickPickItem [ ] = symbols
27
22
. filter ( ( symbol ) => symbol . kind === vscode . SymbolKind . Method )
28
23
. map ( ( symbol ) => {
@@ -35,28 +30,28 @@ export async function jumpToTagAndOffset(): Promise<void> {
35
30
quickPick . title = "Jump to Tag + Offset" ;
36
31
quickPick . items = items ;
37
32
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 ;
45
42
return ;
46
43
}
47
- const parts = quickPick . value . split ( "+" ) ;
44
+ const parts = quickPick . value . trim ( ) . split ( "+" ) ;
48
45
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 ;
55
50
}
56
51
if ( parts . length > 1 ) {
57
52
offset += parseInt ( parts [ 1 ] , 10 ) ;
58
53
}
59
- const line = editor . document . lineAt ( offset ) ;
54
+ const line = document . lineAt ( offset ) ;
60
55
const range = new vscode . Range ( line . range . start , line . range . start ) ;
61
56
editor . selection = new vscode . Selection ( range . start , range . start ) ;
62
57
editor . revealRange ( range , vscode . TextEditorRevealType . AtTop ) ;
0 commit comments