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

Analysis server should not need to resolve a file in order to format it #56960

Closed
stereotype441 opened this issue Oct 24, 2024 · 3 comments
Closed
Assignees
Labels
analyzer-editing-experience area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@stereotype441
Copy link
Member

The analysis server code for running the formatter calls AnalysisDriver.getResolvedUnit, which means that it won't be able to format the file until it's fully resolved it. It would be nice if it could use an analysis API that didn't require resolution, since that could in principle make formatting much faster.

The reason it currently uses AnalysisDriver.getResolvedUnit is because it needs unit.libraryElement2.effectiveLanguageVersion in order to tell the formatter which language version to use for formatting. But this feels like overkill; it should be possible to figure out the langauge version based on the unresolved AST and some information from the context.

See discussion here: https://dart-review.googlesource.com/c/sdk/+/391840/comment/5e5314af_b5c7db9a/

@stereotype441 stereotype441 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-editing-experience labels Oct 24, 2024
@bwilkerson
Copy link
Member

See also https://dart-review.googlesource.com/c/sdk/+/391663/2/pkg/analysis_server/lib/src/lsp/source_edits.dart, which indicates that the problem can be resolved by adding one public getter to CompilationUnit (a getter that's already implemented in CompilationUnitImpl).

@munificent
Copy link
Member

I ran into a similar issue with the IDE integration and @DanTup got that sorted out so maybe we can do something similar here.

@DanTup
Copy link
Collaborator

DanTup commented Oct 25, 2024

Ah, my fix was only for LSP (which was already using only a parsed AST). I'm looking at some changes so all CompilationUnits have a non-null version, so I'll fix this while I'm at it.

@DanTup DanTup self-assigned this Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-editing-experience area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

4 participants