mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 09:38:38 +01:00
[json] add 'Clear schema cache' command. Fixes #138524
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user