mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
fixes #6974: [json] $schema attribute - strange path resolution behavior when referencing local schema file
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user