@@ -10,14 +10,14 @@ import { getScopes, getSubScope } from "../themeScopeColors";
10
10
11
11
12
12
type element = {
13
+ type : 'file' | 'root' | 'line' | 'token' | 'scope' | 'rule' | 'name' | 'regex' | 'capture' | 'pattern' ,
13
14
line ?: number ,
14
15
tokenId ?: number ,
15
16
scopeId ?: number ,
16
17
ruleIndex ?: number ,
17
18
ruleId ?: RuleId ,
18
19
token ?: IToken ,
19
20
document : vscode . TextDocument ,
20
- type : 'file' | 'root' | 'line' | 'token' | 'scope' | 'rule' | 'name' | 'regex' | 'capture' | 'pattern' ,
21
21
} ;
22
22
23
23
// type rule = {
@@ -38,6 +38,7 @@ const grammars: {
38
38
} = { } ;
39
39
let grammar : IGrammar ;
40
40
let callView : CallView = 'tree' ;
41
+ let currentFile : string ;
41
42
42
43
// const ruleChached: number[] = [];
43
44
@@ -54,9 +55,10 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
54
55
return ;
55
56
}
56
57
58
+ currentFile = activeTextEditor . document . uri . toString ( ) ;
57
59
const treeElement : element = {
58
- document : activeTextEditor . document ,
59
60
type : 'file' ,
61
+ document : activeTextEditor . document ,
60
62
} ;
61
63
elements . push ( treeElement ) ;
62
64
return elements ;
@@ -67,8 +69,8 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
67
69
68
70
if ( type == 'file' ) {
69
71
const treeElement : element = {
70
- document : document ,
71
72
type : 'root' ,
73
+ document : document ,
72
74
} ;
73
75
elements . push ( treeElement ) ;
74
76
return elements ;
@@ -147,11 +149,11 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
147
149
148
150
if ( depth == 0 ) {
149
151
const childElement : element = {
152
+ type : 'rule' ,
150
153
line : line ,
151
154
ruleId : ruleId ,
152
155
ruleIndex : index ,
153
156
document : document ,
154
- type : 'rule' ,
155
157
// stage: 'name',
156
158
} ;
157
159
elements . push ( childElement ) ;
@@ -173,9 +175,9 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
173
175
if ( type == 'root' ) {
174
176
for ( let index = 0 ; index < grammar . lines . length && index < 125000 ; index ++ ) {
175
177
const element : element = {
178
+ type : 'line' ,
176
179
line : index ,
177
180
document : document ,
178
- type : 'line' ,
179
181
} ;
180
182
elements . push ( element ) ;
181
183
}
@@ -186,11 +188,11 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
186
188
const tokens = grammar . lines [ element . line ] . tokens ;
187
189
for ( let index = 0 ; index < tokens . length && index < 125000 ; index ++ ) {
188
190
const tokenElement : element = {
191
+ type : 'token' ,
189
192
token : tokens [ index ] ,
190
193
tokenId : index ,
191
194
line : element . line ,
192
195
document : document ,
193
- type : 'token' ,
194
196
} ;
195
197
elements . push ( tokenElement ) ;
196
198
}
@@ -202,11 +204,11 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
202
204
const token = element . tokenId ;
203
205
for ( let index = grammar . lines [ element . line ] . tokens [ token ] . scopes . length - 1 ; index >= 0 ; index -- ) {
204
206
const tokenElement : element = {
207
+ type : 'scope' ,
205
208
tokenId : element . tokenId ,
206
209
scopeId : index ,
207
210
line : element . line ,
208
211
document : document ,
209
- type : 'scope' ,
210
212
} ;
211
213
elements . push ( tokenElement ) ;
212
214
}
@@ -218,6 +220,16 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
218
220
// vscode.window.showInformationMessage(`getTreeItem\n${JSON.stringify(element)}`);
219
221
220
222
const type = element . type ;
223
+ const document = element . document ;
224
+
225
+ if ( type == 'file' ) {
226
+ const item = new vscode . TreeItem ( document . uri , vscode . TreeItemCollapsibleState . Collapsed ) ;
227
+ item . description = document . languageId ;
228
+ item . iconPath = vscode . ThemeIcon . File ;
229
+ item . contextValue = 'document' ;
230
+ item . id = document . uri . toString ( ) ;
231
+ return item ;
232
+ }
221
233
222
234
if ( type == 'root' ) {
223
235
grammar = await tokenizeFile ( element . document , true ) ;
@@ -233,16 +245,8 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
233
245
const item = new vscode . TreeItem ( treeLabel , vscode . TreeItemCollapsibleState . Collapsed ) ;
234
246
item . iconPath = new vscode . ThemeIcon ( 'symbol-variable' ) ;
235
247
item . tooltip = `Time: ${ time } ` ;
236
- item . description = timeFixed + "ms" + ( time > 500 ? ' ⚠️' : '' ) ;
237
- return item ;
238
- }
239
-
240
- const document = element . document ;
241
- if ( type == 'file' ) {
242
- const item = new vscode . TreeItem ( document . uri , vscode . TreeItemCollapsibleState . Collapsed ) ;
243
- item . description = document . languageId ;
244
- item . iconPath = vscode . ThemeIcon . File ;
245
- item . contextValue = 'document' ;
248
+ item . description = `${ timeFixed } ms${ ( time > 500 ? ' ⚠️' : '' ) } ` ;
249
+ item . id = grammar . _rootScopeName ;
246
250
return item ;
247
251
}
248
252
@@ -450,25 +454,28 @@ export const TreeDataProvider: vscode.TreeDataProvider<element> = {
450
454
} ,
451
455
getParent ( element : element ) : element {
452
456
// vscode.window.showInformationMessage(`getParent\n${JSON.stringify(element)}`);
453
- const type = element . type ;
454
-
455
- if ( type == 'root' ) {
456
- const parentElement : element = {
457
- document : element . document ,
458
- type : 'file' ,
459
- } ;
460
- return parentElement ;
461
- }
462
-
463
- if ( type == 'line' ) {
464
- const parentElement : element = {
465
- document : element . document ,
466
- type : 'root' ,
467
- } ;
468
- return parentElement ;
457
+ const document = element . document ;
458
+ switch ( element . type ) {
459
+ case 'token' :
460
+ return {
461
+ type : 'line' ,
462
+ line : element . line ,
463
+ document : document ,
464
+ } ;
465
+ case 'line' :
466
+ return {
467
+ type : 'root' ,
468
+ document : document ,
469
+ } ;
470
+ case 'root' :
471
+ return {
472
+ type : 'file' ,
473
+ document : document ,
474
+ } ;
475
+ case 'file' :
476
+ default :
477
+ return undefined ;
469
478
}
470
-
471
- return undefined ;
472
479
} ,
473
480
resolveTreeItem ( item : vscode . TreeItem , element : element , token : vscode . CancellationToken ) : vscode . TreeItem {
474
481
// vscode.window.showInformationMessage(`resolveTreeItem\n${JSON.stringify(element)}\n${JSON.stringify(item, stringify)}`);
@@ -568,82 +575,50 @@ async function CallStackView(textEditor: vscode.TextEditor, edit: vscode.TextEdi
568
575
const document = textEditor . document ;
569
576
const position = textEditor . selection . active ;
570
577
571
- // const tokenLineResults = await tokenizeFile(document);
572
- // // vscode.window.showInformationMessage(JSON.stringify(tokenLineResults, stringify));
573
-
574
- // let rootParent = true;
575
- // let index = 0;
576
- // const ruleList: {
577
- // scopeName: string,
578
- // ruleId: RuleId,
579
- // depth: number,
580
- // _enterPos: number,
581
- // line: number,
582
- // }[] = [];
583
- // for (const tokenLine of tokenLineResults) {
584
- // let parentRule = <StateStackImpl>tokenLine.ruleStack;
585
- // index++;
586
- // const tempRules = [];
587
- // while (parentRule) {
588
- // if (parentRule._enterPos != -1 || rootParent) {
589
- // const rule = {
590
- // scopeName: parentRule.nameScopesList.scopePath.scopeName,
591
- // ruleId: parentRule.ruleId,
592
- // depth: parentRule.depth,
593
- // _enterPos: parentRule._enterPos,
594
- // line: index,
595
- // };
596
- // tempRules.unshift(rule);
597
- // rootParent = false;
598
- // }
599
- // parentRule = parentRule.parent;
600
- // }
601
- // ruleList.push(...tempRules);
602
- // // ruleList = [...ruleList, ...tempRules];
603
- // }
604
-
605
- // const ruleTree = {};
606
-
607
- // vscode.window.showInformationMessage(JSON.stringify(ruleList, stringify));
608
-
609
- // const grammar = await tokenizeFile(document);
610
-
611
- // onDidChangeTreeData.fire(undefined);
612
-
613
- const activeTextEditor = vscode . window . activeTextEditor ;
614
- if ( ! activeTextEditor ) {
615
- return ;
578
+ if ( currentFile != document . uri . toString ( ) ) {
579
+ refresh ( ) ;
616
580
}
617
- await treeView . reveal (
618
- undefined ,
619
- {
620
- expand : true ,
621
- focus : true ,
622
- select : true ,
623
- }
624
- ) ;
625
- await treeView . reveal (
626
- {
627
- document : activeTextEditor . document ,
628
- type : 'file' ,
629
- } ,
630
- {
631
- expand : true ,
632
- focus : true ,
633
- select : true ,
634
- }
635
- ) ;
581
+
636
582
await treeView . reveal (
637
583
{
638
- document : activeTextEditor . document ,
639
584
type : 'root' ,
585
+ document : document ,
640
586
} ,
641
587
{
642
588
expand : true ,
643
- focus : true ,
644
- select : true ,
589
+ focus : false ,
590
+ select : false ,
645
591
}
646
592
) ;
593
+
594
+ if ( callView == 'list' ) {
595
+ const line = position . line ;
596
+ const character = position . character ;
597
+ const tokens = grammar . lines [ line ] . tokens ;
598
+ let index = 0 ;
599
+ for ( const token of tokens ) {
600
+ if ( token . startIndex <= character && token . endIndex >= character ) {
601
+ break ;
602
+ }
603
+ index ++ ;
604
+ }
605
+ await treeView . reveal (
606
+ {
607
+ type : 'token' ,
608
+ token : tokens [ index ] ,
609
+ tokenId : index ,
610
+ line : line ,
611
+ document : document ,
612
+ } ,
613
+ {
614
+ expand : false ,
615
+ focus : true ,
616
+ select : true ,
617
+ } ,
618
+ ) ;
619
+ return ;
620
+ }
621
+
647
622
// treeView.badge = {
648
623
// tooltip: "tooltip badge 56: is there any use for this number?",
649
624
// value: 56,
0 commit comments