microsoft / microsoft/TypeScript

"fix everything in this file" code action

Open
#29,452 0 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: API Domain: LS: Quick Fixes Domain: LS: TSServer In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked VS Code proposal and the TypeScript server API discussion. The issue names no files, tests, or existing entry point, so the first step is to identify the relevant language-service and code-action interfaces. Done would require an agreed API and an initial implementation covering the proposed diagnostic fixes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers, devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.