Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify API for updating settings #54183

Closed
weinand opened this issue Jul 12, 2018 · 2 comments
Closed

Simplify API for updating settings #54183

weinand opened this issue Jul 12, 2018 · 2 comments
Assignees
Labels
api config VS Code configuration, set up issues feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Milestone

Comments

@weinand
Copy link
Contributor

weinand commented Jul 12, 2018

Today the API for modifying settings supports to target the different settings stores (user, workspace, folder). This is powerful but a bit laborious to use.

If you need to update a value in the store where it came from, you need to write code to figure out where it came from and then select the appropriate target value for passing it to WorkspaceConfiguration.update.

This results in something like this:

	const conf = vscode.workspace.getConfiguration('debug.node');
	const info = conf.inspect('autoAttach');
        const value = conf.get('autoAttach');
	let target: vscode.ConfigurationTarget = vscode.ConfigurationTarget.Global;
	if (info) {
		if (info.workspaceFolderValue) {
			target = vscode.ConfigurationTarget.WorkspaceFolder;
		} else if (info.workspaceValue) {
			target = vscode.ConfigurationTarget.Workspace;
		} else if (info.globalValue) {
			target = vscode.ConfigurationTarget.Global;
		} else if (info.defaultValue) {
			// setting not yet used: store setting in workspace
			if (vscode.workspace.workspaceFolders) {
				target = vscode.ConfigurationTarget.Workspace;
			}
		}
	}
	conf.update('autoAttach', !value, target);

I suggest that we simplify the API a bit.

Currently I see two approaches:

  1. Add a new enum value originalTarget to the ConfigurationTarget type. With this a setting value can be toggled like this:
    const conf = vscode.workspace.getConfiguration('debug.node');
    const value = conf.get('autoAttach');
    conf.update('autoAttach', !value, vscode.ConfigurationTarget.originalTarget);
  1. Add a new attribute effectiveTarget to the structure returned from WorkspaceConfiguration.inspect. effectiveTarget would contain the target where the value came from. With this a setting value can be toggled like this:
    const conf = vscode.workspace.getConfiguration('debug.node');
    const info = conf.inspect('autoAttach');
    const value = conf.get('autoAttach');
    conf.update('autoAttach', !value, info.effectiveTarget);
@weinand weinand added feature-request Request for new features or functionality api labels Jul 12, 2018
@sandy081 sandy081 added this to the July 2018 milestone Jul 13, 2018
@sandy081
Copy link
Member

I like the first approach of giving a different target value to update to specify an effective target. Getting from inspect might not be correct as if a setting is not defined only in default settings then it does not makes sense to return user target as effective target.

@sandy081 sandy081 modified the milestones: July 2018, August 2018 Jul 24, 2018
@sandy081 sandy081 modified the milestones: August 2018, September 2018 Aug 27, 2018
@sandy081 sandy081 modified the milestones: September 2018, Backlog Sep 26, 2018
@sandy081 sandy081 added the config VS Code configuration, set up issues label Sep 26, 2018
@sandy081 sandy081 added the *out-of-scope Posted issue is not in scope of VS Code label Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api config VS Code configuration, set up issues feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

3 participants
@weinand @sandy081 and others