-
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
Plumb page width from analysis_options.yaml to formatter when formatting in analysis_server #56864
Comments
@bwilkerson @munificent both the LSP and legacy server have ways to configure page width already - which should take priority when both are provided? My feeling is that I presume the rules for overriding Also (since we'll need to validate the options):
formatter:
page_width:
TODO
|
I agree. If a package specifies a default then I think most users would want that default to be honored more than they'd want their person preference to be used.
The only reason it's a request parameter is because we didn't provide any kind of configuration support. I don't have any concerns about treating the user preference the same across the IDEs, and I think it might be confusing if they were treated differently.
I agree that the API is weird. We should consider adding an API to the
No.
No, and neither are negative values, or any non-integer values. I'm not sure what a minimum valid value is (I assume that We should treat an incomplete or invalid option as if it wasn't specified at all. In other words, they shouldn't change the default page width. |
Thanks - I'll do this. I think your other answers align with the assumptions I made the first CL at https://dart-review.googlesource.com/c/sdk/+/388822, though I am just accepting >= 1 because @munificent didn't mention a minimum - but I can update the validation if there is (if there is, perhaps it should be exposed by the formatter as a constant to avoid us duplicating it). |
…_width in LSP This adds support for validation + completion for `formatter/page_width` in analysis_options, and uses this value in preference to the client-supplied value in the LSP server. It does not yet add support for the legacy protocol, and there are a few questions in #56864 (comment). See #56864 Change-Id: I7844e3abd1191beb9cc24197bbc8aa7c9e9ad4fa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388822 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
…in legacy protocol This adds the same support previously added to LSP to the legacy protocol. As with LSP, the value in analysis_options overrides the explicit argument (since the expectation is that the user has not specifically chosen this value for this file, but rather as a default for the project/globally). See #56864 [analyzer] Add support for "formatter" in analysis_options + use page_width in LSP This adds support for validation + completion for `formatter/page_width` in analysis_options, and uses this value in preference to the client-supplied value in the LSP server. It does not yet add support for the legacy protocol, and there are a few questions in #56864 (comment). See #56864 Change-Id: Ic2be00087f78eb62c409dbc8f558d2f24b521f78 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388920 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
I agree. It's not good to be in a situation where your local preferences override a committed configuration because then any changes you make are likely to break CI or cause large diffs when you upload a PR.
I don't know what this means, but that's OK. :)
Yes. I borrowed the implementation and semantics from server. A nearer
Right.
These tests are more like integration tests and validate that the page width makes its way from the
In the formatter's code for extracting a page_width from
It's definitely not going to do anything useful, but the formatter will let you try. :) Thank you for the quick turnaround! |
I treated 0 as invalid, so if the user types this they will get a diagnostic (same as if they type a negative value), and we will ignore it (that is, we'll pass nothing to the formatter, or the globally configured value from the IDE). I think this is fine, but if |
I honestly don't think it matters much one way or the other. For what it's worth, |
My understanding is that analysis_server uses the formatter directly as a library so that it can format code as it exists in the IDE and not on disk.
I recently added support to the
dart format
CLI (but not the dart_style library API) to look for a surroundinganalysis_options.yaml
file and configure the page width from there if present. The schema looks like:To be consistent, analysis_server should also plumb that same page width in when it formats a file in memory. The library API already supports a
pageWidth
optional parameter, so this can be implemented whenever.Let me know if you have any questions and I can fill you in on all the details. If you want a reference, the
dart format
implementation is here with these tests. (I harvested this code from analyzer initially, but ended up rewriting a lot because the YamlNode API is... weird.)Thank you!
cc @DanTup
The text was updated successfully, but these errors were encountered: