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

LSP: Advertise which CodeActionKinds the server supports to prevent blocking formatters in VS Code #8277

Closed
jvilk-stripe opened this issue Jan 31, 2020 · 0 comments

Comments

@jvilk-stripe
Copy link

See microsoft/vscode#89745 and flow/flow-for-vscode#375

Flow version: 0.107.0 (although it's the same in new versions)

Expected behavior

Flow advertises which CodeActionKinds it supports during initialization:

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

Actual behavior

Flow advertises true or false, telling VS Code that it may support all code actions.

As a result, VS Code believes the Flow extension supports "source.fixAll" code actions, which is a non-standard code action that can block formatters like Prettier from running:

https://code.visualstudio.com/api/references/vscode-api#CodeActionKind

Since Flow can be slow to respond to code action requests when typechecking edits, users can see a multi-second wait before Prettier runs in VS Code.

This is only an issue if the user configures VS Code to apply "fixall" code actions before save. Unfortunately for Flow, the VS Code ESLint extension now uses source.fixAll code actions to surface ESLint fixups, and encourages users to configure VS Code to apply all ESLint fixups on save:

https://github.com/Microsoft/vscode-eslint#release-notes

"editor.codeActionsOnSave": {
  "source.fixAll.eslint": true
}

This setting tells VS Code "apply all fixups for the range covered by a diagnostic with source eslint". Thus, VS Code queries all code action providers for JavaScript that support source.fixAll code actions to see if they have fixes for diagnostics with "source" set to "eslint" -- including flow. These requests block prettier from running.

A workaround is to disable code actions entirely in Flow.

  • Link to Try-Flow or Github repo:
@mroch mroch added LSP and removed needs triage labels Jan 31, 2020
facebook-github-bot pushed a commit that referenced this issue Mar 3, 2020
Summary:
Telling the LSP client that we're a codeActionProvider means that it'll ask us for codeActions when the user hovers over errors. This'll let us provide quickfixes corresponding to type errors; specifically, the "Did you mean?" type error.

The codeActions we'll provide (both the existing "autofix exports" actions and the "did you mean?" actions being added in D20003667) will be quickfix CodeAction literals, so we initialize as a provider of quickfixes iff the client supports quickfix CodeAction literals.

Fixes #8277

Reviewed By: nmote

Differential Revision: D19919160

fbshipit-source-id: 32aa3dbcaa7d083fe5141557892fb8d8912d6ffe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants