diff --git a/extensions/json/server/src/jsonSchemaService.ts b/extensions/json/server/src/jsonSchemaService.ts index da1c2392dfe54b34dd4d7e5105bd3cbce2bbfb69..2dcfd5491ba89036f6f0f72853ae5089882b672d 100644 --- a/extensions/json/server/src/jsonSchemaService.ts +++ b/extensions/json/server/src/jsonSchemaService.ts @@ -206,7 +206,7 @@ export interface ITelemetryService { } export interface IWorkspaceContextService { - toResource(workspaceRelativePath: string): string; + resolveRelativePath(relativePath: string, resource: string): string; } export interface IRequestService { @@ -473,13 +473,8 @@ export class JSONSchemaService implements IJSONSchemaService { let schemaProperties = (document.root).properties.filter((p) => (p.key.value === '$schema') && !!p.value); if (schemaProperties.length > 0) { let schemeId = schemaProperties[0].value.getValue(); - if (!Strings.startsWith(schemeId, 'http://') && !Strings.startsWith(schemeId, 'https://') && !Strings.startsWith(schemeId, 'file://')) { - if (this.contextService) { - let resourceURL = this.contextService.toResource(schemeId); - if (resourceURL) { - schemeId = resourceURL.toString(); - } - } + if (Strings.startsWith(schemeId, '.') && this.contextService) { + schemeId = this.contextService.resolveRelativePath(schemeId, resource); } if (schemeId) { let id = this.normalizeId(schemeId); diff --git a/extensions/json/server/src/server.ts b/extensions/json/server/src/server.ts index da55236362c5070f28a899a98037de751addab0e..b91d4ca9e1210f312b0ecc50fb85f6e936bb82aa 100644 --- a/extensions/json/server/src/server.ts +++ b/extensions/json/server/src/server.ts @@ -78,11 +78,12 @@ connection.onInitialize((params: InitializeParams): InitializeResult => { }); let workspaceContext = { - toResource: (workspaceRelativePath: string) => { - if (typeof workspaceRelativePath === 'string' && workspaceRoot) { - return URI.file(path.join(workspaceRoot.fsPath, workspaceRelativePath)).toString(); + resolveRelativePath: (relativePath: string, resource: string) => { + if (typeof relativePath === 'string' && resource) { + let resourceURI = URI.parse(resource); + return URI.file(path.normalize(path.join(path.dirname(resourceURI.fsPath), relativePath))).toString(); } - return workspaceRelativePath; + return void 0; } }; @@ -192,11 +193,9 @@ function updateConfiguration() { url = 'vscode://schemas/custom/' + encodeURIComponent(schema.fileMatch.join('&')); } } - if (!Strings.startsWith(url, 'http://') && !Strings.startsWith(url, 'https://') && !Strings.startsWith(url, 'file://')) { - let resourceURL = workspaceContext.toResource(url); - if (resourceURL) { - url = resourceURL.toString(); - } + if (Strings.startsWith(url, '.') && workspaceRoot) { + // workspace relative path + url = URI.file(path.normalize(path.join(workspaceRoot.fsPath, url))).toString(); } if (url) { jsonSchemaService.registerExternalSchema(url, schema.fileMatch, schema.schema);