mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
[json] schemas in workspace settings also apply to external files (#178010)
This commit is contained in:
parent
2f1f07ec2b
commit
2ea2c80d63
|
@ -545,35 +545,45 @@ function getSettings(): Settings {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const collectSchemaSettings = (schemaSettings: JSONSchemaSettings[] | undefined, folderUri: Uri | undefined = undefined, settingsLocation = folderUri) => {
|
/*
|
||||||
|
* Add schemas from the settings
|
||||||
|
* folderUri to which folder the setting is scoped to. `undefined` means global (also external files)
|
||||||
|
* settingsLocation against which path relative schema URLs are resolved
|
||||||
|
*/
|
||||||
|
const collectSchemaSettings = (schemaSettings: JSONSchemaSettings[] | undefined, folderUri: string | undefined, settingsLocation: Uri | undefined) => {
|
||||||
if (schemaSettings) {
|
if (schemaSettings) {
|
||||||
for (const setting of schemaSettings) {
|
for (const setting of schemaSettings) {
|
||||||
const url = getSchemaId(setting, settingsLocation);
|
const url = getSchemaId(setting, settingsLocation);
|
||||||
if (url) {
|
if (url) {
|
||||||
const schemaSetting: JSONSchemaSettings = { url, fileMatch: setting.fileMatch, folderUri: folderUri?.toString(false), schema: setting.schema };
|
const schemaSetting: JSONSchemaSettings = { url, fileMatch: setting.fileMatch, folderUri, schema: setting.schema };
|
||||||
schemas.push(schemaSetting);
|
schemas.push(schemaSetting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const folders = workspace.workspaceFolders;
|
const folders = workspace.workspaceFolders ?? [];
|
||||||
|
|
||||||
const schemaConfigInfo = workspace.getConfiguration('json', null).inspect<JSONSchemaSettings[]>('schemas');
|
const schemaConfigInfo = workspace.getConfiguration('json', null).inspect<JSONSchemaSettings[]>('schemas');
|
||||||
if (schemaConfigInfo) {
|
if (schemaConfigInfo) {
|
||||||
if (schemaConfigInfo.workspaceValue && workspace.workspaceFile && folders && folders.length) {
|
// settings in user config
|
||||||
const settingsLocation = Uri.joinPath(workspace.workspaceFile, '..');
|
collectSchemaSettings(schemaConfigInfo.globalValue, undefined, undefined);
|
||||||
for (const folder of folders) {
|
if (workspace.workspaceFile) {
|
||||||
collectSchemaSettings(schemaConfigInfo.workspaceValue, folder.uri, settingsLocation);
|
if (schemaConfigInfo.workspaceValue) {
|
||||||
|
const settingsLocation = Uri.joinPath(workspace.workspaceFile, '..');
|
||||||
|
// settings in the workspace configuration file apply to all files (also external files)
|
||||||
|
collectSchemaSettings(schemaConfigInfo.workspaceValue, undefined, settingsLocation);
|
||||||
|
}
|
||||||
|
for (const folder of folders) {
|
||||||
|
const folderUri = folder.uri;
|
||||||
|
const folderSchemaConfigInfo = workspace.getConfiguration('json', folderUri).inspect<JSONSchemaSettings[]>('schemas');
|
||||||
|
collectSchemaSettings(folderSchemaConfigInfo?.workspaceFolderValue, folderUri.toString(false), folderUri);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (schemaConfigInfo.workspaceValue && folders.length === 1) {
|
||||||
|
// single folder workspace: settings apply to all files (also external files)
|
||||||
|
collectSchemaSettings(schemaConfigInfo.workspaceValue, undefined, folders[0].uri);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
collectSchemaSettings(schemaConfigInfo.globalValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (folders) {
|
|
||||||
for (const folder of folders) {
|
|
||||||
const schemaConfigInfo = workspace.getConfiguration('json', folder.uri).inspect<JSONSchemaSettings[]>('schemas');
|
|
||||||
collectSchemaSettings(schemaConfigInfo?.workspaceFolderValue, folder.uri);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return settings;
|
return settings;
|
||||||
|
|
Loading…
Reference in a new issue