Skip to content

Commit 0e4192c

Browse files
committed
Added registration for custom schema provider
1 parent 74f640a commit 0e4192c

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/languageservice/services/jsonSchemaService.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,14 @@ export class JSONSchemaService implements IJSONSchemaService {
243243
private callOnDispose: Function[];
244244
private requestService: SchemaRequestService;
245245
private promiseConstructor: PromiseConstructor;
246-
private customSchemaProvider: CustomSchemaProvider;
246+
private customSchemaProvider: CustomSchemaProvider | undefined;
247247

248-
constructor(requestService: SchemaRequestService, contextService?: WorkspaceContextService, customSchemaProvider?: CustomSchemaProvider, promiseConstructor?: PromiseConstructor) {
248+
constructor(requestService: SchemaRequestService, contextService?: WorkspaceContextService, promiseConstructor?: PromiseConstructor) {
249249
this.contextService = contextService;
250250
this.requestService = requestService;
251251
this.promiseConstructor = promiseConstructor || Promise;
252252
this.callOnDispose = [];
253-
this.customSchemaProvider = customSchemaProvider;
253+
this.customSchemaProvider = undefined;
254254
this.contributionSchemas = {};
255255
this.contributionAssociations = {};
256256
this.schemasById = {};
@@ -259,6 +259,10 @@ export class JSONSchemaService implements IJSONSchemaService {
259259
this.registeredSchemasIds = {};
260260
}
261261

262+
registerCustomSchemaProvider(customSchemaProvider: CustomSchemaProvider) {
263+
this.customSchemaProvider = customSchemaProvider;
264+
}
265+
262266
public getRegisteredSchemaIds(filter?: (scheme) => boolean): string[] {
263267
return Object.keys(this.registeredSchemasIds).filter(id => {
264268
let scheme = URI.parse(id).scheme;

src/languageservice/yamlLanguageService.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) Microsoft Corporation. All rights reserved.
44
* Licensed under the MIT License. See License.txt in the project root for license information.
55
*--------------------------------------------------------------------------------------------*/
6-
import { JSONSchemaService } from './services/jsonSchemaService'
6+
import { JSONSchemaService, CustomSchemaProvider } from './services/jsonSchemaService'
77
import { TextDocument, Position, CompletionList, FormattingOptions, Diagnostic } from 'vscode-languageserver-types';
88
import { JSONSchema } from './jsonSchema';
99
import { YAMLDocumentSymbols } from './services/documentSymbols';
@@ -92,6 +92,7 @@ export interface SchemaConfiguration {
9292

9393
export interface LanguageService {
9494
configure(settings): void;
95+
registerCustomSchemaProvider(schemaProvider: CustomSchemaProvider): void; // Register a custom schema provider
9596
doComplete(document: TextDocument, position: Position, doc): Thenable<CompletionList>;
9697
doValidation(document: TextDocument, yamlDocument): Thenable<Diagnostic[]>;
9798
doHover(document: TextDocument, position: Position, doc);
@@ -101,10 +102,10 @@ export interface LanguageService {
101102
doFormat(document: TextDocument, options: FormattingOptions, customTags: Array<String>);
102103
}
103104

104-
export function getLanguageService(schemaRequestService, workspaceContext, contributions, customSchemaProvider, promiseConstructor?): LanguageService {
105+
export function getLanguageService(schemaRequestService, workspaceContext, contributions, promiseConstructor?): LanguageService {
105106
let promise = promiseConstructor || Promise;
106107

107-
let schemaService = new JSONSchemaService(schemaRequestService, workspaceContext, customSchemaProvider);
108+
let schemaService = new JSONSchemaService(schemaRequestService, workspaceContext);
108109

109110
let completer = new YAMLCompletion(schemaService, contributions, promise);
110111
let hover = new YAMLHover(schemaService, contributions, promise);
@@ -123,6 +124,9 @@ export function getLanguageService(schemaRequestService, workspaceContext, contr
123124
let customTagsSetting = settings && settings["customTags"] ? settings["customTags"] : [];
124125
completer.configure(customTagsSetting);
125126
},
127+
registerCustomSchemaProvider: (schemaProvider: CustomSchemaProvider) => {
128+
schemaService.registerCustomSchemaProvider(schemaProvider);
129+
},
126130
doComplete: completer.doComplete.bind(completer),
127131
doResolve: completer.doResolve.bind(completer),
128132
doValidation: yamlValidation.doValidation.bind(yamlValidation),

src/server.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Strings = require('./languageservice/utils/strings');
2222
import { getLineOffsets, removeDuplicatesObj } from './languageservice/utils/arrUtils';
2323
import { getLanguageService as getCustomLanguageService, LanguageSettings } from './languageservice/yamlLanguageService';
2424
import * as nls from 'vscode-nls';
25-
import { FilePatternAssociation } from './languageservice/services/jsonSchemaService';
25+
import { FilePatternAssociation, CustomSchemaProvider } from './languageservice/services/jsonSchemaService';
2626
import { parse as parseYAML } from './languageservice/parser/yamlParser';
2727
import { JSONDocument } from './languageservice/parser/jsonParser';
2828
import { JSONSchema } from './languageservice/jsonSchema';
@@ -36,6 +36,10 @@ namespace SchemaAssociationNotification {
3636
export const type: NotificationType<{}, {}> = new NotificationType('json/schemaAssociations');
3737
}
3838

39+
namespace DynamicCustomSchemaRequestRegistration {
40+
export const type: NotificationType<{}, {}> = new NotificationType('yaml/registerCustomSchemaRequest');
41+
}
42+
3943
namespace VSCodeContentRequest {
4044
export const type: RequestType<{}, {}, {}, {}> = new RequestType('vscode/content');
4145
}
@@ -167,8 +171,7 @@ let schemaRequestService = (uri: string): Thenable<string> => {
167171

168172
export let KUBERNETES_SCHEMA_URL = "https://gist.githubusercontent.com/JPinkney/ccaf3909ef811e5657ca2e2e1fa05d76/raw/f85e51bfb67fdb99ab7653c2953b60087cc871ea/openshift_schema_all.json";
169173
export let KEDGE_SCHEMA_URL = "https://raw.githubusercontent.com/kedgeproject/json-schema/master/master/kedge-json-schema.json";
170-
export let customLanguageService = getCustomLanguageService(schemaRequestService, workspaceContext, [],
171-
(resource) => connection.sendRequest(CustomSchemaRequest.type, resource));
174+
export let customLanguageService = getCustomLanguageService(schemaRequestService, workspaceContext, []);
172175

173176
// The settings interface describes the server relevant settings part
174177
interface Settings {
@@ -287,6 +290,11 @@ connection.onNotification(SchemaAssociationNotification.type, associations => {
287290
updateConfiguration();
288291
});
289292

293+
connection.onNotification(DynamicCustomSchemaRequestRegistration.type, () => {
294+
const schemaProvider = ((resource) => connection.sendRequest(CustomSchemaRequest.type, resource)) as CustomSchemaProvider;
295+
customLanguageService.registerCustomSchemaProvider(schemaProvider);
296+
});
297+
290298
function updateConfiguration() {
291299
let languageSettings: LanguageSettings = {
292300
validate: yamlShouldValidate,

0 commit comments

Comments
 (0)