vscode#ConfigurationTarget TypeScript Examples

The following examples show how to use vscode#ConfigurationTarget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VsCodeSetting.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
async set(value: T): Promise<void> {
		const value2 = this.serializer.serializer(value);
		const c = workspace.getConfiguration(undefined, this.scope);
		let target: ConfigurationTarget;
		if (this.target !== undefined) {
			target = this.target;
		} else {
			const result = c.inspect(this.id);
			if (
				result &&
				[
					result.workspaceFolderLanguageValue,
					result.workspaceFolderValue,
				].some((i) => i !== undefined)
			) {
				target = ConfigurationTarget.WorkspaceFolder;
			}
			if (
				result &&
				[result.workspaceLanguageValue, result.workspaceValue].some(
					(i) => i !== undefined
				)
			) {
				target = ConfigurationTarget.Workspace;
			} else {
				target = ConfigurationTarget.Global;
			}
		}

		await c.update(this.id, value2, target);
	}
Example #2
Source File: vscodeUtils.ts    From vscode-todo-md with MIT License 6 votes vote down vote up
/**
 * Toggle global setting (cycle through passed values).
 */
export async function toggleGlobalSetting(settingName: string, values: unknown[]) {
	const settings = workspace.getConfiguration(undefined, null);
	const currentSettingValue = settings.get(settingName);

	if (values.length === 1) {
		return settings.update(settingName, values[0], ConfigurationTarget.Global);
	} else {
		const next = getNextOrFirstElement(values, currentSettingValue);
		return settings.update(settingName, next, ConfigurationTarget.Global);
	}
}
Example #3
Source File: utils.ts    From memo with MIT License 6 votes vote down vote up
updateConfigProperty = async (
  property: string,
  value: unknown,
  target = ConfigurationTarget.Workspace,
) => {
  await workspace.getConfiguration().update(property, value, target);
}
Example #4
Source File: javaRuntimesUtils.ts    From vscode-stripe with MIT License 6 votes vote down vote up
export async function updateJavaHomeWorkspaceConfig(context: ExtensionContext, javaHome: string) {
  if (!javaHome) {
    return;
  }

  const allow = 'Allow';
  const disallow = 'Disallow';

  const key = getKey(IS_WORKSPACE_JDK_ALLOWED, context.storagePath, javaHome);
  const globalState = context.globalState;
  const allowWorkspaceEdit = globalState.get(key);

  if (allowWorkspaceEdit === undefined) {
    await window
      .showWarningMessage(
        `Do you allow Stripe extention to set the ${STRIPE_JAVA_HOME} variable? \n ${STRIPE_JAVA_HOME}: ${javaHome}`,
        disallow,
        allow,
      )
      .then(async (selection) => {
        if (selection === allow) {
          globalState.update(key, true);
          await workspace
            .getConfiguration()
            .update(STRIPE_JAVA_HOME, javaHome, ConfigurationTarget.Global);
        } else if (selection === disallow) {
          globalState.update(key, false);
          // leave the settings unchanged, in case user had manually set it before
        }
      });
  } else if (allowWorkspaceEdit) {
    const javaHomeValue = workspace.getConfiguration().get<string>(STRIPE_JAVA_HOME) || '';
    if (javaHomeValue !== javaHome) {
      await workspace
        .getConfiguration()
        .update(STRIPE_JAVA_HOME, javaHome, ConfigurationTarget.Global);
    }
  }
}
Example #5
Source File: VsCodeSetting.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
private readValue(): any {
		const config = workspace.getConfiguration(undefined, this.scope);

		if (this.target === undefined) {
			return config.get(this.id);
		} else {
			const result = config.inspect(this.id);
			if (!result) {
				return undefined;
			}
			if (this.target === ConfigurationTarget.Global) {
				return result.globalValue;
			} else if (this.target === ConfigurationTarget.Workspace) {
				return result.workspaceValue;
			} else if (this.target === ConfigurationTarget.WorkspaceFolder) {
				return result.workspaceFolderValue;
			}
		}
	}
Example #6
Source File: VsCodeSetting.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
constructor(
		readonly id: string,
		options: {
			serializer?: Serializer<T>;
			scope?: Uri;
			target?: ConfigurationTarget;
		} = {}
	) {
		this.scope = options.scope;
		this.serializer = options.serializer || {
			deserialize: (val) => val as T,
			serializer: (val) => val,
		};

		this.target = options.target;
		this.settingResource = new VsCodeSettingResource(
			this.id,
			this.scope,
			this.target
		);
	}
Example #7
Source File: json-reader.ts    From Json-to-Dart-Model with MIT License 6 votes vote down vote up
async getConfirmation(): Promise<boolean> {
        return window.showInformationMessage(
            'Start building JSON models?\n\nBuilds from tracked file locations.',
            { modal: true },
            ...['Start', "Don't ask again"]).then((action) => {
                switch (action) {
                    case "Don't ask again":
                        config.setConfig<boolean>('fastMode', true, ConfigurationTarget.Global);
                        return true;
                    case 'Start':
                        return true;
                    default:
                        return false;
                }
            });
    }
Example #8
Source File: VsCodeSetting.ts    From vscode-drawio with GNU General Public License v3.0 6 votes vote down vote up
private readValue(): any {
		const config = workspace.getConfiguration(undefined, this.scope);

		if (this.target === undefined) {
			return config.get(this.id);
		} else {
			const result = config.inspect(this.id);
			if (!result) {
				return undefined;
			}
			if (this.target === ConfigurationTarget.Global) {
				return result.globalValue;
			} else if (this.target === ConfigurationTarget.Workspace) {
				return result.workspaceValue;
			} else if (this.target === ConfigurationTarget.WorkspaceFolder) {
				return result.workspaceFolderValue;
			}
		}
	}
Example #9
Source File: VsCodeSetting.ts    From vscode-drawio with GNU General Public License v3.0 6 votes vote down vote up
public constructor(
		public readonly id: string,
		options: {
			serializer?: Serializer<T>;
			scope?: Uri;
			target?: ConfigurationTarget;
		} = {}
	) {
		this.scope = options.scope;
		this.serializer = options.serializer || {
			deserialize: (val) => val,
			serializer: (val) => val,
		};

		this.target = options.target;
		this.settingResource = new VsCodeSettingResource(
			this.id,
			this.scope,
			this.target
		);
	}
Example #10
Source File: VsCodeSetting.ts    From vscode-drawio with GNU General Public License v3.0 6 votes vote down vote up
public async set(value: T): Promise<void> {
		const value2 = this.serializer.serializer(value);
		const c = workspace.getConfiguration(undefined, this.scope);
		let target: ConfigurationTarget;
		if (this.target !== undefined) {
			target = this.target;
		} else {
			const result = c.inspect(this.id);
			if (
				result &&
				[
					result.workspaceFolderLanguageValue,
					result.workspaceFolderValue,
				].some((i) => i !== undefined)
			) {
				target = ConfigurationTarget.WorkspaceFolder;
			}
			if (
				result &&
				[result.workspaceLanguageValue, result.workspaceValue].some(
					(i) => i !== undefined
				)
			) {
				target = ConfigurationTarget.Workspace;
			} else {
				target = ConfigurationTarget.Global;
			}
		}

		await c.update(this.id, value2, target);
	}
Example #11
Source File: VsCodeSetting.ts    From vscode-drawio with GNU General Public License v3.0 5 votes vote down vote up
constructor(
		private readonly id: string,
		private readonly scope: Uri | undefined,
		private readonly target: ConfigurationTarget | undefined
	) {}
Example #12
Source File: configuration.ts    From Json-to-Dart-Model with MIT License 5 votes vote down vote up
async setConfig<T>(key: string, value: T, target: ConfigurationTarget): Promise<void> {
        await this.config.update(key, value, target);
    }
Example #13
Source File: driveExtensionSettings.ts    From google-drive-vscode with MIT License 5 votes vote down vote up
updateAlertMissingCredentials(value: boolean): Thenable<void> {
        return settingsGroup().update(MISSING_CREDENTIALS, value, ConfigurationTarget.Global);
    }
Example #14
Source File: VsCodeSetting.ts    From vscode-drawio with GNU General Public License v3.0 5 votes vote down vote up
private readonly target: ConfigurationTarget | undefined;
Example #15
Source File: VsCodeSetting.ts    From vscode-lean4 with Apache License 2.0 5 votes vote down vote up
private readonly target: ConfigurationTarget | undefined;
Example #16
Source File: VsCodeSetting.ts    From vscode-lean4 with Apache License 2.0 5 votes vote down vote up
constructor(
		private readonly id: string,
		private readonly scope: Uri | undefined,
		private readonly target: ConfigurationTarget | undefined
	) {}
Example #17
Source File: lsp-commands.ts    From vscode-microprofile with Apache License 2.0 5 votes vote down vote up
function addToPreferenceArray<T>(key: string, value: T): void {
  const configArray: T[] = workspace.getConfiguration().get<T[]>(key, []);
  if (configArray.includes(value)) {
    return;
  }
  configArray.push(value);
  workspace.getConfiguration().update(key, configArray, ConfigurationTarget.Workspace);
}
Example #18
Source File: Config.ts    From vscode-drawio with GNU General Public License v3.0 5 votes vote down vote up
private readonly _knownPlugins = new VsCodeSetting<
		{ pluginId: string; fingerprint: string; allowed: boolean }[]
	>(`${extensionId}.knownPlugins`, {
		serializer: serializerWithDefault<any>([]),
		// Don't use workspace settings here!
		target: ConfigurationTarget.Global,
	});
Example #19
Source File: vscodeUtils.ts    From vscode-todo-md with MIT License 5 votes vote down vote up
/**
 * Updates global setting with new value.
 */
export async function updateSetting(settingName: string, newValue: unknown) {
	const settings = workspace.getConfiguration(undefined, null);
	return settings.update(settingName, newValue, ConfigurationTarget.Global);
}
Example #20
Source File: settings.ts    From dendron with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
   * Upgrade config
   * @param config config to upgrade
   * @param target: config set to upgrade to
   */
  static async upgrade(
    src: WorkspaceConfiguration,
    target: ConfigUpdateChangeSet,
    opts?: SettingsUpgradeOpts
  ): Promise<ConfigChanges> {
    const cleanOpts = _.defaults(opts, { force: false });
    const add: any = {};
    const errors: any = {};
    await Promise.all(
      _.map(
        _.omit(target, [
          "workbench.colorTheme",
          "[markdown]",
          CONFIG.DEFAULT_JOURNAL_DATE_FORMAT.key,
          CONFIG.DEFAULT_SCRATCH_DATE_FORMAT.key,
        ]),
        async (entry, key) => {
          const item = src.inspect(key);
          // if value for key is not defined anywhere, set it to the default
          if (
            _.every(
              [
                item?.globalValue,
                item?.workspaceFolderValue,
                item?.workspaceValue,
              ],
              _.isUndefined
            ) ||
            cleanOpts.force
          ) {
            const value = entry.default;
            try {
              src.update(key, value, ConfigurationTarget.Workspace);
              add[key] = value;
              return;
            } catch (err) {
              errors[key] = err;
            }
          }
          return;
        }
      )
    );
    return { add, errors };
  }