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

Add in operator support to when clauses #97544

Closed
eamodio opened this issue May 11, 2020 · 6 comments · Fixed by #104625
Closed

Add in operator support to when clauses #97544

eamodio opened this issue May 11, 2020 · 6 comments · Fixed by #104625
Assignees
Labels
context-keys feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan
Milestone

Comments

@eamodio
Copy link
Contributor

eamodio commented May 11, 2020

Refs: #96927

There is a desire to be able to show a context menu command conditionally on explorer folders (or others) based on computed/determined criteria. For example, lets say I have a folder with a certain file type in it (or all of the same type) and I want to offer a command to only show up for folders that match that criteria. Today this isn't possible, since we don't offer any trigger on selection in the explorer tree (so you can't set a "global" context value), nor is it possible to lookup a context value using another context value.

To address this I propose a new in operator to be supported. This in operator would allow using an existing context key as a lookup key into another context value. The target of the in would be either an array or an object.

For example:

Given something like the following context key,

foldersToShowCommandFor: [ 'test', 'src/foo', 'src/foo/bar' ];

You'd then be able to use the following when on a command:

"menus": {
	"explorer/context": [
		{
			"command": "ext.jsFolder",
                        "when": "explorerResourceIsFolder && resourceFilename in foldersToShowCommandFor"
		}
	]
}

@idoprz Please add any more details or specifics about your use case too.

//cc @alexdima @jrieken

@isidorn
Copy link
Contributor

isidorn commented May 12, 2020

This can not be solved just to be specific to the explorer, thus unassing myself.

@isidorn isidorn removed their assignment May 12, 2020
@idoprz
Copy link

idoprz commented May 12, 2020

Hi,

Looks great to me! would solve allot of problems.
How would I set "foldersToShowCommandFor"? I assume I can set it in my extension code? Do I use setContext command for it? I saw it been used in GitLens, but it's not documented (#46445). Is it ok to use it?

@alexdima alexdima self-assigned this May 12, 2020
@alexdima alexdima added the feature-request Request for new features or functionality label May 12, 2020
@alexdima alexdima added this to the Backlog milestone May 12, 2020
@alexdima alexdima removed their assignment May 12, 2020
@idoprz

This comment has been minimized.

@idoprz
Copy link

idoprz commented Jul 19, 2020

Hi,
Is this item going into development?

@eamodio
Copy link
Contributor Author

eamodio commented Aug 14, 2020

@idoprz I've opened a PR for this feature. Hopefully we can get it in soon.

@idoprz
Copy link

idoprz commented Aug 15, 2020

Amazing! Thanks for following through.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
context-keys feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@eamodio @isidorn @alexdima @idoprz and others