|
| 1 | +# Document Editing Sample |
| 2 | + |
| 3 | +This example demonstrates the usage of the "when clause" [`in` conditional operator`](https://code.visualstudio.com/api/references/when-clause-contexts#in-conditional-operator) |
| 4 | +To create **dynamic** context menus based on **custom** provided logic. |
| 5 | + |
| 6 | +In this example we have two context menus entries when right-clicking on `package.json` files. |
| 7 | +These entries should only be displayed to the end-user under specific conditions: |
| 8 | +- `Install Dependencies` should only appear if the **specific** `package.json` file includes |
| 9 | + a dependencies or devDependencies section. |
| 10 | +- `Run Tests` should only appear if the **specific** `package.json` includes a `scripts.test` section. |
| 11 | + |
| 12 | +## Demo |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +## VS Code API |
| 17 | + |
| 18 | +### `vscode` module |
| 19 | + |
| 20 | +- [`workspace.findFiles`](https://code.visualstudio.com/api/references/vscode-api#workspace.findFIles) |
| 21 | +- [`workspace.createFileSystemWatcher`](https://code.visualstudio.com/api/references/vscode-api#workspace.createFileSystemWatcher) |
| 22 | +- [`commands.registerCommand`](https://code.visualstudio.com/api/references/vscode-api#commands.registerCommand) |
| 23 | +- [`commands.executeCommand`](https://code.visualstudio.com/api/references/vscode-api#commands.executeCommand) |
| 24 | +- [`tasks.executeTask`](https://code.visualstudio.com/api/references/vscode-api#tasks.executeTask) |
| 25 | + |
| 26 | +### Contribution Points |
| 27 | + |
| 28 | +- [`contributes.commands`](https://code.visualstudio.com/api/references/contribution-points#contributes.commands) |
| 29 | +- [`contributes.menus`](https://code.visualstudio.com/api/references/contribution-points#contributes.menus) |
| 30 | + |
| 31 | + |
| 32 | +## Running the Sample |
| 33 | + |
| 34 | +- Run `npm install` in terminal to install dependencies. |
| 35 | +- Run `npm compile` in terminal to compile the sources. |
| 36 | +- Run the `Run Extension` target in the Debug View this will run the extension in a new VS Code window. |
| 37 | +- `file` --> `Open Folder` --> [`example-workspace`](./example-workspace) in the new VS Code window. |
| 38 | +- Wait a few seconds for the file watcher to initialize the context state. |
| 39 | +- Right click on the four different `package.json` files available in that folder and |
| 40 | + note how the `Install Dependencies` and `Run Tests` context menus only appear where relevant. |
0 commit comments