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

Simpler quick fix API #46249

Open
mjbvz opened this issue Oct 6, 2021 · 4 comments
Open

Simpler quick fix API #46249

mjbvz opened this issue Oct 6, 2021 · 4 comments
Assignees
Labels
API Relates to the public API for TypeScript Domain: TSServer Issues related to the TSServer In Discussion Not yet reached consensus Suggestion An idea for TypeScript VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Oct 6, 2021

Follow up on #27614

Search terms

  • code action / codeaction
  • quick fix / quickfix
  • getCodeFixes
  • getSupportedCodeFixes

Problem

The getCodeFixes API currently takes a range plus a diagnostic code. Currently, the range we pass to it has to match the range of the diagnostic we are trying to fix. This API is difficult for editors to implement for a few reasons:

  • We need to make multiple requests if we want to display quick fixes for multiple (potentially overlapping) diagnostics
  • The editor has to ensure that the diagnostics as fully synchronized with the current text buffer state before making the request. It's easy for the editor's diagnostics to get temporarily out of sync with those on the server
  • The editor has to keep around a list of diagnostics to make these requests

Proposal

We should consider a new quick fix API that addresses these problems and also is better aligned with the language server protocol. My proposal is that instead of having to think about diagnostics, editors pass the TS Server a range and are returned the valid quick fixes in that range.

Here's what the VS Code api for this looks like:

https://github.com/microsoft/vscode/blob/9a21b536639c2d986c50fb51b7da67bafdb50c9b/src/vs/vscode.d.ts#L2336

And here's the LSP:

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction

@mjbvz
Copy link
Contributor Author

mjbvz commented Oct 7, 2021

microsoft/vscode#117812 shows another case where a different API could help us ship a better user experience. Right now, you have to wait a moment to get fixes after you introduce an error in a file

@DanielRosenwasser DanielRosenwasser added API Relates to the public API for TypeScript In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Oct 8, 2021
@Kingwl
Copy link
Contributor

Kingwl commented Oct 9, 2021

Might also refactor?

@andrewbranch
Copy link
Member

@justschen
Copy link

@navya9singh @DanielRosenwasser just an update - on the VS Code extension side of things, @mjbvz and I have added a fix to handle the issue when there are pending diagnostics at the point of re-requesting code actions microsoft/vscode#117812

this is currently in our latest insiders, but lmk if this leads to any issues with the changes in the API, or when those changes land!

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: TSServer Issues related to the TSServer In Discussion Not yet reached consensus Suggestion An idea for TypeScript VS Code Priority Critical issues that VS Code needs fixed in the current TypeScript milestone
Projects
None yet
Development

No branches or pull requests

6 participants