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 pattern matching to when clause, when contributing menus #26044

Closed
fbricon opened this issue May 5, 2017 · 9 comments · Fixed by #41646
Closed

Add pattern matching to when clause, when contributing menus #26044

fbricon opened this issue May 5, 2017 · 9 comments · Fixed by #41646
Assignees
Labels
extensions Issues concerning extensions feature-request Request for new features or functionality on-testplan
Milestone

Comments

@fbricon
Copy link
Contributor

fbricon commented May 5, 2017

  • VSCode Version: 1.12.0
  • OS Version: MacOS Sierra 10.12.4

In vscode-java, we'd like to be able to provide context menus for all gradle files. The current when clause is limited to language types ("when": "resourceLangId == groovy") or a single file name ("when": "resourceFilename == 'build.gradle'").

It would be helpful if there was support for glob pattern matching, as @jrieken mentioned in #3192 (comment)

@egamma egamma added the feature-request Request for new features or functionality label May 5, 2017
@alexdima alexdima added this to the Backlog milestone May 8, 2017
@alexdima alexdima added the extensions Issues concerning extensions label May 8, 2017
@alexdima alexdima removed their assignment May 8, 2017
@gawicks
Copy link

gawicks commented Aug 14, 2017

Hi, Any update on this?

@jrieken
Copy link
Member

jrieken commented Jan 23, 2018

@chrisdias I will push an additional change that expands this to support normal regular expressions instead of just glob-patterns. We figured that's more powerful and closer to ST

@jrieken jrieken changed the title Add glob pattern matching to when clause, when contributing menus Add pattern matching to when clause, when contributing menus Jan 23, 2018
@eamodio
Copy link
Contributor

eamodio commented Jan 23, 2018

Will this be usable in matching any when clause value? Can you give an example?

@jrieken
Copy link
Member

jrieken commented Jan 23, 2018

You write key =~ pattern, so resourceFilename =~ /.*Docker\d{2,3}.*$/ will execute this /.*Docker\d{2,3}.*$/.test(context.getValue('resourceName')). A sample from my dummy extensions (matches filenames ending in z)

"explorer/context": [
{
	"command": "extension.sayHello",
	"when": "resourceFilename =~ /z$/"
}]

@eamodio
Copy link
Contributor

eamodio commented Jan 23, 2018

This is AWESOME! Should reduce the number of duplicate menu items I need to define

@jrieken
Copy link
Member

jrieken commented Jan 24, 2018

Slight update on this: The value must be enclosed in slashes, so someName =~ /regexp/. I have updated above sample

@weinand
Copy link
Contributor

weinand commented Feb 6, 2018

@jrieken FYI:
I tried to apply this feature to the "loaded script view" by following the entry in the release notes:

2018-02-06_22-19-51

But without much success.

After looking into the test item and the corresponding feature item, I noticed that the latest syntax uses regular regexp syntax.

I've taken the liberty to change the release notes to this:

2018-02-07_00-31-02

I did not attempt to clarify why /docker/ actually matches "Docker files".

@webdeb
Copy link

webdeb commented Feb 23, 2018

Hmm, I am writing a simple copyName extension, and would like to copy any resourceName.

It works without any when clause, but the menu item also shows up, when r-clicking inside the empty space. I would like to prevent it.

Is there something like this "when": isResource ?

@webdeb
Copy link

webdeb commented Feb 23, 2018

Ok I found resourceIsFile. And its actually what I was looking for. But I did not found it in the docs, but code base.

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions Issues concerning extensions feature-request Request for new features or functionality on-testplan
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants