Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix persisting property values directly #80

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,39 @@ export function getConfigIDE<T = unknown>(
if (rawResult === undefined) return defaultValue;
return rawResult;
}

export function updateConfig<T>(
configKey: CfgKey,
value: T,
isProperty: boolean,
configTarget: vscode.ConfigurationTarget | undefined = undefined,
outputChannel: vscode.OutputChannel | undefined = undefined,
) {
const log = outputChannel?.appendLine;
log?.(
`updateConfig(${configKey}, ${JSON.stringify(value)}, ${isProperty}, ${configTarget}`,
);
/**
* The key to the corresponding object for this config value.
* Note that we can only update objects, not individual properties.
*/
const configObjectKey = isProperty
? configKey.substring(0, configKey.lastIndexOf('.'))
: configKey;
const lastKeyPart = configKey.substring(configKey.lastIndexOf('.') + 1);
const configRoot = getConfigRoot();
log?.(`Fetching ${configPrefix}.${configObjectKey}`);
const currentObjectValue = configRoot.get(configObjectKey, {});
log?.(`currentObjectValue: ${JSON.stringify(currentObjectValue)}`);
const newObjectValue = isProperty
? {
...currentObjectValue,
[lastKeyPart]: value,
}
: {
...currentObjectValue,
...value,
};
log?.(`newObjectValue: ${JSON.stringify(newObjectValue)}`);
configRoot.update(configObjectKey, newObjectValue, configTarget);
}
6 changes: 3 additions & 3 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
serverResetInterpreterPath,
ahkIsRunningContext,
} from '../../util/src/env';
import { getConfigIDE, getConfigRoot } from './config';
import { getConfigIDE, getConfigRoot, updateConfig } from './config';

let client: LanguageClient, outputchannel: OutputChannel, ahkStatusBarItem: StatusBarItem;
const ahkprocesses = new Map<number, ChildProcess & { path?: string }>();
Expand Down Expand Up @@ -572,7 +572,7 @@ async function setInterpreter() {
pick.dispose();
if (sel.detail) {
ahkStatusBarItem.tooltip = interpreterPath = sel.detail;
getConfigRoot().update(CfgKey.InterpreterPath, interpreterPath, from);
updateConfig(CfgKey.InterpreterPath, interpreterPath, true, from, outputchannel);
ahkStatusBarItem.text = sel.label ||= (await getAHKVersion([interpreterPath]))[0];
if (server_is_ready)
commands.executeCommand(serverResetInterpreterPath, interpreterPath);
Expand Down Expand Up @@ -617,7 +617,7 @@ async function selectSyntaxes() {
}
if (path === undefined || v.toLowerCase() === path.toLowerCase())
return;
getConfigRoot().update(CfgKey.Syntaxes, path || undefined, f);
updateConfig(CfgKey.Syntaxes, path || undefined, false, f, outputchannel);
}

function getAHKVersion(paths: string[]): Thenable<string[]> {
Expand Down
1 change: 1 addition & 0 deletions util/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export const getCfg = <T = string>(
* Sets the value of the key in the provided config.
* If no config provided, updates the global config.
* Does not update IDE settings.
* To update IDE settings, see /extension/config.ts
*/
export const setCfg = <T>(
key: CfgKey,
Expand Down
Loading