Skip to content

Commit ad818a6

Browse files
committed
Attempt to open to the file where the offending setting is defined
1 parent b33ef79 commit ad818a6

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/configuration.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,4 +865,51 @@ export function handleConfigurationChangeEvent(
865865
};
866866
}
867867

868+
/**
869+
* Opens the appropriate settings JSON file based on where the setting is configured
870+
*/
871+
export async function openSettingsJsonForSetting(settingName: string): Promise<void> {
872+
try {
873+
const config = vscode.workspace.getConfiguration();
874+
const inspection = config.inspect(settingName);
875+
876+
if (!inspection) {
877+
// If we can't inspect the setting, fall back to global settings
878+
await vscode.commands.executeCommand("workbench.action.openSettingsJson");
879+
return;
880+
}
881+
882+
// Determine the most specific scope where the setting is defined
883+
if (inspection.workspaceFolderValue !== undefined) {
884+
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
885+
if (workspaceFolder) {
886+
const settingsUri = vscode.Uri.joinPath(
887+
workspaceFolder.uri,
888+
".vscode",
889+
"settings.json"
890+
);
891+
try {
892+
await vscode.window.showTextDocument(settingsUri);
893+
return;
894+
} catch {
895+
// If the file doesn't exist, create it or fall back
896+
await vscode.commands.executeCommand(
897+
"workbench.action.openWorkspaceSettingsFile"
898+
);
899+
return;
900+
}
901+
}
902+
}
903+
904+
if (inspection.workspaceValue !== undefined) {
905+
await vscode.commands.executeCommand("workbench.action.openWorkspaceSettingsFile");
906+
return;
907+
}
908+
909+
await vscode.commands.executeCommand("workbench.action.openSettingsJson");
910+
} catch (error) {
911+
await vscode.commands.executeCommand("workbench.action.openSettingsJson");
912+
}
913+
}
914+
868915
export default configuration;

src/extension.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { registerSourceKitSchemaWatcher } from "./commands/generateSourcekitConf
2525
import configuration, {
2626
ConfigurationValidationError,
2727
handleConfigurationChangeEvent,
28+
openSettingsJsonForSetting,
2829
} from "./configuration";
2930
import { ContextKeys, createContextKeys } from "./contextKeys";
3031
import { registerDebugger } from "./debugger/debugAdapterFactory";
@@ -197,10 +198,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<Api> {
197198
if (error instanceof ConfigurationValidationError) {
198199
void vscode.window.showErrorMessage(error.message, "Open Settings").then(selection => {
199200
if (selection === "Open Settings") {
200-
void vscode.commands.executeCommand(
201-
"workbench.action.openSettings",
202-
error.settingName
203-
);
201+
void openSettingsJsonForSetting(error.settingName);
204202
}
205203
});
206204
} else {

0 commit comments

Comments
 (0)