diff --git a/extensions/json/client/src/jsonMain.ts b/extensions/json/client/src/jsonMain.ts index e1e94e1de80..1498820c33d 100644 --- a/extensions/json/client/src/jsonMain.ts +++ b/extensions/json/client/src/jsonMain.ts @@ -21,6 +21,10 @@ namespace VSCodeContentRequest { export const type: RequestType = new RequestType('vscode/content'); } +namespace SchemaContentChangeNotification { + export const type: NotificationType = new NotificationType('json/schemaContent'); +} + export interface ISchemaAssociations { [pattern: string]: string[]; } @@ -58,9 +62,11 @@ interface JSONSchemaSettings { export function activate(context: ExtensionContext) { + let toDispose = context.subscriptions; + let packageInfo = getPackageInfo(context); let telemetryReporter: TelemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey); - context.subscriptions.push(telemetryReporter); + toDispose.push(telemetryReporter); // The server is implemented in node let serverModule = context.asAbsolutePath(path.join('server', 'out', 'jsonServerMain.js')); @@ -97,6 +103,7 @@ export function activate(context: ExtensionContext) { client.registerFeature(new ConfigurationFeature(client)); let disposable = client.start(); + toDispose.push(disposable); client.onReady().then(() => { client.onTelemetry(e => { if (telemetryReporter) { @@ -114,10 +121,18 @@ export function activate(context: ExtensionContext) { }); }); + let handleContentChange = (uri: Uri) => { + if (uri.scheme === 'vscode' && uri.authority === 'schemas') { + client.sendNotification(SchemaContentChangeNotification.type, uri.toString()); + } + }; + toDispose.push(workspace.onDidChangeTextDocument(e => handleContentChange(e.document.uri))); + toDispose.push(workspace.onDidCloseTextDocument(d => handleContentChange(d.uri))); + client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context)); // register color provider - context.subscriptions.push(languages.registerColorProvider(documentSelector, { + toDispose.push(languages.registerColorProvider(documentSelector, { provideDocumentColors(document: TextDocument): Thenable { let params: DocumentColorParams = { textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document) @@ -147,10 +162,6 @@ export function activate(context: ExtensionContext) { })); }); - // Push the disposable to the context's subscriptions so that the - // client can be deactivated on extension deactivation - context.subscriptions.push(disposable); - languages.setLanguageConfiguration('json', { wordPattern: /("(?:[^\\\"]*(?:\\.)?)*"?)|[^\s{}\[\],:]+/, indentationRules: { diff --git a/extensions/json/server/src/jsonServerMain.ts b/extensions/json/server/src/jsonServerMain.ts index 64b604093d9..92d57211f74 100644 --- a/extensions/json/server/src/jsonServerMain.ts +++ b/extensions/json/server/src/jsonServerMain.ts @@ -35,6 +35,10 @@ namespace VSCodeContentRequest { export const type: RequestType = new RequestType('vscode/content'); } +namespace SchemaContentChangeNotification { + export const type: NotificationType = new NotificationType('json/schemaContent'); +} + // Create a connection for the server let connection: IConnection = createConnection(); @@ -172,6 +176,11 @@ connection.onNotification(SchemaAssociationNotification.type, associations => { updateConfiguration(); }); +// A schema has changed +connection.onNotification(SchemaContentChangeNotification.type, uri => { + languageService.resetSchema(uri); +}); + function updateConfiguration() { let languageSettings: LanguageSettings = { validate: true,