parent
ad95ccefbb
commit
649f448ef9
3 changed files with 43 additions and 27 deletions
|
@ -81,15 +81,11 @@ export function activate(context: ExtensionContext) {
|
|||
|
||||
let documentSelector = ['json', 'jsonc'];
|
||||
|
||||
let statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, 0);
|
||||
statusBarItem.command = '_json.retrySchema';
|
||||
toDispose.push(statusBarItem);
|
||||
|
||||
let showStatusBarItem = (message: string) => {
|
||||
statusBarItem.tooltip = message + '\n' + localize('json.clickToRetry', 'Click to retry.');
|
||||
statusBarItem.text = '$(alert)';
|
||||
statusBarItem.show();
|
||||
};
|
||||
let schemaResolutionErrorStatusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, 0);
|
||||
schemaResolutionErrorStatusBarItem.command = '_json.retryResolveSchema';
|
||||
schemaResolutionErrorStatusBarItem.tooltip = localize('json.schemaResolutionErrorMessage', 'Unable to resolve schema.') + ' ' + localize('json.clickToRetry', 'Click to retry.');
|
||||
schemaResolutionErrorStatusBarItem.text = '$(alert)';
|
||||
toDispose.push(schemaResolutionErrorStatusBarItem);
|
||||
|
||||
let fileSchemaErrors = new Map<string, string>();
|
||||
|
||||
|
@ -108,16 +104,19 @@ export function activate(context: ExtensionContext) {
|
|||
},
|
||||
handleDiagnostics: (uri: Uri, diagnostics: Diagnostic[], next: HandleDiagnosticsSignature) => {
|
||||
const schemaErrorIndex = diagnostics.findIndex(candidate => candidate.code === /* SchemaResolveError */ 0x300);
|
||||
if (schemaErrorIndex !== -1) {
|
||||
// Show schema resolution errors in status bar only; ref: #51032
|
||||
|
||||
if (schemaErrorIndex === -1) {
|
||||
fileSchemaErrors.delete(uri.toString());
|
||||
return next(uri, diagnostics);
|
||||
}
|
||||
|
||||
const schemaResolveDiagnostic = diagnostics[schemaErrorIndex];
|
||||
fileSchemaErrors.set(uri.toString(), schemaResolveDiagnostic.message);
|
||||
showStatusBarItem(schemaResolveDiagnostic.message);
|
||||
diagnostics.splice(schemaErrorIndex, 1);
|
||||
} else {
|
||||
statusBarItem.hide();
|
||||
fileSchemaErrors.delete(uri.toString());
|
||||
|
||||
if (window.activeTextEditor && window.activeTextEditor.document.uri.toString() === uri.toString()) {
|
||||
schemaResolutionErrorStatusBarItem.show();
|
||||
}
|
||||
|
||||
next(uri, diagnostics);
|
||||
}
|
||||
}
|
||||
|
@ -153,12 +152,16 @@ export function activate(context: ExtensionContext) {
|
|||
};
|
||||
|
||||
let handleActiveEditorChange = (activeEditor?: TextEditor) => {
|
||||
const uriStr = activeEditor && activeEditor.document.uri.toString();
|
||||
if (uriStr && fileSchemaErrors.has(uriStr)) {
|
||||
const message = fileSchemaErrors.get(uriStr)!;
|
||||
showStatusBarItem(message);
|
||||
if (!activeEditor) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeDocUri = activeEditor.document.uri.toString();
|
||||
|
||||
if (activeDocUri && fileSchemaErrors.has(activeDocUri)) {
|
||||
schemaResolutionErrorStatusBarItem.show();
|
||||
} else {
|
||||
statusBarItem.hide();
|
||||
schemaResolutionErrorStatusBarItem.hide();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -169,14 +172,25 @@ export function activate(context: ExtensionContext) {
|
|||
}));
|
||||
toDispose.push(window.onDidChangeActiveTextEditor(handleActiveEditorChange));
|
||||
|
||||
let handleRetrySchemaCommand = () => {
|
||||
let handleRetryResolveSchemaCommand = () => {
|
||||
if (window.activeTextEditor) {
|
||||
client.sendRequest(ForceValidateRequest.type, window.activeTextEditor.document.uri.toString());
|
||||
statusBarItem.text = '$(watch)';
|
||||
schemaResolutionErrorStatusBarItem.text = '$(watch)';
|
||||
const activeDocUri = window.activeTextEditor.document.uri.toString();
|
||||
client.sendRequest(ForceValidateRequest.type, activeDocUri).then((diagnostics) => {
|
||||
const schemaErrorIndex = diagnostics.findIndex(candidate => candidate.code === /* SchemaResolveError */ 0x300);
|
||||
if (schemaErrorIndex !== -1) {
|
||||
// Show schema resolution errors in status bar only; ref: #51032
|
||||
const schemaResolveDiagnostic = diagnostics[schemaErrorIndex];
|
||||
fileSchemaErrors.set(activeDocUri, schemaResolveDiagnostic.message);
|
||||
} else {
|
||||
schemaResolutionErrorStatusBarItem.hide();
|
||||
}
|
||||
schemaResolutionErrorStatusBarItem.text = '$(alert)';
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
toDispose.push(commands.registerCommand('_json.retrySchema', handleRetrySchemaCommand));
|
||||
toDispose.push(commands.registerCommand('_json.retryResolveSchema', handleRetryResolveSchemaCommand));
|
||||
|
||||
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
|
||||
});
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
],
|
||||
"main": "./client/out/jsonMain",
|
||||
"scripts": {
|
||||
"compile": "gulp compile-extension:json-language-features-client && gulp compile-extension:json-language-features-server",
|
||||
"compile": "gulp compile-extension:json-language-features-client compile-extension:json-language-features-server",
|
||||
"watch": "gulp watch-extension:json-language-features-client watch-extension:json-language-features-server",
|
||||
"postinstall": "cd server && yarn install",
|
||||
"install-client-next": "yarn add vscode-languageclient@next"
|
||||
},
|
||||
|
|
|
@ -10,5 +10,6 @@
|
|||
"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.schemaResolutionErrorMessage": "Unable to resolve schema.",
|
||||
"json.clickToRetry": "Click to retry."
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue