fixes #6974: [json] $schema attribute - strange path resolution behavior when referencing local schema file

This commit is contained in:
Martin Aeschlimann
2016-05-30 17:15:02 +02:00
parent 28a78cba4f
commit fb4d59aa39
2 changed files with 11 additions and 17 deletions

View File

@@ -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 = (<Parser.ObjectASTNode>document.root).properties.filter((p) => (p.key.value === '$schema') && !!p.value);
if (schemaProperties.length > 0) {
let schemeId = <string>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);

View File

@@ -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);