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 lints on format/save and Fix-all #3445

Closed
rrousselGit opened this issue Jul 1, 2021 · 4 comments
Closed

Fix lints on format/save and Fix-all #3445

rrousselGit opened this issue Jul 1, 2021 · 4 comments
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement
Milestone

Comments

@rrousselGit
Copy link

Is your feature request related to a problem? Please describe.
Numerous lints come with an auto-fix option, but we have to apply the fixes almost one by one, which is tedious.

Describe the solution you'd like
Since VS code already keeps tracks of the list of issues and offers to fix them, VS code could expose a command for "apply all fixes".

Similarly, we could have an option to, right before executing dartfmt, apply fixes for the file.

Describe alternatives you've considered
N/A

Additional context
N/A

@DanTup DanTup added this to the v3.25.0 milestone Jul 1, 2021
@DanTup DanTup added in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server labels Jul 1, 2021
@DanTup
Copy link
Member

DanTup commented Jul 1, 2021

I think this would make sense implemented as a Source CodeAction (source.fixAll), which can be added to editor.codeActionsOnSave:

https://code.visualstudio.com/updates/v1_32#_fix-all-source-actions

It should follow the guides given by VS Code:

Fix all actions automatically fix errors that have a clear fix that do not require user input. They should not suppress errors or perform unsafe fixes such as generating new types or classes.

It should be implemented in the server so it's a single request that builds all fixes, and not enumerated on the client as applying fixes for one diagnostic could interfere with others (for example changing offsets, or invalidating some other fixes), and repeated round trips to the server could be slow.

I think the server already has all the parts necessary for this (between dart fix and the (experimental) edit.bulkFixes call in the original protocol), but I'm not certain if they're stable enough to expose here yet.

@DanTup
Copy link
Member

DanTup commented Jul 7, 2021

dart-lang/sdk@85d455f adds an implementation for "source.fixAll" which can be run from the command palette (Fix All) or added to editor.codeActionsOnSave.

It only fixes the same things that dart fix/flutter fix will fix (which is not the whole set of fixes available in the lightbulb menu, but those that are deemed safe to fix in an automated way (this work might not be complete, so it may still expand over time)).

@DanTup DanTup closed this as completed Jul 7, 2021
@ViniciusSossela
Copy link

@DanTup @rrousselGit I am trying to launch the Fix All command, but it doesn't show on the command palette. Am I missing something?

Screen Shot 2021-08-03 at 10 11 21

Screen Shot 2021-08-03 at 10 13 45

Flutter 2.2.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f4abaa0735 (5 weeks ago) • 2021-07-01 12:46:11 -0700
Engine • revision 241c87ad80
Tools • Dart 2.13.4

@DanTup
Copy link
Member

DanTup commented Aug 3, 2021

See my reply at #3469 (comment), thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement
Projects
None yet
Development

No branches or pull requests

3 participants