From cb8d48242988cb1c3743871f4bd20f5e3698f455 Mon Sep 17 00:00:00 2001 From: Literallie Date: Thu, 11 Oct 2018 16:41:39 +0200 Subject: [PATCH] Cache JSON schema error files --- .../client/src/jsonMain.ts | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/extensions/json-language-features/client/src/jsonMain.ts b/extensions/json-language-features/client/src/jsonMain.ts index 46a39b4be44..5116fba257c 100644 --- a/extensions/json-language-features/client/src/jsonMain.ts +++ b/extensions/json-language-features/client/src/jsonMain.ts @@ -8,7 +8,7 @@ import * as fs from 'fs'; import * as nls from 'vscode-nls'; const localize = nls.loadMessageBundle(); -import { workspace, window, languages, commands, ExtensionContext, extensions, Uri, LanguageConfiguration, Diagnostic, StatusBarAlignment } from 'vscode'; +import { workspace, window, languages, commands, ExtensionContext, extensions, Uri, LanguageConfiguration, Diagnostic, StatusBarAlignment, TextEditor } from 'vscode'; import { LanguageClient, LanguageClientOptions, RequestType, ServerOptions, TransportKind, NotificationType, DidChangeConfigurationNotification, HandleDiagnosticsSignature } from 'vscode-languageclient'; import TelemetryReporter from 'vscode-extension-telemetry'; @@ -85,6 +85,14 @@ export function activate(context: ExtensionContext) { statusBarItem.command = '_json.retrySchema'; toDispose.push(statusBarItem); + let showStatusBarItem = (message: string) => { + statusBarItem.tooltip = message + '\n' + localize('json.clickToRetry', 'Click to retry.'); + statusBarItem.text = '$(alert) JSON'; + statusBarItem.show(); + }; + + let fileSchemaErrors = new Map(); + // Options to control the language client let clientOptions: LanguageClientOptions = { // Register the server for json documents @@ -104,13 +112,12 @@ export function activate(context: ExtensionContext) { if (schemaErrorIndex !== -1) { // Show schema resolution errors in status bar only; ref: #51032 const schemaResolveDiagnostic = diagnostics[schemaErrorIndex]; - statusBarItem.tooltip = schemaResolveDiagnostic.message + - '\n' + localize('json.clickToRetry', 'Click to retry.'); - statusBarItem.text = '$(alert) JSON'; - statusBarItem.show(); + fileSchemaErrors.set(uri.toString(), schemaResolveDiagnostic.message); + showStatusBarItem(schemaResolveDiagnostic.message); diagnostics.splice(schemaErrorIndex, 1); } else { statusBarItem.hide(); + fileSchemaErrors.delete(uri.toString()); } next(uri, diagnostics); } @@ -146,12 +153,20 @@ export function activate(context: ExtensionContext) { } }; - let handleActiveEditorChange = () => { - statusBarItem.hide(); + let handleActiveEditorChange = (activeEditor?: TextEditor) => { + if (activeEditor && fileSchemaErrors.has(activeEditor.document.uri.toString())) { + const message = fileSchemaErrors.get(activeEditor.document.uri.toString())!; + showStatusBarItem(message); + } else { + statusBarItem.hide(); + } }; toDispose.push(workspace.onDidChangeTextDocument(e => handleContentChange(e.document.uri))); - toDispose.push(workspace.onDidCloseTextDocument(d => handleContentChange(d.uri))); + toDispose.push(workspace.onDidCloseTextDocument(d => { + handleContentChange(d.uri); + fileSchemaErrors.delete(d.uri.toString()); + })); toDispose.push(window.onDidChangeActiveTextEditor(handleActiveEditorChange)); let handleRetrySchemaCommand = () => {