From f2f79b8ecf9c22f8c5ebcdee48787b8263a2cd9b Mon Sep 17 00:00:00 2001 From: kshitij79 Date: Sun, 25 Aug 2024 12:30:35 -0400 Subject: [PATCH] Refined diagnostics reporting Signed-off-by: kshitij79 --- server/src/commands/commandHandler.ts | 2 +- server/src/documents/concertoHandler.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/server/src/commands/commandHandler.ts b/server/src/commands/commandHandler.ts index a60dc29..f247cd1 100644 --- a/server/src/commands/commandHandler.ts +++ b/server/src/commands/commandHandler.ts @@ -53,7 +53,7 @@ export async function loadModels() { log(`Document count: ${GLOBAL_STATE.documents.all().length}`); GLOBAL_STATE.documents.all().forEach(async document => { const change: TextDocumentChangeEvent = { document }; - handleConcertoDocumentChange(GLOBAL_STATE, change); + await handleConcertoDocumentChange(GLOBAL_STATE, change); }); } else { log('GLOBAL_STATE.connection is null'); diff --git a/server/src/documents/concertoHandler.ts b/server/src/documents/concertoHandler.ts index 3bf6fe8..6b6beee 100644 --- a/server/src/documents/concertoHandler.ts +++ b/server/src/documents/concertoHandler.ts @@ -89,8 +89,13 @@ export async function handleConcertoDocumentChange(state:LanguageServerState, ch catch (error: any) { if(!state.isLoading) { // we may be offline? Validate without external models - state.modelManager.validateModelFiles(); - state.diagnostics.pushDiagnostic(DiagnosticSeverity.Warning, change.document, error, 'model'); + if (!navigator.onLine){ + state.modelManager.validateModelFiles(); + } + // we only report errors for the document that changed, if error has a fileName + if(change.document.uri == error.fileName || !error.fileName){ + state.diagnostics.pushDiagnostic(DiagnosticSeverity.Warning, change.document, error, 'model'); + } } else { log(`Ignored model validation error while initializing ${change.document.uri}`); @@ -99,7 +104,9 @@ export async function handleConcertoDocumentChange(state:LanguageServerState, ch } catch (error: any) { if(!state.isLoading) { - state.diagnostics.pushDiagnostic(DiagnosticSeverity.Error, change.document, error, 'model'); + if(change.document.uri == error.fileName || !error.fileName){ + state.diagnostics.pushDiagnostic(DiagnosticSeverity.Error, change.document, error, 'model'); + } } else { log(`Ignored model validation error while initializing ${change.document.uri}`);