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

"fix everything in this file" code action #29452

Open
mjbvz opened this issue Jan 17, 2019 · 0 comments
Open

"fix everything in this file" code action #29452

mjbvz opened this issue Jan 17, 2019 · 0 comments
Labels
API Relates to the public API for TypeScript Domain: Quick Fixes Editor-provided fixes, often called code actions. Domain: TSServer Issues related to the TSServer In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jan 17, 2019

VS Code is investigating an api for better support for fixing all fixable errors in a file with a single action. This action could also be triggered on save. You can find the current proposal here

Motivating use case

You change a file's extension from ts to js and start seeing lots of errors about converting your old jsdocs to real types. Thankfully you've enabled "editor.codeActionsOnSave": { "source.autoFix": true } in VS Code and TypeScript has implemented this feature. So you just save the file and all your jsdocs are converted to types (along with fixing other trivial errors)

Current VS Code proposal

The current VS Code proposal for this requires that extensions return a single source code action marked as autoFix. This action would contain all auto-fix edits for the file. We'd handle applying these edits on save.

Proposal for TS

To implement this properly for TS, we likely need a new TS server api that would take a file and return a set of edits that fix all of the trivial errors within that file. Making this a single API call per file allows TS to properly handle overlapping fixes within the file. Candidates for what could be fixed automatically:

  • Errors with one, well known quick fix, such as convert jsdocs to types
  • Trivial coding errors where the intent of the programmer was clear.

I see this feature as being especially helpful for JS -> TS. The initial implementation would only need to support fixes for a small set of diagnostics, which could be expanded in future releases.

/cc @DanielRosenwasser, @minestarks, @amcasey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Domain: Quick Fixes Editor-provided fixes, often called code actions. Domain: TSServer Issues related to the TSServer In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants