MCPcopy
hub / github.com/PowerShell/vscode-powershell / onSettingChange

Function onSettingChange

src/settings.ts:362–383  ·  view source on GitHub ↗
(
    section: string,
    setting: string,
    action: (newValue: T | undefined) => void,
    options?: onSettingChangeOptions,
)

Source from the content-addressed store, hash-verified

360// Because we actually do use the constraint in the callback
361// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
362export 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

Callers 1

Calls 2

doOnSettingsChangeFunction · 0.85
disposeMethod · 0.45

Tested by

no test coverage detected