-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add in conditional operator sample
- Loading branch information
Showing
18 changed files
with
1,652 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/**@type {import('eslint').Linter.Config} */ | ||
// eslint-disable-next-line no-undef | ||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
plugins: [ | ||
'@typescript-eslint', | ||
], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
rules: { | ||
'semi': [2, "always"], | ||
'@typescript-eslint/no-unused-vars': 0, | ||
'@typescript-eslint/no-explicit-any': 0, | ||
'@typescript-eslint/explicit-module-boundary-types': 0, | ||
'@typescript-eslint/no-non-null-assertion': 0, | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | ||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | ||
|
||
// List of extensions which should be recommended for users of this workspace. | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// A launch configuration that compiles the extension and then opens it inside a new window | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Extension", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": [ | ||
"--extensionDevelopmentPath=${workspaceFolder}" | ||
], | ||
"outFiles": [ | ||
"${workspaceFolder}/out/**/*.js" | ||
], | ||
"preLaunchTask": "npm: watch" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.insertSpaces": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// See https://go.microsoft.com/fwlink/?LinkId=733558 | ||
// for the documentation about the tasks.json format | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "npm", | ||
"script": "watch", | ||
"problemMatcher": "$tsc-watch", | ||
"isBackground": true, | ||
"presentation": { | ||
"reveal": "never" | ||
}, | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# `in` Conditional Operator Sample | ||
|
||
This example demonstrates the usage of the "when clause" [`in` conditional operator`](https://code.visualstudio.com/api/references/when-clause-contexts#in-conditional-operator) | ||
To create **dynamic** context menus based on **custom** provided logic. | ||
|
||
In this example we have two context menus entries when right-clicking on `package.json` files. | ||
These entries should only be displayed to the end-user under specific conditions: | ||
- `Install Dependencies` should only appear if the **specific** `package.json` file includes | ||
a dependencies or devDependencies section. | ||
- `Run Tests` should only appear if the **specific** `package.json` includes a `scripts.test` section. | ||
|
||
## Demo | ||
|
||
 | ||
|
||
## VS Code API | ||
|
||
### `vscode` module | ||
|
||
- [`workspace.findFiles`](https://code.visualstudio.com/api/references/vscode-api#workspace.findFIles) | ||
- [`workspace.createFileSystemWatcher`](https://code.visualstudio.com/api/references/vscode-api#workspace.createFileSystemWatcher) | ||
- [`commands.registerCommand`](https://code.visualstudio.com/api/references/vscode-api#commands.registerCommand) | ||
- [`commands.executeCommand`](https://code.visualstudio.com/api/references/vscode-api#commands.executeCommand) | ||
- [`tasks.executeTask`](https://code.visualstudio.com/api/references/vscode-api#tasks.executeTask) | ||
|
||
### Contribution Points | ||
|
||
- [`contributes.commands`](https://code.visualstudio.com/api/references/contribution-points#contributes.commands) | ||
- [`contributes.menus`](https://code.visualstudio.com/api/references/contribution-points#contributes.menus) | ||
|
||
|
||
## Running the Sample | ||
|
||
- Run `npm install` in terminal to install dependencies. | ||
- Run `npm compile` in terminal to compile the sources. | ||
- Run the `Run Extension` target in the Debug View this will run the extension in a new VS Code window. | ||
- `file` --> `Open Folder` --> [`example-workspace`](./example-workspace) in the new VS Code window. | ||
- Wait a few seconds for the file watcher to initialize the context state. | ||
- Right click on the four different `package.json` files available in that folder and | ||
note how the `Install Dependencies` and `Run Tests` context menus only appear where relevant. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
|
||
# These are part of the demo flow | ||
# no need to pollute the source control | ||
package-lock.json | ||
|
11 changes: 11 additions & 0 deletions
11
in-conditional-operator-sample/example-workspace/with-both/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "with-deps", | ||
"version": "1.0.0", | ||
"description": "Example of a package.json with both `dependencies` and `test script` sections", | ||
"dependencies": { | ||
"lodash": "^4.17.21" | ||
}, | ||
"scripts": { | ||
"test": "echo \"hello cruel world!\"" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
in-conditional-operator-sample/example-workspace/with-deps/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "with-deps", | ||
"version": "1.0.0", | ||
"description": "Example of a package.json with `dependencies` but without `test script` sections", | ||
"dependencies": { | ||
"lodash": "^4.17.21" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
in-conditional-operator-sample/example-workspace/with-neither/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "with-deps", | ||
"version": "1.0.0", | ||
"description": "Example of a package.json without both `dependencies` and `test script` sections", | ||
"scripts": { | ||
"build" : "echo \"compiling...\"" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
in-conditional-operator-sample/example-workspace/with-test-script/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "with-scripts", | ||
"version": "1.0.0", | ||
"description": "Example of a package.json with `test script` but without `dependencies` sections", | ||
"scripts": { | ||
"test" : "echo \"hello cruel world!\"" | ||
} | ||
} |
Oops, something went wrong.