-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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] Need to plumb through experiment flags to DartFormatter
#54139
Comments
\cc @DanTup Since I'm not sure if LSP or the VS Code extension accesses the formatter differently. |
For LSP we use the formatter by referencing
It's possible we have multiple contexts with their own FYI @bwilkerson @pq I dont' know if this might also be impacted by changes to contexts. I guess we need to be able to get from a path/parsed result to a |
It's a little simpler than that. We don't cache the formatter, we re-create it every time it's needed. (It's a lightweight object, so instantiating one is inexpensive.) We will need to use the new APIs to determine which experiments are enabled, but those APIs already exist, so that should be doable now. |
Oh, that's much simpler. In LSP we currently do cache it and I thought I had copied that from legacy (and there was a reason for it), but perhaps it was just an optimisation I invented and can be removed :-) @parlough do you have an example of how to trigger the crash you see? (and were you planning to look at this, or shall I?) |
It's possible that we're caching it and I didn't realize it, but I don't think we should need to. |
No I think you're right - I couldn't see any caching except in LSP, so I think that was my doing and it's unnecessary. Looking through https://github.com/dart-lang/dart_style/blob/main/lib/src/dart_formatter.dart I also don't see any state that seems like it would benefit from this. |
Sorry, I wasn't fully clear, the analysis server doesn't crash, just fails to format. In IntelliJ this is surfaced as "Failed to format code", and in VS Code it doesn't seem any warning is shown to the user by default, the formatter just silently fails. (I've seen other people raise that as a point of confusion before). For reproducing:
I'm not going to have time for a few days due to the US holiday, so if you want to take a look, that'd be appreciated! I also am not sure the best/desired way to get access to the analysis context from the |
As for caching, yeah I agree it's not necessary from looking at the formatter. |
I'll also note that this isn't a high priority as the inline-class experiment has been enabled by default on main at this point. To the best of my knowledge the formatter doesn't yet support any of the not-yet-enabled experimental language features. |
Unfortunately I don't think that will work this time, since Maybe that needs to change its logic as well (otherwise Edit: Updating |
I can reproduce the issue with a simple LSP test that uses @bwilkerson I have a |
You're right. The default language version has to be increased before extension types will be parsed correctly. Technically the formatter ought to be passing in the real default language version as specified by the minimum SDK constraints. That's something that the analyzer can probably compute for it, so it shouldn't require too much work. But I have to wonder whether we might want the formatter to just always use the version of the language that's supported by the version of the
It looks like the
I've actually suggested a few times that the formatter might want an API for the server to use that would allow us to pass in the already parsed AST. That would be slightly more efficient, though parsing is really fast, so not a huge performance gain. But assuming that the formatter wouldn't crash given ASTs containing nodes it doesn't yet know about, it would eliminate the need to pass this information back into the formatter. I suspect, though, that we need @munificent's input before we can go much farther in deciding how best to communicate this data to the formatter. |
This CL allows experiments to be passed to `dart fix` and subsequently the analysis server. The analysis server will still need to pass the experiments to the formatter, which is tracked in #54139. Closes #54142 Bug: #54142 Change-Id: Ib436b0c1375d1d878f18668bb799a9d275fb9fda Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338060 Reviewed-by: Ben Konyi <bkonyi@google.com> Auto-Submit: Parker Lougheed <parlough@gmail.com> Reviewed-by: Keerti Parthasarathy <keertip@google.com> Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Yes, it should be updated. Sorry I missed that one. Thank you for the fix! |
Closing in favor of #55125 which has a bit more focused discussion on the remaining tasks here. Thanks all! |
After dart-lang/dart_style#1256,
dart_style
through theDartFormatter
that the server uses no longer enables available experiments automatically, so format requests in the IDE crash when trying out language experiments.The analysis server should pass the experiments specified in the
analysis_options.yaml
file to the formatter.The text was updated successfully, but these errors were encountered: