diff --git a/extensions/json-language-features/client/src/jsonMain.ts b/extensions/json-language-features/client/src/jsonMain.ts index e38e6221c5b..46a39b4be44 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, ExtensionContext, extensions, Uri, LanguageConfiguration, Diagnostic, StatusBarAlignment, TextEditor } from 'vscode'; +import { workspace, window, languages, commands, ExtensionContext, extensions, Uri, LanguageConfiguration, Diagnostic, StatusBarAlignment } from 'vscode'; import { LanguageClient, LanguageClientOptions, RequestType, ServerOptions, TransportKind, NotificationType, DidChangeConfigurationNotification, HandleDiagnosticsSignature } from 'vscode-languageclient'; import TelemetryReporter from 'vscode-extension-telemetry'; @@ -22,6 +22,10 @@ namespace SchemaContentChangeNotification { export const type: NotificationType = new NotificationType('json/schemaContent'); } +namespace SchemaRetryNotification { + export const type: NotificationType = new NotificationType('json/schemaRetry'); +} + export interface ISchemaAssociations { [pattern: string]: string[]; } @@ -78,7 +82,7 @@ export function activate(context: ExtensionContext) { let documentSelector = ['json', 'jsonc']; let statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, 0); - statusBarItem.text = '$(alert) JSON'; + statusBarItem.command = '_json.retrySchema'; toDispose.push(statusBarItem); // Options to control the language client @@ -100,7 +104,9 @@ 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; + statusBarItem.tooltip = schemaResolveDiagnostic.message + + '\n' + localize('json.clickToRetry', 'Click to retry.'); + statusBarItem.text = '$(alert) JSON'; statusBarItem.show(); diagnostics.splice(schemaErrorIndex, 1); } else { @@ -140,7 +146,7 @@ export function activate(context: ExtensionContext) { } }; - let handleActiveEditorChange = (_?: TextEditor) => { + let handleActiveEditorChange = () => { statusBarItem.hide(); }; @@ -148,6 +154,15 @@ export function activate(context: ExtensionContext) { toDispose.push(workspace.onDidCloseTextDocument(d => handleContentChange(d.uri))); toDispose.push(window.onDidChangeActiveTextEditor(handleActiveEditorChange)); + let handleRetrySchemaCommand = () => { + if (window.activeTextEditor) { + client.sendNotification(SchemaRetryNotification.type, window.activeTextEditor.document.uri.toString()); + statusBarItem.text = '$(watch) JSON'; + } + }; + + toDispose.push(commands.registerCommand('_json.retrySchema', handleRetrySchemaCommand)); + client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context)); }); diff --git a/extensions/json-language-features/package.nls.json b/extensions/json-language-features/package.nls.json index 943de414e15..62e983f9bb6 100644 --- a/extensions/json-language-features/package.nls.json +++ b/extensions/json-language-features/package.nls.json @@ -9,5 +9,6 @@ "json.format.enable.desc": "Enable/disable default JSON formatter", "json.tracing.desc": "Traces the communication between VS Code and the JSON language server.", "json.colorDecorators.enable.desc": "Enables or disables color decorators", - "json.colorDecorators.enable.deprecationMessage": "The setting `json.colorDecorators.enable` has been deprecated in favor of `editor.colorDecorators`." -} \ No newline at end of file + "json.colorDecorators.enable.deprecationMessage": "The setting `json.colorDecorators.enable` has been deprecated in favor of `editor.colorDecorators`.", + "json.clickToRetry": "Click to retry." +}