Skip to content

Commit

Permalink
Fix: Add a try error for set settings
Browse files Browse the repository at this point in the history
  • Loading branch information
whats2000 committed Dec 28, 2024
1 parent 74f12d6 commit c9e3c25
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions VSCodeExtension/code-brt/src/api/settingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,46 @@ export class SettingsManager implements ISettingsManager {
setting: T,
value: ExtensionSettings[T],
): Promise<void> {
// Check if the setting is local
if (setting in DEFAULT_LOCAL_SETTINGS) {
(this.localSettings as any)[setting] = value;
await this.saveLocalSettings();
} else if (setting in DEFAULT_WORKSPACE_SETTINGS) {
// Check if the workspace is available
if (this.isMissingWorkspace) {
vscode.window
.showWarningMessage(
'Seems like you do not have a workspace open. ' +
'Open a workspace to save workspace settings, use agent tools, and save conversation history.',
'Open Workspace',
)
.then((selection) => {
if (selection === 'Open Workspace') {
vscode.commands.executeCommand('vscode.openFolder');
}
});
return;
}
try {
// Check if the setting is local
if (setting in DEFAULT_LOCAL_SETTINGS) {
(this.localSettings as any)[setting] = value;
await this.saveLocalSettings();
} else if (setting in DEFAULT_WORKSPACE_SETTINGS) {
// Check if the workspace is available
if (this.isMissingWorkspace) {
vscode.window
.showWarningMessage(
'Seems like you do not have a workspace open. ' +
'Open a workspace to save workspace settings, use agent tools, and save conversation history.',
'Open Workspace',
)
.then((selection) => {
if (selection === 'Open Workspace') {
vscode.commands.executeCommand('vscode.openFolder');
}
});
return;
}

await this.workspaceConfig.update(
setting,
value,
vscode.ConfigurationTarget.Workspace,
);
} else if (setting in DEFAULT_CROSS_DEVICE_SETTINGS) {
await this.workspaceConfig.update(
setting,
value,
vscode.ConfigurationTarget.Global,
await this.workspaceConfig.update(
setting,
value,
vscode.ConfigurationTarget.Workspace,
);
} else if (setting in DEFAULT_CROSS_DEVICE_SETTINGS) {
await this.workspaceConfig.update(
setting,
value,
vscode.ConfigurationTarget.Global,
);
} else {
console.error(`Setting ${setting} not found`);
}
} catch (error) {
vscode.window.showErrorMessage(
`Failed to set the setting: ${setting}. ${error}`,
);
} else {
throw new Error(`Unknown setting: ${setting}`);
}
}
}

0 comments on commit c9e3c25

Please sign in to comment.