fix(json.schemaDownload.trustedDomains): avoid always update json.sch… (#298423)

fix(json.schemaDownload.trustedDomains): avoid always update json.schemaDownload.trustedDomains

Signed-off-by: loongtao.zhang <loongtao.zhang@outlook.com>
This commit is contained in:
cathaysia
2026-03-02 18:19:12 +08:00
committed by GitHub
parent c95cc7ae08
commit 43755b4762

View File

@@ -690,6 +690,23 @@ async function startClientWithParticipants(_context: ExtensionContext, languageP
execute: () => Promise<void>;
}
const normalizeTrustedDomains = (domains: Record<string, boolean>): Record<string, boolean> => {
return Object.fromEntries(Object.entries(domains).sort(([a], [b]) => a.localeCompare(b)));
};
const updateTrustedDomains = async (updateDomain: string): Promise<void> => {
const config = workspace.getConfiguration();
const currentDomains = config.get<Record<string, boolean>>(SettingIds.trustedDomains, {});
if (currentDomains[updateDomain] === true) {
return;
}
const nextDomains = normalizeTrustedDomains({
...currentDomains,
[updateDomain]: true
});
await config.update(SettingIds.trustedDomains, nextDomains, true);
};
const items: QuickPickItemWithAction[] = [];
try {
@@ -701,10 +718,7 @@ async function startClientWithParticipants(_context: ExtensionContext, languageP
label: l10n.t('Trust Domain: {0}', domain),
description: l10n.t('Allow all schemas from this domain'),
execute: async () => {
const config = workspace.getConfiguration();
const currentDomains = config.get<Record<string, boolean>>(SettingIds.trustedDomains, {});
currentDomains[domain] = true;
await config.update(SettingIds.trustedDomains, currentDomains, true);
await updateTrustedDomains(domain);
await commands.executeCommand(CommandIds.workbenchActionOpenSettings, SettingIds.trustedDomains);
}
});
@@ -714,10 +728,7 @@ async function startClientWithParticipants(_context: ExtensionContext, languageP
label: l10n.t('Trust URI: {0}', schemaUri),
description: l10n.t('Allow only this specific schema'),
execute: async () => {
const config = workspace.getConfiguration();
const currentDomains = config.get<Record<string, boolean>>(SettingIds.trustedDomains, {});
currentDomains[schemaUri] = true;
await config.update(SettingIds.trustedDomains, currentDomains, true);
await updateTrustedDomains(schemaUri);
await commands.executeCommand(CommandIds.workbenchActionOpenSettings, SettingIds.trustedDomains);
}
});
@@ -926,4 +937,3 @@ export function isSchemaResolveError(d: Diagnostic) {
return typeof d.code === 'number' && d.code >= ErrorCodes.SchemaResolveError;
}