1
1
import * as path from 'path' ;
2
2
import * as fs from 'fs' ;
3
3
import { env , TextDocument , Range } from 'vscode' ;
4
- import { Token } from './scope-info' ;
4
+ import { Token , IToken } from './scope-info' ;
5
5
import * as textmate from 'vscode-textmate' ;
6
6
7
7
type TextmateType = typeof textmate ;
@@ -12,23 +12,31 @@ type TextmateType = typeof textmate;
12
12
function getCoreNodeModule ( moduleName : string ) {
13
13
try {
14
14
return require ( `${ env . appRoot } /node_modules.asar/${ moduleName } ` ) ;
15
- } catch ( err ) { }
15
+ } catch ( err ) {
16
+ // do nothing
17
+ }
16
18
17
19
try {
18
20
return require ( `${ env . appRoot } /node_modules/${ moduleName } ` ) ;
19
- } catch ( err ) { }
21
+ } catch ( err ) {
22
+ // do nothing
23
+ }
20
24
21
25
return null ;
22
26
}
23
27
24
28
function getOnigWasmBin ( ) {
25
29
try {
26
30
return fs . readFileSync ( `${ env . appRoot } /node_modules.asar/vscode-oniguruma/release/onig.wasm` ) . buffer ;
27
- } catch ( err ) { }
31
+ } catch ( err ) {
32
+ // do nothing
33
+ }
28
34
29
35
try {
30
36
return fs . readFileSync ( `${ env . appRoot } /node_modules/vscode-oniguruma/release/onig.wasm` ) . buffer ;
31
- } catch ( err ) { }
37
+ } catch ( err ) {
38
+ // do nothing
39
+ }
32
40
33
41
console . error ( "Could not load the onig.wasm" ) ;
34
42
@@ -50,13 +58,14 @@ async function getRegistry(tm: TextmateType) {
50
58
} ) ;
51
59
}
52
60
61
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
53
62
// @ts -ignore
54
63
return new tm . Registry ( ) ;
55
64
}
56
65
57
66
const grammarPath = path . resolve ( __dirname + '/../../../syntaxes/firestorerules.tmLanguage.json' ) ;
58
67
59
- let grammar : any ;
68
+ let grammar : textmate . IGrammar ;
60
69
async function getGrammar ( ) {
61
70
if ( grammar ) {
62
71
return grammar ;
@@ -71,14 +80,14 @@ async function getGrammar() {
71
80
}
72
81
73
82
export async function tokenize ( document : TextDocument ) : Promise < Token [ ] [ ] > {
74
- let grammar = await getGrammar ( ) ;
83
+ const grammar = await getGrammar ( ) ;
75
84
76
- var ruleStack : any ;
77
- var tokens : Token [ ] [ ] = [ ] ;
85
+ let ruleStack : textmate . StackElement | null = null ;
86
+ const tokens : Token [ ] [ ] = [ ] ;
78
87
for ( let i = 0 ; i < document . lineCount ; i ++ ) {
79
- let line = document . getText ( new Range ( i , 0 , i + 1 , 0 ) ) ;
80
- var r = grammar . tokenizeLine ( line , ruleStack ! ) ;
81
- tokens . push ( r . tokens . map ( ( v : any ) => Token . create ( v , i , document ) ) ) ;
88
+ const line = document . getText ( new Range ( i , 0 , i + 1 , 0 ) ) ;
89
+ const r = grammar . tokenizeLine ( line , ruleStack ) ;
90
+ tokens . push ( r . tokens . map ( ( v : IToken ) => Token . create ( v , i , document ) ) ) ;
82
91
ruleStack = r . ruleStack ;
83
92
}
84
93
return tokens ;
0 commit comments