diff --git a/src/configuration.ts b/src/configuration.ts index bfba157..6eec110 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -328,9 +328,9 @@ type SubPath = Key extends string : never : never; -type Path = SubPath | keyof T; +export type Path = SubPath | keyof T; -type PathValue> = P extends `${infer Key}.${infer Rest}` +export type PathValue> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Rest extends Path ? PathValue @@ -340,5 +340,5 @@ type PathValue> = P extends `${infer Key}.${infer Rest}` ? T[P] : never; -type ConfigPath = Path; -type ConfigPathValue

= PathValue; +export type ConfigPath = Path; +export type ConfigPathValue

= PathValue; diff --git a/src/webviews/protocol.ts b/src/webviews/protocol.ts index 400d2c7..91d2e30 100644 --- a/src/webviews/protocol.ts +++ b/src/webviews/protocol.ts @@ -1,4 +1,6 @@ import type { Config } from '../config'; +import type { ConfigPath, ConfigPathValue } from '../configuration'; +import type { CustomConfigPath, CustomConfigPathValue } from './webviewWithConfigBase'; export interface IpcMessage { id: string; @@ -61,7 +63,7 @@ export const GenerateConfigurationPreviewCommandType = new IpcCommandType | CustomConfigPathValue; }; removes: string[]; scope?: 'user' | 'workspace'; diff --git a/src/webviews/webviewWithConfigBase.ts b/src/webviews/webviewWithConfigBase.ts index 880def6..bc83ec3 100644 --- a/src/webviews/webviewWithConfigBase.ts +++ b/src/webviews/webviewWithConfigBase.ts @@ -1,5 +1,6 @@ import type { ConfigurationChangeEvent, WebviewPanelOnDidChangeViewStateEvent } from 'vscode'; import { ConfigurationTarget } from 'vscode'; +import type { Path, PathValue } from '../configuration'; import { configuration } from '../configuration'; import type { Commands, ContextKeys } from '../constants'; import type { Container } from '../container'; @@ -76,17 +77,24 @@ export abstract class WebviewWithConfigBase extends WebviewBase { const target = params.scope === 'workspace' ? ConfigurationTarget.Workspace : ConfigurationTarget.Global; - for (const key in params.changes) { + let key: keyof typeof params.changes; + for (key in params.changes) { let value = params.changes[key]; - const customSetting = this.customSettings.get(key); - if (customSetting != null) { - await customSetting.update(value); + if (isCustomConfigKey(key)) { + const customSetting = this.customSettings.get(key); + if (customSetting != null) { + if (typeof value === 'boolean') { + await customSetting.update(value); + } else { + debugger; + } + } continue; } - const inspect = configuration.inspect(key as any)!; + const inspect = configuration.inspect(key)!; if (value != null) { if (params.scope === 'workspace') { @@ -189,10 +197,10 @@ export abstract class WebviewWithConfigBase extends WebviewBase { } } - private _customSettings: Map | undefined; + private _customSettings: Map | undefined; private get customSettings() { if (this._customSettings == null) { - this._customSettings = new Map([ + this._customSettings = new Map([ [ 'rebaseEditor.enabled', { @@ -241,3 +249,24 @@ interface CustomSetting { enabled: () => boolean; update: (enabled: boolean) => Promise; } + +interface CustomConfig { + rebaseEditor: { + enabled: boolean; + }; + currentLine: { + useUncommittedChangesFormat: boolean; + }; +} + +export type CustomConfigPath = Path; +export type CustomConfigPathValue

= PathValue; + +const customConfigKeys: readonly CustomConfigPath[] = [ + 'rebaseEditor.enabled', + 'currentLine.useUncommittedChangesFormat', +]; + +export function isCustomConfigKey(key: string): key is CustomConfigPath { + return customConfigKeys.includes(key as CustomConfigPath); +}