Skip to content

Register Command onto the Nodes of Project View

Sheng Chen edited this page Sep 7, 2020 · 12 revisions

Start from version 0.13.0, we refined the context value of each node in the Project view, so other extensions can register their commands onto the nodes if they want to.

Context Value Format

java:<node type>[+<attribute>]*

Available Node Types:

Currently, available node types are:

  • workspaceFolder
  • project
  • container
  • packageRoot
  • package
  • jar

Not available node types are:

  • folder
  • file
  • type (class, enum, interface,...)

Below picture illustrates the different node types image

Attributes:

For each node type, it may have some attributes. Every attribute will start with a +.

Common Attributes:

  • +uri: The node has uri

Specific Attributes:

Project Node:

  • +java: Java project
  • +maven: Maven project
  • +gradle: Gradle project

Container Node:

  • +jre: Container for JRE
  • +maven: Container for Maven
  • +gradle: Container for Gradle
  • +referencedLibrary: Container for Referenced Libraries

Package Root Node:

  • +source: Source package root.
  • +resource: Resource package root

Package Node:

  • +source: Source package
  • +binary: Binary package (Expanded inside a binary jar)

Jar Node:

  • +referencedLibrary: Referenced Library jar

Usage example:

For example, A node for a Maven project may have the following context value:

java:project+maven+uri

If you want to register a command on that node, you can write your when clause in package.json as:

"contributes": {
  ...
  "menus": {
    ...
    "view/item/context": [
      {
        "command": "...",
        "when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+maven\\b)(?=.*?\\b\\+uri\\b)/",
        "group": "...
      }
    ]
  }
}
Clone this wiki locally