vscode#WorkspaceConfiguration TypeScript Examples

The following examples show how to use vscode#WorkspaceConfiguration. 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: Configuration.ts    From vscode-alxmldocumentation with MIT License 6 votes vote down vote up
/**
     * Get configuration value for given configuration parameter.
     * @param configParam Configuration Parameter to retrieve value from.
     * @param fileUri URI to actual file or undefined.
     */
    private static GetConfigurationValue(configParam: string, fileUri: Uri | undefined = undefined): any {
        let config: WorkspaceConfiguration | undefined = this.GetConfiguration(fileUri);
        if (config === undefined) {
            return;
        }
        return config.get(configParam);
    }
Example #2
Source File: Configuration.ts    From vscode-alxmldocumentation with MIT License 6 votes vote down vote up
/**
     * Get Configuration related for the actual file opened.
     * @param fileUri URI to actual file or undefined.
     */
    private static GetConfiguration(fileUri: Uri | undefined = undefined): WorkspaceConfiguration | undefined {
        let config: WorkspaceConfiguration | undefined;
        if (fileUri === undefined) {
            let activeDocument = (window.activeTextEditor !== undefined) ? window.activeTextEditor.document : undefined;
            let workspaceFolder: WorkspaceFolder | undefined = undefined;
            if (activeDocument !== undefined) {
                workspaceFolder = workspace.getWorkspaceFolder(activeDocument.uri);
                config = workspace.getConfiguration(ALXmlDocConfigurationPrefix, workspaceFolder);
            } else {
                config = workspace.getConfiguration(ALXmlDocConfigurationPrefix);
            }
        } else {
            let workspaceFolder = workspace.getWorkspaceFolder(fileUri);
            config = workspace.getConfiguration(ALXmlDocConfigurationPrefix, workspaceFolder);
        }

        return config;
    }
Example #3
Source File: Configuration.ts    From vscode-alxmldocumentation with MIT License 6 votes vote down vote up
/**
     * Sets configuration value for given configuration parameter.
     * @param configParam Configuration Parameter to set value.
     * @param configValue New Configuration Value.
     */
    private static SetConfigurationValue(configParam: string, configValue: any) {
        let config: WorkspaceConfiguration | undefined = this.GetConfiguration();
        if (config === undefined) {
            workspace.getConfiguration(ALXmlDocConfigurationPrefix).update(configParam, configValue);
            return;
        }

        config.update(configParam, configValue);
    }
Example #4
Source File: config.ts    From format-imports-vscode with MIT License 6 votes vote down vote up
function transform(wsConfig: WorkspaceConfiguration) {
  const { detectIndentation, insertSpaces, tabSize, codeActionsOnSave } =
    wsConfig.get<VscEditorConfig>('editor') ?? {};
  // If 'detectIndentation' is true, indentation is detected instead of from settings.
  const tabType =
    detectIndentation || insertSpaces === undefined
      ? undefined
      : insertSpaces
      ? ('space' as const)
      : ('tab' as const);
  const actionId = SortActionProvider.ACTION_ID;
  const codeAction =
    codeActionsOnSave &&
    (Array.isArray(codeActionsOnSave)
      ? codeActionsOnSave.includes(actionId)
      : codeActionsOnSave[actionId]);
  const { insertFinalNewline: nl, eol } = wsConfig.get<VscFilesConfig>('files') ?? {};
  return {
    config: {
      tabType,
      tabSize: detectIndentation ? undefined : tabSize,
      insertFinalNewline: nl ? true : ('preserve' as const),
      eof: eol === 'auto' ? undefined : eol,
    },
    codeAction,
  };
}
Example #5
Source File: Config.ts    From al-objid with MIT License 5 votes vote down vote up
private _config: WorkspaceConfiguration;
Example #6
Source File: client.ts    From vala-vscode with MIT License 5 votes vote down vote up
config: WorkspaceConfiguration
Example #7
Source File: parser.ts    From vscode-discord with MIT License 5 votes vote down vote up
public config: WorkspaceConfiguration;
Example #8
Source File: listener.ts    From vscode-discord with MIT License 5 votes vote down vote up
private config: WorkspaceConfiguration;
Example #9
Source File: client.ts    From vscode-discord with MIT License 5 votes vote down vote up
constructor(public config: WorkspaceConfiguration) {}
Example #10
Source File: project-factory.ts    From karma-test-explorer with MIT License 5 votes vote down vote up
private shouldActivateAdapterForWorkspaceFolder(
    workspaceFolderPath: string,
    config: WorkspaceConfiguration
  ): boolean {
    const enableExtension = config.get<boolean | null>(WorkspaceConfigSetting.EnableExtension);

    if (typeof enableExtension === 'boolean') {
      this.logger.debug(
        () =>
          `${enableExtension ? 'Including' : 'Excluding'} projects in workspace ` +
          `folder '${workspaceFolderPath}' because the extension has been ` +
          `explicitly ${enableExtension ? 'enabled' : 'disabled'} by setting the ` +
          `'${EXTENSION_CONFIG_PREFIX}.${WorkspaceConfigSetting.EnableExtension}' ` +
          `setting to ${enableExtension ? 'true' : 'false'}`
      );
      return enableExtension;
    }

    const configuredExtensionSetting = Object.values(WorkspaceConfigSetting).find(
      configSetting => config.inspect(configSetting)?.workspaceFolderValue ?? false
    );

    if (configuredExtensionSetting !== undefined) {
      this.logger.debug(
        () =>
          `Including projects in workspace folder '${workspaceFolderPath}' ` +
          `because it has one or more extension settings configured: ` +
          `${configuredExtensionSetting}`
      );
      return true;
    }

    const projectRootPath = config.get<string>(WorkspaceConfigSetting.ProjectRootPath) ?? '';
    const projectPackageJsonFilePath = posix.join(workspaceFolderPath, projectRootPath, 'package.json');
    const workspacePackageJsonFilePath = posix.join(workspaceFolderPath, 'package.json');

    let packageJsonFilePath: string | undefined;

    try {
      if (existsSync(projectPackageJsonFilePath)) {
        packageJsonFilePath = projectPackageJsonFilePath;
      }
    } catch (error) {
      this.logger.debug(() => `Could not find a project package.json file at ${projectPackageJsonFilePath}`);
    }

    try {
      if (!packageJsonFilePath && existsSync(workspacePackageJsonFilePath)) {
        packageJsonFilePath = workspacePackageJsonFilePath;
      }
    } catch (error) {
      this.logger.debug(() => `Could not find a workspace package.json file at ${workspacePackageJsonFilePath}`);
    }

    const packageJson: { devDependencies: Record<string, string> } | undefined = packageJsonFilePath
      ? require(projectPackageJsonFilePath)
      : undefined;

    if (packageJson && Object.keys(packageJson.devDependencies).includes('karma')) {
      this.logger.debug(
        () =>
          `Including projects in workspace folder '${workspaceFolderPath}' ` +
          `because related package.json file '${packageJsonFilePath}' has a karma dev dependency`
      );
      return true;
    }
    return false;
  }
Example #11
Source File: configuration.ts    From Json-to-Dart-Model with MIT License 5 votes vote down vote up
private config: WorkspaceConfiguration;
Example #12
Source File: gopExtraInfo.ts    From vscode-goplus with Apache License 2.0 5 votes vote down vote up
private goPlusConfig: WorkspaceConfiguration | undefined;
Example #13
Source File: gopExtraInfo.ts    From vscode-goplus with Apache License 2.0 5 votes vote down vote up
constructor(goPlusConfig?: WorkspaceConfiguration) {
		this.goPlusConfig = goPlusConfig;
	}
Example #14
Source File: MockDendronExtension.ts    From dendron with GNU Affero General Public License v3.0 5 votes vote down vote up
getWorkspaceConfig(): WorkspaceConfiguration {
    // TODO: the old implementation of this was wrong - it did not return WorkspaceConfiguration but a WorkspaceSettings object
    // since this doesn't seem to be used, just adding an exception here for future work
    throw Error("not implemented");
  }
Example #15
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 };
  }
Example #16
Source File: index.ts    From cloudmusic-vscode with MIT License 5 votes vote down vote up
FOREIGN = (conf: WorkspaceConfiguration): boolean =>
  conf.get("network.foreignUser", false)
Example #17
Source File: index.ts    From cloudmusic-vscode with MIT License 5 votes vote down vote up
HTTPS_API = (conf: WorkspaceConfiguration): boolean =>
  conf.get("network.httpsAPI", true)
Example #18
Source File: index.ts    From cloudmusic-vscode with MIT License 5 votes vote down vote up
MUSIC_CACHE_SIZE = (conf: WorkspaceConfiguration): number =>
  conf.get("cache.size", 4096) * 1024 * 1024
Example #19
Source File: index.ts    From cloudmusic-vscode with MIT License 5 votes vote down vote up
MUSIC_QUALITY = (conf: WorkspaceConfiguration): number =>
  conf.get<128000 | 192000 | 320000 | 999000>("music.quality", 192000)
Example #20
Source File: index.ts    From cloudmusic-vscode with MIT License 5 votes vote down vote up
CONF = (): WorkspaceConfiguration =>
  workspace.getConfiguration("cloudmusic")
Example #21
Source File: driveExtensionSettings.ts    From google-drive-vscode with MIT License 5 votes vote down vote up
function settingsGroup(): WorkspaceConfiguration {
    return workspace.getConfiguration(EXTENSION_SETTINGS_GROUP);
}