Add retry action to JSON status bar icon

This commit is contained in:
Literallie 2018-10-11 00:27:58 +02:00
parent 7814f38222
commit fe4ce0b9d4
No known key found for this signature in database
GPG key ID: 7BE463C902ED152C
2 changed files with 22 additions and 6 deletions

View file

@ -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<string, any> = new NotificationType('json/schemaContent');
}
namespace SchemaRetryNotification {
export const type: NotificationType<string, any> = 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));
});

View file

@ -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`."
}
"json.colorDecorators.enable.deprecationMessage": "The setting `json.colorDecorators.enable` has been deprecated in favor of `editor.colorDecorators`.",
"json.clickToRetry": "Click to retry."
}