Skip to content

Commit a27f6c6

Browse files
committed
feat: add in conditional operator sample
1 parent aa42c2e commit a27f6c6

File tree

18 files changed

+1652
-0
lines changed

18 files changed

+1652
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**@type {import('eslint').Linter.Config} */
2+
// eslint-disable-next-line no-undef
3+
module.exports = {
4+
root: true,
5+
parser: '@typescript-eslint/parser',
6+
plugins: [
7+
'@typescript-eslint',
8+
],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
],
13+
rules: {
14+
'semi': [2, "always"],
15+
'@typescript-eslint/no-unused-vars': 0,
16+
'@typescript-eslint/no-explicit-any': 0,
17+
'@typescript-eslint/explicit-module-boundary-types': 0,
18+
'@typescript-eslint/no-non-null-assertion': 0,
19+
}
20+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3+
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4+
5+
// List of extensions which should be recommended for users of this workspace.
6+
"recommendations": [
7+
"dbaeumer.vscode-eslint"
8+
]
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"runtimeExecutable": "${execPath}",
13+
"args": [
14+
"--extensionDevelopmentPath=${workspaceFolder}"
15+
],
16+
"outFiles": [
17+
"${workspaceFolder}/out/**/*.js"
18+
],
19+
"preLaunchTask": "npm: watch"
20+
}
21+
]
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.insertSpaces": false
3+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "watch",
9+
"problemMatcher": "$tsc-watch",
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never"
13+
},
14+
"group": {
15+
"kind": "build",
16+
"isDefault": true
17+
}
18+
}
19+
]
20+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
![demo](./demo.gif)
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.
1.57 MB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
3+
# These are part of the demo flow
4+
# no need to pollute the source control
5+
package-lock.json
6+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "with-deps",
3+
"version": "1.0.0",
4+
"description": "Example of a package.json with both `dependencies` and `test script` sections",
5+
"dependencies": {
6+
"lodash": "^4.17.21"
7+
},
8+
"scripts": {
9+
"test": "echo \"hello cruel world!\""
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "with-deps",
3+
"version": "1.0.0",
4+
"description": "Example of a package.json with `dependencies` but without `test script` sections",
5+
"dependencies": {
6+
"lodash": "^4.17.21"
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "with-deps",
3+
"version": "1.0.0",
4+
"description": "Example of a package.json without both `dependencies` and `test script` sections",
5+
"scripts": {
6+
"build" : "echo \"compiling...\""
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "with-scripts",
3+
"version": "1.0.0",
4+
"description": "Example of a package.json with `test script` but without `dependencies` sections",
5+
"scripts": {
6+
"test" : "echo \"hello cruel world!\""
7+
}
8+
}

0 commit comments

Comments
 (0)