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 codeActionsOnSave to docs #3938

Merged
merged 3 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions docs/languages/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,48 +223,16 @@ The `editor.codeActionsOnSave` setting lets you configure a set of Code Actions
"source.organizeImports": true,
}
```
You can also enable or disable which Code Actions are run on save per language using a language specific setting:
```json
"[javascript]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
```

Here are some source actions:

* `"organizeImports"` - Enables organize imports on save.
* `"fixAll"` - Auto Fix on Save computes all possible fixes in one round (for all providers including ESLint).
* `"fixAll.eslint"` - Auto Fix only for ESLint.
* `"addMissingImports"` - Adds all missing imports on save.

The TSLint extension already uses `source.fixAll` Code Action kind to implement fix all and auto fix on save.
See [Node.js/JavaScript](/docs/nodejs/working-with-javascript) for more information.
Copy link

@Luxcium Luxcium Aug 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you prefer to link to a subsection instead but I found the subsection links just in case:

https://code.visualstudio.com/docs/getstarted/settings#_language-specific-editor-settings

For organizeImports specifically in Node.js/JavaScript:
https://code.visualstudio.com/docs/languages/javascript#_organize-imports


You can also set `editor.codeActionsOnSave` to an array of Code Actions to execute in order. You can use this to guarantee that a specific Code Action is always run before or after another one that may conflict with it.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep this part (with or without the example‽) :

You can also set editor.codeActionsOnSave to an array of Code Actions to execute in order. You can use this to guarantee that a specific Code Action is always run before or after another one that may conflict with it.

The following `editor.codeActionsOnSave` will always run Organize Imports followed by Fix All once organize imports finishes:
```json
"editor.codeActionsOnSave": [
"source.organizeImports",
"source.fixAll"
]
```
Note: `editor.codeActionsOnSave` supports both object and array configs in settings.

Examples:

Selective behaviour for different source actions:
```json
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.fixAll.eslint": false
}
```
Add all missing imports on save:
```json
"editor.codeActionsOnSave": [
"source.addMissingImports"
]
```

## Code suggestions

Expand Down
35 changes: 2 additions & 33 deletions docs/languages/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,48 +255,17 @@ The `editor.codeActionsOnSave` setting lets you configure a set of Code Actions
"source.organizeImports": true,
}
```
You can also enable or disable which Code Actions are run on save per language using a language specific setting:
```json
"[typescript]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
```

Here are some source actions:

* `"organizeImports"` - Enables organize imports on save.
* `"fixAll"` - Auto Fix on Save computes all possible fixes in one round (for all providers including ESLint).
* `"fixAll.eslint"` - Auto Fix only for ESLint.
* `"addMissingImports"` - Adds all missing imports on save.

The TSLint extension already uses `source.fixAll` Code Action kind to implement fix all and auto fix on save.

You can also set `editor.codeActionsOnSave` to an array of Code Actions to execute in order. You can use this to guarantee that a specific Code Action is always run before or after another one that may conflict with it.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you guys think it is possible to retain the part where you explain the reason why one should prefer using an array over an object ?? 

You can also set editor.codeActionsOnSave to an array of Code Actions to execute in order. You can use this to guarantee that a specific Code Action is always run before or after another one that may conflict with it.
The following editor.codeActionsOnSave will always run Organize Imports followed by Fix All once organize imports finishes:

"editor.codeActionsOnSave": [	
    "source.organizeImports",	
    "source.fixAll"	
]	

The following `editor.codeActionsOnSave` will always run Organize Imports followed by Fix All once organize imports finishes:
```json
"editor.codeActionsOnSave": [
"source.organizeImports",
"source.fixAll"
]
```
Note: `editor.codeActionsOnSave` supports both object and array configs in settings.
See [TypeScript](/docs/typescript/typescript-tutorial) for more information.
Copy link

@Luxcium Luxcium Aug 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you prefer to link to a subsection instead but I found the subsection links just in case:

https://code.visualstudio.com/docs/getstarted/settings#_language-specific-editor-settings

For organizeImports specifically in TypeScript:
https://code.visualstudio.com/docs/languages/typescript#_organize-imports


Examples:

Selective behaviour for different source actions:
```json
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.fixAll.eslint": false
}
```
Add all missing imports on save:
```json
"editor.codeActionsOnSave": [
"source.addMissingImports"
]
```
## Code suggestions

VS Code automatically suggests some common code simplifications such as converting a chain of `.then` calls on a promise to use `async` and `await`
Expand Down