@@ -11,18 +11,18 @@ interface Language {
1111}
1212
1313// 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" } ,
1717 agda : { module : "tree-sitter-agda" } ,
1818 c : { module : "tree-sitter-c" } ,
1919 clojure : { module : "tree-sitter-clojure" } ,
2020 cpp : { module : "tree-sitter-cpp" } ,
2121 csharp : { module : "tree-sitter-c_sharp" } ,
2222 css : { module : "tree-sitter-css" } ,
2323 dart : { module : "tree-sitter-dart" } ,
24- elm : { module : "tree-sitter-elm" } ,
2524 elixir : { module : "tree-sitter-elixir" } ,
25+ elm : { module : "tree-sitter-elm" } ,
2626 gdscript : { module : "tree-sitter-gdscript" } ,
2727 gleam : { module : "tree-sitter-gleam" } ,
2828 go : { module : "tree-sitter-go" } ,
@@ -68,7 +68,7 @@ const initParser = treeSitter.Parser.init(); // TODO this isn't a field, suppres
6868export async function activate ( context : vscode . ExtensionContext ) {
6969 console . debug ( "Activating tree-sitter..." ) ;
7070 // Parse of all visible documents
71- const trees : { [ uri : string ] : treeSitter . Tree } = { } ;
71+ const trees : Record < string , treeSitter . Tree | undefined > = { } ;
7272
7373 /**
7474 * FIXME: On newer vscode versions some Tree sitter parser throws memory errors
@@ -141,6 +141,9 @@ export async function activate(context: vscode.ExtensionContext) {
141141 }
142142
143143 const language = languages [ document . languageId ] ;
144+ if ( language ?. parser == null ) {
145+ throw new Error ( `No parser for language ${ document . languageId } ` ) ;
146+ }
144147 const t = language . parser ?. parse ( document . getText ( ) ) ;
145148 if ( t == null ) {
146149 throw Error ( `Failed to parse ${ document . uri } ` ) ;
@@ -184,6 +187,9 @@ export async function activate(context: vscode.ExtensionContext) {
184187 return ;
185188 }
186189 const old = trees [ edit . document . uri . toString ( ) ] ;
190+ if ( old == null ) {
191+ throw new Error ( `No existing tree for ${ edit . document . uri } ` ) ;
192+ }
187193 for ( const e of edit . contentChanges ) {
188194 const startIndex = e . rangeOffset ;
189195 const oldEndIndex = e . rangeOffset + e . rangeLength ;
@@ -243,13 +249,14 @@ export async function activate(context: vscode.ExtensionContext) {
243249 context . subscriptions . push (
244250 vscode . workspace . onDidOpenTextDocument ( openIfVisible )
245251 ) ;
252+
246253 // Don't wait for the initial color, it takes too long to inspect the themes and causes VSCode extension host to hang
247254 colorAllOpen ( ) ;
248255
249256 function getTreeForUri ( uri : vscode . Uri ) {
250257 const ret = trees [ uri . toString ( ) ] ;
251258
252- if ( typeof ret === "undefined" ) {
259+ if ( ret == null ) {
253260 const document = vscode . workspace . textDocuments . find (
254261 ( textDocument ) => textDocument . uri . toString ( ) === uri . toString ( )
255262 ) ;
0 commit comments