(
section: string,
setting: string,
action: (newValue: T | undefined) => void,
options?: onSettingChangeOptions,
)
| 360 | // Because we actually do use the constraint in the callback |
| 361 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters |
| 362 | export function onSettingChange<T>( |
| 363 | section: string, |
| 364 | setting: string, |
| 365 | action: (newValue: T | undefined) => void, |
| 366 | options?: onSettingChangeOptions, |
| 367 | ): vscode.Disposable { |
| 368 | const settingPath = `${section}.${setting}`; |
| 369 | const disposable = vscode.workspace.onDidChangeConfiguration((e) => { |
| 370 | if (!e.affectsConfiguration(settingPath, options?.scope)) { |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | doOnSettingsChange(section, setting, action, options?.scope); |
| 375 | if (options?.run === "once") { |
| 376 | disposable.dispose(); // Javascript black magic, referring to an outer reference before it exists |
| 377 | } |
| 378 | }); |
| 379 | if (options?.run === "now") { |
| 380 | doOnSettingsChange(section, setting, action, options.scope); |
| 381 | } |
| 382 | return disposable; |
| 383 | } |
| 384 | |
| 385 | /** Implementation is separate to avoid duplicate code for run now */ |
| 386 |
no test coverage detected