1
1
"use strict" ;
2
2
import * as vscode from "vscode" ;
3
- import * as logFunctions from "./logFunctions"
4
- import * as commonFunctions from "./commonFunctions"
3
+ import * as logFunctions from "./logFunctions" ;
4
+ import * as commonFunctions from "./commonFunctions" ;
5
+ import { symbolCache } from "./extension" ;
5
6
6
7
const red = 0 ;
7
8
const green = 1 ;
@@ -13,28 +14,35 @@ const decorationTypeCurrentRow = vscode.window.createTextEditorDecorationType(
13
14
{
14
15
fontWeight : "bold" ,
15
16
borderRadius : "5px" ,
16
- dark : {
17
- border : "1px solid rgb(215,215,215); opacity: 0.5;" ,
18
- } ,
19
- light : {
20
- border : "1px solid rgb(115,115,115); opacity: 0.5;" ,
21
- }
17
+ dark : { border : "1px solid rgb(215,215,215); opacity: 0.5;" } ,
18
+ light : { border : "1px solid rgb(115,115,115); opacity: 0.5;" }
22
19
}
23
20
) ;
24
21
25
- var lastLine : vscode . Position ;
22
+ const decorationTypeSub = vscode . window . createTextEditorDecorationType (
23
+ {
24
+ fontWeight : "bolder" ,
25
+ dark : { color : "rgb(45, 156, 66);" , } ,
26
+ light : { color : "rgb(78, 74, 139);" , }
27
+ }
28
+ ) ;
26
29
30
+ let lastLine : vscode . Position ;
27
31
export function setupDecorate ( ) {
28
- decorateAll ( vscode . window . activeTextEditor ) ; // Decorate on activate/first open
29
-
30
- // Decorate when the text editor changes
31
- vscode . window . onDidChangeActiveTextEditor ( async ( e : { document : any ; } ) => {
32
- if ( ! e || ! e . document ) {
33
- return
32
+ symbolCache . length = 0 ;
33
+ vscode . commands . executeCommand < vscode . DocumentSymbol [ ] > ( 'vscode.executeDocumentSymbolProvider' , vscode . window . activeTextEditor . document . uri )
34
+ . then ( ( ) => {
35
+ decorateAll ( vscode . window . activeTextEditor ) ;
36
+ } ) ;
37
+
38
+ vscode . window . onDidChangeActiveTextEditor ( ( editor ) : void => {
39
+ if ( editor ) {
40
+ vscode . commands . executeCommand < vscode . DocumentSymbol [ ] > ( 'vscode.executeDocumentSymbolProvider' , editor . document . uri )
41
+ . then ( ( ) => {
42
+ decorateAll ( editor ) ;
43
+ } ) ;
34
44
}
35
- decorateAll ( vscode . window . activeTextEditor ) ;
36
45
} ) ;
37
-
38
46
vscode . window . onDidChangeTextEditorSelection ( ( ) => { decorateSingleLine ( vscode . window . activeTextEditor ) ; } )
39
47
}
40
48
@@ -55,12 +63,14 @@ function decorateSingleLine(editor: any) {
55
63
56
64
const config = vscode . workspace . getConfiguration ( "qb64" ) ;
57
65
58
- let includeLeading : vscode . Range [ ] = [ ]
59
- let includeTrailing : vscode . Range [ ] = [ ]
60
- let todo : vscode . Range [ ] = [ ]
66
+ let includeLeading : vscode . Range [ ] = [ ] ;
67
+ let includeTrailing : vscode . Range [ ] = [ ] ;
68
+ let todo : vscode . Range [ ] = [ ] ;
69
+ let subs : vscode . Range [ ] = [ ] ;
70
+
61
71
62
72
if ( lastLine && lastLine . line != currrentLine . line ) {
63
- decorate ( editor , lastLine . line , editor . document . lineAt ( lastLine . line ) . text , outputChannnel , includeLeading , includeTrailing , todo ) ;
73
+ decorate ( editor , lastLine . line , editor . document . lineAt ( lastLine . line ) . text , outputChannnel , includeLeading , includeTrailing , todo , subs ) ;
64
74
}
65
75
66
76
if ( config . get ( "isCurrentRowHighlightEnabled" ) ) {
@@ -82,7 +92,7 @@ function decorateSingleLine(editor: any) {
82
92
}
83
93
}
84
94
85
- function decorateAll ( editor : any ) {
95
+ export function decorateAll ( editor : any ) {
86
96
87
97
if ( ! editor || editor . document . languageId == "Log" || editor . document . fileName == "extension-output-qb64-official.qb64-#3-QB64: Decorate" ) {
88
98
return ;
@@ -93,21 +103,24 @@ function decorateAll(editor: any) {
93
103
const sourceCode = editor . document . getText ( ) . split ( '\n' ) ;
94
104
let includeLeading : vscode . Range [ ] = [ ] ;
95
105
let includeTrailing : vscode . Range [ ] = [ ] ;
96
- let todo : vscode . Range [ ] = [ ] ;
106
+ let todos : vscode . Range [ ] = [ ] ;
107
+ let subs : vscode . Range [ ] = [ ] ;
108
+
97
109
for ( let line = 0 ; line < sourceCode . length ; line ++ ) {
98
- decorate ( editor , line , sourceCode [ line ] , outputChannnel , includeLeading , includeTrailing , todo ) ;
110
+ decorate ( editor , line , sourceCode [ line ] , outputChannnel , includeLeading , includeTrailing , todos , subs ) ;
99
111
}
100
112
101
113
editor . setDecorations ( decorationTypeIncludeLeading , includeLeading ) ;
102
114
editor . setDecorations ( decorationTypeIncludeTrailing , includeTrailing ) ;
103
- editor . setDecorations ( decorationTypeTodo , todo ) ;
115
+ editor . setDecorations ( decorationTypeTodo , todos ) ;
116
+ editor . setDecorations ( decorationTypeSub , subs ) ;
104
117
105
118
} catch ( error ) {
106
119
logFunctions . writeLine ( `ERROR in decorateAll: ${ error } ` , outputChannnel ) ;
107
120
}
108
121
}
109
122
110
- function decorate ( editor : any , lineNumber : number , lineOfCode : string , outputChannnel : any , includeLeading : vscode . Range [ ] , includeTrailing : vscode . Range [ ] , todo : vscode . Range [ ] ) {
123
+ function decorate ( editor : any , lineNumber : number , lineOfCode : string , outputChannnel : any , includeLeading : vscode . Range [ ] , includeTrailing : vscode . Range [ ] , todos : vscode . Range [ ] , subs : vscode . Range [ ] ) {
111
124
112
125
if ( ! editor || editor . document . languageId == "Log" || editor . document . fileName == "extension-output-qb64-official.qb64-#3-QB64: Decorate" ) {
113
126
return ;
@@ -144,7 +157,36 @@ function decorate(editor: any, lineNumber: number, lineOfCode: string, outputCha
144
157
if ( config . get ( "isTodoHighlightEnabled" ) ) {
145
158
const matches = lineOfCode . matchAll ( / (?< = ' * | r e m * ) T O D O : | F I X I T : | F I X M E : / ig) ;
146
159
for ( const match of matches ) {
147
- todo . push ( commonFunctions . createRange ( match , lineNumber , 0 ) ) ;
160
+ todos . push ( commonFunctions . createRange ( match , lineNumber , 0 ) ) ;
161
+ }
162
+ }
163
+
164
+ if ( symbolCache && symbolCache . length > 0 ) {
165
+ const tokens = lineOfCode . split ( / [ \s ( ] + / ) ;
166
+ for ( let tokenIndex = 0 ; tokenIndex < tokens . length ; tokenIndex ++ ) {
167
+ const sub = symbolCache . find ( ( s ) => s . name . toLowerCase ( ) === tokens [ tokenIndex ] . toLowerCase ( ) && ( s . kind === vscode . SymbolKind . Method || s . kind === vscode . SymbolKind . Function ) ) ;
168
+ if ( sub ) {
169
+
170
+ const matches = lineOfCode . matchAll ( new RegExp ( `\\s*(\\b(call|declare sub|sub|function|\\s+=\\s+)\\s+)?${ commonFunctions . escapeRegExp ( sub . name ) } (?:\\()?(?!\\))` , 'gi' ) ) ;
171
+
172
+ /*
173
+ if (lineOfCode == "MachSpeed& = CalcDelay&") {
174
+ console.log("here");
175
+ }
176
+ */
177
+
178
+ for ( let match of matches ) {
179
+
180
+ let start : number = match . index < 1 ? match [ 0 ] . toLowerCase ( ) . indexOf ( sub . name . toLowerCase ( ) ) : match . index
181
+ let stop : number = match . index < 1 ? start + sub . name . length : start + sub . name . length + 1
182
+
183
+ subs . push (
184
+ new vscode . Range (
185
+ new vscode . Position ( lineNumber , start ) ,
186
+ new vscode . Position ( lineNumber , stop )
187
+ ) ) ;
188
+ }
189
+ }
148
190
}
149
191
}
150
192
0 commit comments