Open stereotype441 opened 4 hours ago
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
).
I ran into a similar issue with the IDE integration and @DanTup got that sorted out so maybe we can do something similar here.
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 needsunit.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/