Skip to content

Commit 07d120e

Browse files
authored
schema URI not resolving in workspace file (microsoft#175320)
schema URI not resolve in workspace file
1 parent d2e6222 commit 07d120e

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

extensions/json-language-features/client/src/jsonClient.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,10 @@ function getSettings(): Settings {
545545
}
546546
};
547547

548-
const collectSchemaSettings = (schemaSettings: JSONSchemaSettings[] | undefined, folderUri?: Uri) => {
549-
548+
const collectSchemaSettings = (schemaSettings: JSONSchemaSettings[] | undefined, folderUri: Uri | undefined = undefined, settingsLocation = folderUri) => {
550549
if (schemaSettings) {
551550
for (const setting of schemaSettings) {
552-
const url = getSchemaId(setting, folderUri);
551+
const url = getSchemaId(setting, settingsLocation);
553552
if (url) {
554553
const schemaSetting: JSONSchemaSettings = { url, fileMatch: setting.fileMatch, folderUri: folderUri?.toString(false), schema: setting.schema };
555554
schemas.push(schemaSetting);
@@ -558,15 +557,19 @@ function getSettings(): Settings {
558557
}
559558
};
560559

560+
const folders = workspace.workspaceFolders;
561+
561562
const schemaConfigInfo = workspace.getConfiguration('json', null).inspect<JSONSchemaSettings[]>('schemas');
562563
if (schemaConfigInfo) {
563-
if (workspace.workspaceFile) {
564-
collectSchemaSettings(schemaConfigInfo.workspaceValue, workspace.workspaceFile);
564+
if (schemaConfigInfo.workspaceValue && workspace.workspaceFile && folders && folders.length) {
565+
const settingsLocation = Uri.joinPath(workspace.workspaceFile, '..');
566+
for (const folder of folders) {
567+
collectSchemaSettings(schemaConfigInfo.workspaceValue, folder.uri, settingsLocation);
568+
}
565569
}
566570
collectSchemaSettings(schemaConfigInfo.globalValue);
567571
}
568572

569-
const folders = workspace.workspaceFolders;
570573
if (folders) {
571574
for (const folder of folders) {
572575
const schemaConfigInfo = workspace.getConfiguration('json', folder.uri).inspect<JSONSchemaSettings[]>('schemas');
@@ -576,14 +579,14 @@ function getSettings(): Settings {
576579
return settings;
577580
}
578581

579-
function getSchemaId(schema: JSONSchemaSettings, folderUri?: Uri): string | undefined {
582+
function getSchemaId(schema: JSONSchemaSettings, settingsLocation?: Uri): string | undefined {
580583
let url = schema.url;
581584
if (!url) {
582585
if (schema.schema) {
583586
url = schema.schema.id || `vscode://schemas/custom/${encodeURIComponent(hash(schema.schema).toString(16))}`;
584587
}
585-
} else if (folderUri && (url[0] === '.' || url[0] === '/')) {
586-
url = Uri.joinPath(folderUri, url).toString(false);
588+
} else if (settingsLocation && (url[0] === '.' || url[0] === '/')) {
589+
url = Uri.joinPath(settingsLocation, url).toString(false);
587590
}
588591
return url;
589592
}

0 commit comments

Comments
 (0)