@@ -4,7 +4,7 @@ import * as vscodeOniguruma from 'vscode-oniguruma';
44import * as textmateOnigmo from 'vscode-onigmo' ;
55import * as PCRE from '@syntropiq/libpcre-ts' ;
66import * as onigurumaToES from 'oniguruma-to-es' ;
7- import { closeEnoughQuestionMark , DocumentSelector , getPackageJSON , JSONParseStringRelaxed , stringify , wagnerFischer } from "./extension" ;
7+ import { closeEnoughQuestionMark , DocumentSelector , getPackageJSON , JSONParseStringRelaxed , stringify , tryCatch , wagnerFischer } from "./extension" ;
88import { getLastNode , getTrees , queryNode , toRange , trees } from "./TreeSitter" ;
99import { ignoreDiagnosticsUnusedRepos } from "./Providers/CodeActionsProvider" ;
1010import { unicodeproperties } from "./UNICODE_PROPERTIES" ;
@@ -125,6 +125,7 @@ const activeDocuments: {
125125 } ;
126126} = { } ;
127127
128+
128129const DiagnosticCollection = vscode . languages . createDiagnosticCollection ( "textmate" ) ;
129130export async function initDiagnostics ( context : vscode . ExtensionContext ) {
130131 // vscode.window.showInformationMessage(JSON.stringify("initDiagnostics"));
@@ -139,19 +140,20 @@ export async function initDiagnostics(context: vscode.ExtensionContext) {
139140 }
140141
141142 context . subscriptions . push (
142- vscode . workspace . onDidOpenTextDocument ( ( document : vscode . TextDocument ) => {
143- // vscode.window.showInformationMessage(`open\n${JSON.stringify(document)}`);
144- debouncedDiagnostics ( document ) ;
145- } ) ,
143+ vscode . workspace . onDidOpenTextDocument ( debouncedDiagnostics ) ,
146144 vscode . workspace . onDidChangeTextDocument ( ( edits : vscode . TextDocumentChangeEvent ) => {
147- // vscode.window.showInformationMessage(`edit\n${JSON.stringify(edits)}`);
148145 debouncedDiagnostics ( edits . document ) ;
149146 } ) ,
150147 vscode . workspace . onDidCloseTextDocument ( ( document : vscode . TextDocument ) => {
151- // vscode.window.showInformationMessage(`close\n${JSON.stringify(document)}`);
152148 delete activeDocuments [ document . uri . toString ( ) ] ;
153149 DiagnosticCollection . delete ( document . uri ) ;
154- } )
150+ } ) ,
151+ vscode . window . onDidChangeActiveTextEditor ( ( textEditor : vscode . TextEditor | undefined ) => {
152+ if ( textEditor ) {
153+ const document = textEditor . document ;
154+ debouncedDiagnostics ( document ) ;
155+ }
156+ } ) ,
155157 ) ;
156158}
157159
@@ -171,7 +173,7 @@ export function debouncedDiagnostics(document: vscode.TextDocument) {
171173 activeDocument . countDown ++ ; // waits longer the more edits there are
172174
173175 // Debounce recently repeated requests
174- if ( activeDocument . timeout == undefined ) {
176+ if ( activeDocument . timeout === undefined ) {
175177
176178 // Wait 50ms and repeatedly execute CallBack
177179 activeDocument . timeout = setInterval (
@@ -180,8 +182,8 @@ export function debouncedDiagnostics(document: vscode.TextDocument) {
180182
181183 if ( activeDocument . countDown < 0 ) {
182184 clearInterval ( activeDocument . timeout ) ; // timeout.refresh() doesn't work in VSCode web
183- await Diagnostics ( activeDocument . document ) ;
184185 activeDocument . timeout = undefined ;
186+ await Diagnostics ( activeDocument . document ) ;
185187 }
186188
187189 activeDocument . countDown -= 2 ;
@@ -200,29 +202,23 @@ async function Diagnostics(document: vscode.TextDocument) {
200202
201203 const diagnostics : vscode . Diagnostic [ ] = [ ] ;
202204
203- const results = await Promise . allSettled ( [
204- diagnosticsMismatchingRootScopeName ( diagnostics , rootNode , document ) ,
205- diagnosticsTreeSitterJSONErrors ( diagnostics , rootNode ) ,
206- diagnosticsTreeSitterRegexErrors ( diagnostics , trees ) ,
207- diagnosticsRegularExpressionErrors ( diagnostics , trees ) ,
208- diagnosticsBrokenIncludes ( diagnostics , rootNode ) ,
209- diagnosticsUnusedRepos ( diagnostics , rootNode ) ,
210- diagnosticsLinguistCaptures ( diagnostics , rootNode ) ,
211- diagnosticsDeadTextMateCode ( diagnostics , rootNode ) ,
205+ await Promise . allSettled ( [
206+ tryCatch ( diagnosticsMismatchingRootScopeName ( diagnostics , rootNode , document ) , "Diagnostics error:" , "MismatchingPackageJSONInfo" ) ,
207+ tryCatch ( diagnosticsTreeSitterJSONErrors ( diagnostics , rootNode ) , "Diagnostics error:" , "TreeSitterJSONErrors" ) ,
208+ tryCatch ( diagnosticsTreeSitterRegexErrors ( diagnostics , trees ) , "Diagnostics error:" , "TreeSitterRegexErrors" ) ,
209+ tryCatch ( diagnosticsRegularExpressionErrors ( diagnostics , trees ) , "Diagnostics error:" , "OnigurumaRegexErrors" ) ,
210+ tryCatch ( diagnosticsBrokenIncludes ( diagnostics , rootNode ) , "Diagnostics error:" , "BrokenIncludes" ) ,
211+ tryCatch ( diagnosticsUnusedRepos ( diagnostics , rootNode ) , "Diagnostics error:" , "UnusedRepos" ) ,
212+ tryCatch ( diagnosticsLinguistCaptures ( diagnostics , rootNode ) , "Diagnostics error:" , "LinguistCaptures" ) ,
213+ tryCatch ( diagnosticsDeadTextMateCode ( diagnostics , rootNode ) , "Diagnostics error:" , "DeadTextMateCode" ) ,
212214 ] ) ;
213215
214- for ( const result of results ) {
215- if ( result . status == 'rejected' ) {
216- console . warn ( "JSON TextMate: Diagnostics error\n" , result . reason ) ;
217- }
218- }
219-
220216 DiagnosticCollection . set ( document . uri , diagnostics ) ;
221217 // vscode.window.showInformationMessage(`Diagnostics ${(performance.now() - start).toFixed(3)}ms\n${JSON.stringify(diagnostics)}`);
222218}
223219
224220
225- async function diagnosticsTreeSitterJSONErrors ( diagnostics : vscode . Diagnostic [ ] , rootNode : webTreeSitter . Node ) {
221+ function diagnosticsTreeSitterJSONErrors ( diagnostics : vscode . Diagnostic [ ] , rootNode : webTreeSitter . Node ) {
226222 // vscode.window.showInformationMessage(JSON.stringify("diagnostics JSON"));
227223 // const start = performance.now();
228224 const jsonQuery = `;scm
@@ -270,7 +266,7 @@ async function diagnosticsTreeSitterJSONErrors(diagnostics: vscode.Diagnostic[],
270266 // vscode.window.showInformationMessage(`JSON ${(performance.now() - start).toFixed(3)}ms`);
271267}
272268
273- async function diagnosticsTreeSitterRegexErrors ( diagnostics : vscode . Diagnostic [ ] , trees : trees ) {
269+ function diagnosticsTreeSitterRegexErrors ( diagnostics : vscode . Diagnostic [ ] , trees : trees ) {
274270 // vscode.window.showInformationMessage(JSON.stringify("diagnostics Regex"));
275271 // const start = performance.now();
276272 const regexTrees = trees . regexTrees ;
@@ -660,7 +656,7 @@ async function diagnosticsRegularExpressionErrors(diagnostics: vscode.Diagnostic
660656 // vscode.window.showInformationMessage(`Oniguruma ${(performance.now() - start).toFixed(3)}ms`);
661657}
662658
663- async function diagnosticsBrokenIncludes ( diagnostics : vscode . Diagnostic [ ] , rootNode : webTreeSitter . Node ) {
659+ function diagnosticsBrokenIncludes ( diagnostics : vscode . Diagnostic [ ] , rootNode : webTreeSitter . Node ) {
664660 // vscode.window.showInformationMessage(JSON.stringify("diagnostics #includes"))
665661 // const start = performance.now();
666662
0 commit comments