提交 fb4d59aa 编写于 作者: M Martin Aeschlimann

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

fixes #6974: [json] $schema attribute - strange path resolution behavior when referencing local schema file
上级 28a78cba
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册