@@ -29,7 +29,7 @@ export function getTrees(source: vscode.TextDocument | vscode.Uri): trees {
2929 }
3030 }
3131
32- vscode . window . showWarningMessage ( `TextMate: TreeSitter Tree does not exist!\nFile:\n${ JSON . stringify ( source ) } \nTrees:\n${ JSON . stringify ( trees ) } ` ) ;
32+ vscode . window . showWarningMessage ( `TextMate: TreeSitter Tree does not exist!\nFile:\n${ JSON . stringify ( source ) } \nTrees:\n${ JSON . stringify ( trees , stringify ) } ` ) ;
3333 return docTrees ;
3434}
3535
@@ -190,8 +190,6 @@ export function toPosition(point: TreeSitter.Point): vscode.Position {
190190}
191191
192192
193- export const parseEvents : ( ( document : vscode . TextDocument ) => void ) [ ] = [ ] ;
194-
195193let jsonParser : TreeSitter . Parser ;
196194let regexParser : TreeSitter . Parser ;
197195
@@ -224,98 +222,30 @@ export async function initTreeSitter(context: vscode.ExtensionContext) {
224222 const regexLanguage = await TreeSitter . Language . load ( regexWasm ) ;
225223 regexParser . setLanguage ( regexLanguage ) ;
226224
227- const activeDocuments : {
228- [ uriString : string ] : {
229- edits : vscode . TextDocumentChangeEvent | undefined ;
230- timeout : NodeJS . Timeout | number | undefined ; // VSCode vs VSCode Web
231- // version: number;
232- } ;
233- } = { } ;
234-
235- // for (const editor of vscode.window.visibleTextEditors) {
236- // // vscode.window.showInformationMessage(JSON.stringify("visible"));
237- // if (!vscode.languages.match(DocumentSelector, editor.document)) {
238- // return;
239- // }
240- // parseTextDocument(editor.document);
241- // }
242-
243225 for ( const editor of vscode . window . visibleTextEditors ) {
244- // vscode.window.showInformationMessage(JSON.stringify("visible"));
245- if ( ! vscode . languages . match ( DocumentSelector , editor . document ) ) {
246- continue ;
247- }
226+ // vscode.window.showInformationMessage(`visible\n${JSON.stringify(editor)}`);
248227 parseTextDocument ( editor . document ) ;
249228 }
250229
251230 context . subscriptions . push (
252231 vscode . workspace . onDidOpenTextDocument ( document => {
253- // vscode.window.showInformationMessage(JSON.stringify("open"));
254- if ( ! vscode . languages . match ( DocumentSelector , document ) ) {
255- return ;
256- }
232+ // vscode.window.showInformationMessage(`open\n${JSON.stringify(document)}`);
257233 parseTextDocument ( document ) ;
258234 } ) ,
259235
260236 vscode . workspace . onDidChangeTextDocument ( edits => {
261- // vscode.window.showInformationMessage(JSON.stringify("change") );
237+ // vscode.window.showInformationMessage(`edit\n${ JSON.stringify(edits)}` );
262238 const document = edits . document ;
263239 if ( ! vscode . languages . match ( DocumentSelector , document ) ) {
264240 return ;
265241 }
266242
267- // https://github.com/microsoft/vscode/issues/11487
268- const uriString = document . uri . toString ( ) ;
269- const activeDocument = activeDocuments [ uriString ] ?? { edits : null , timeout : null } ;
270- activeDocuments [ uriString ] = activeDocument ;
271-
272- // Debounce recently repeated requests
273- if ( activeDocument . timeout == null ) {
274- // Run Diagnostics instantly on first edit
275- reparseTextDocument ( edits ) ;
276-
277- // Wait 50ms and execute CallBack regardless of if there are gonna be new edits or not
278- activeDocument . timeout = setInterval (
279- ( ) => {
280- if ( activeDocument . edits == undefined ) {
281- // No new edits? exit.
282- clearInterval ( activeDocument . timeout ) ; // timeout.refresh() doesn't work in VSCode web
283- activeDocument . timeout = undefined ;
284-
285- for ( const parseEvent of parseEvents ) {
286- try {
287- parseEvent ( document ) ;
288- } catch ( error ) { }
289- }
290- return ;
291- }
292-
293- try {
294- // setInterval() waits for current callback to finish
295- reparseTextDocument ( activeDocument . edits ) ;
296- } catch ( error ) {
297- vscode . window . showInformationMessage ( JSON . stringify ( error ) ) ;
298- }
299- activeDocument . edits = undefined ;
300- } ,
301- 50 , // 50 millisecond intervals. Does anyone want this as a config?
302- ) ;
303- return ;
304- }
305-
306- // Add on the latest edits
307- activeDocument . edits = {
308- document : document ,
309- contentChanges : ( activeDocument . edits ?. contentChanges ?? [ ] ) . concat ( edits . contentChanges ) ,
310- reason : activeDocument . edits ?. reason ,
311- } ;
312- // vscode.window.showInformationMessage(JSON.stringify(activeDocument.edits));
243+ reparseTextDocument ( edits ) ;
313244 } ) ,
314245
315246 vscode . workspace . onDidCloseTextDocument ( document => {
316- // vscode.window.showInformationMessage(JSON.stringify("close") );
247+ // vscode.window.showInformationMessage(`close\n${ JSON.stringify(document)}` );
317248 const uriString = document . uri . toString ( ) ;
318- delete activeDocuments [ uriString ] ;
319249 if ( trees [ uriString ] ) {
320250 trees [ uriString ] . jsonTree . delete ( ) ;
321251 trees [ uriString ] . regexTrees . clear ( ) ;
@@ -327,7 +257,7 @@ export async function initTreeSitter(context: vscode.ExtensionContext) {
327257
328258
329259function parseTextDocument ( document : vscode . TextDocument ) {
330- // vscode.window.showInformationMessage(JSON.stringify("ParseTextDocument") );
260+ // vscode.window.showInformationMessage(`ParseTextDocument\n${ JSON.stringify(document)}` );
331261 // const start = performance.now();
332262
333263 if ( ! vscode . languages . match ( DocumentSelector , document ) ) {
@@ -377,7 +307,7 @@ function parseTextDocument(document: vscode.TextDocument) {
377307}
378308
379309function reparseTextDocument ( edits : vscode . TextDocumentChangeEvent ) {
380- // vscode.window.showInformationMessage(JSON.stringify("ReparseTextDocument") );
310+ // vscode.window.showInformationMessage(`ReparseTextDocument\n${ JSON.stringify(edits)}` );
381311 // const start = performance.now();
382312
383313 if ( edits . contentChanges . length == 0 ) {
0 commit comments