@@ -11,18 +11,18 @@ interface Language {
11
11
}
12
12
13
13
// Be sure to declare the language in package.json and include a minimalist grammar.
14
- const languages : {
15
- [ id : string ] : Language ;
16
- } = {
14
+ const languages : Record < string , Language | undefined > = {
15
+ // eslint-disable-next-line @typescript-eslint/naming-convention
16
+ "java-properties" : { module : "tree-sitter-properties" } ,
17
17
agda : { module : "tree-sitter-agda" } ,
18
18
c : { module : "tree-sitter-c" } ,
19
19
clojure : { module : "tree-sitter-clojure" } ,
20
20
cpp : { module : "tree-sitter-cpp" } ,
21
21
csharp : { module : "tree-sitter-c_sharp" } ,
22
22
css : { module : "tree-sitter-css" } ,
23
23
dart : { module : "tree-sitter-dart" } ,
24
- elm : { module : "tree-sitter-elm" } ,
25
24
elixir : { module : "tree-sitter-elixir" } ,
25
+ elm : { module : "tree-sitter-elm" } ,
26
26
gdscript : { module : "tree-sitter-gdscript" } ,
27
27
gleam : { module : "tree-sitter-gleam" } ,
28
28
go : { module : "tree-sitter-go" } ,
@@ -68,7 +68,7 @@ const initParser = treeSitter.Parser.init(); // TODO this isn't a field, suppres
68
68
export async function activate ( context : vscode . ExtensionContext ) {
69
69
console . debug ( "Activating tree-sitter..." ) ;
70
70
// Parse of all visible documents
71
- const trees : { [ uri : string ] : treeSitter . Tree } = { } ;
71
+ const trees : Record < string , treeSitter . Tree | undefined > = { } ;
72
72
73
73
/**
74
74
* FIXME: On newer vscode versions some Tree sitter parser throws memory errors
@@ -141,6 +141,9 @@ export async function activate(context: vscode.ExtensionContext) {
141
141
}
142
142
143
143
const language = languages [ document . languageId ] ;
144
+ if ( language ?. parser == null ) {
145
+ throw new Error ( `No parser for language ${ document . languageId } ` ) ;
146
+ }
144
147
const t = language . parser ?. parse ( document . getText ( ) ) ;
145
148
if ( t == null ) {
146
149
throw Error ( `Failed to parse ${ document . uri } ` ) ;
@@ -184,6 +187,9 @@ export async function activate(context: vscode.ExtensionContext) {
184
187
return ;
185
188
}
186
189
const old = trees [ edit . document . uri . toString ( ) ] ;
190
+ if ( old == null ) {
191
+ throw new Error ( `No existing tree for ${ edit . document . uri } ` ) ;
192
+ }
187
193
for ( const e of edit . contentChanges ) {
188
194
const startIndex = e . rangeOffset ;
189
195
const oldEndIndex = e . rangeOffset + e . rangeLength ;
@@ -243,13 +249,14 @@ export async function activate(context: vscode.ExtensionContext) {
243
249
context . subscriptions . push (
244
250
vscode . workspace . onDidOpenTextDocument ( openIfVisible )
245
251
) ;
252
+
246
253
// Don't wait for the initial color, it takes too long to inspect the themes and causes VSCode extension host to hang
247
254
colorAllOpen ( ) ;
248
255
249
256
function getTreeForUri ( uri : vscode . Uri ) {
250
257
const ret = trees [ uri . toString ( ) ] ;
251
258
252
- if ( typeof ret === "undefined" ) {
259
+ if ( ret == null ) {
253
260
const document = vscode . workspace . textDocuments . find (
254
261
( textDocument ) => textDocument . uri . toString ( ) === uri . toString ( )
255
262
) ;
0 commit comments