[json] add 'Clear schema cache' command. Fixes #138524

This commit is contained in:
Martin Aeschlimann
2021-12-06 16:56:12 +01:00
parent 1d4b413018
commit 95a9378519
6 changed files with 72 additions and 12 deletions

View File

@@ -27,7 +27,7 @@ namespace VSCodeContentRequest {
}
namespace SchemaContentChangeNotification {
export const type: NotificationType<string> = new NotificationType('json/schemaContent');
export const type: NotificationType<string | string[]> = new NotificationType('json/schemaContent');
}
namespace ForceValidateRequest {
@@ -101,6 +101,7 @@ export interface Runtime {
export interface SchemaRequestService {
getContent(uri: string): Promise<string>;
clearCache?(): Promise<string[]>;
}
export const languageServerDescription = localize('jsonserver.name', 'JSON Language Server');
@@ -111,7 +112,6 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
let rangeFormatting: Disposable | undefined = undefined;
const documentSelector = ['json', 'jsonc'];
const schemaResolutionErrorStatusBarItem = window.createStatusBarItem('status.json.resolveError', StatusBarAlignment.Right, 0);
@@ -122,6 +122,16 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
const fileSchemaErrors = new Map<string, string>();
let schemaDownloadEnabled = true;
let isClientReady = false;
commands.registerCommand('json.clearCache', async () => {
if (isClientReady && runtime.schemaRequests.clearCache) {
const cachedSchemas = await runtime.schemaRequests.clearCache();
await client.sendNotification(SchemaContentChangeNotification.type, cachedSchemas);
}
window.showInformationMessage(localize('json.clearCache.completed', "JSON schema cache cleared."));
});
// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for json documents
@@ -209,6 +219,8 @@ export function startClient(context: ExtensionContext, newLanguageClient: Langua
const disposable = client.start();
toDispose.push(disposable);
client.onReady().then(() => {
isClientReady = true;
const schemaDocuments: { [uri: string]: boolean } = {};
// handle content request