mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 09:08:53 +01:00
Cache JSON schema error files
This commit is contained in:
@@ -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<string, string>();
|
||||
|
||||
// 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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user