Skip to content

Prevent running Fix-All on-save from removing unused imports #4561

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

Closed
DanTup opened this issue May 24, 2023 · 1 comment
Closed

Prevent running Fix-All on-save from removing unused imports #4561

DanTup opened this issue May 24, 2023 · 1 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
Milestone

Comments

@DanTup
Copy link
Member

DanTup commented May 24, 2023

Placeholder for release notes, and for discoverability when this behaviour changes.

Before a recent SDK change, using fix-all-on-save in VS Code would also remove unused imports:

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

This behaviour was a little inconsistent without iterative fix-all (it would not remove the imports if other fixes were applied). Iterative fix-all made it consistent, but this behaviour is not what many users want (for example if they'd temporarily commented out code).

With this change, imports will not be touched when using fix-all if it was invoked automatically by save. However, it's possible to retain the original behaviour by invoked listing the original fix, or (more efficiently) source.organizeImports) to run on-save:

"editor.codeActionsOnSave": {
	"source.fixAll": true,
	"source.organizeImports": true
}
@DanTup DanTup added is enhancement in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server labels May 24, 2023
@DanTup DanTup added this to the Requires SDK Release milestone May 24, 2023
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue May 25, 2023
…un automatically on-save

Before this change, using fix-all-on-save in VS Code would also remove unused imports:

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

This behaviour was a little inconsistent without iterative fix-all (it would not remove the imports if other fixes were applied). Iterative fix-all made it consistent, but this behaviour is not what many users want (for example if they'd temporarily commented out code).

With this change, imports will not be touched when using fix-all if it was invoked automatically by save. However, it's possible to retain the original behaviour by invoked listing the original fix, or (more efficiently) `source.organizeImports`) to run on-save:

```
"editor.codeActionsOnSave": {
	"source.fixAll": true,
	"source.organizeImports": true
}
```

Fixes #52046
Fixes Dart-Code/Dart-Code#4561

Change-Id: If68a5d13c2c1c9a494be61872c942fca8a4dd35c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305021
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
@DanTup
Copy link
Member Author

DanTup commented Jun 7, 2023

Done in dart-lang/sdk@3054053.

@DanTup DanTup closed this as completed Jun 7, 2023
@DanTup DanTup modified the milestones: Requires SDK Release, v3.70.0 Jul 27, 2023
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

1 participant