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
format documents when hover like in android studio #3357
Comments
@bwilkerson this string comes from LSP could do similar (in handler_hover.dart) though I wonder if it may be better if ElementDisplayStringBuilder handled this and was passed some flag to tell it to prefer formatting over multiple lines (which initially would just be passed through from the LSP handler) - any thoughts? |
I wouldn't mind having the logic in If we're going to do this, it would be nice to improve on the display in IntelliJ. It doesn't always produce nice results, as evidenced by this screenshot: I'd propose that if the line is too long and needs to be split up that we break before the every parameter (including the first) and that we indent a fixed number of spaces, more like what the formatter produces. (Bonus points if we can find a way to use the formatter so that it stays consistent over time.) |
Makes sense to me. Some questions:
|
Yes, the underlying source is available. I don't know whether we want to use it though because there could be additional text in it that we don't want to include in the output (comments, annotations on parameters, and default values come to mind). As for using the formatter, I'm not actually certain that that's what we want to do. It was just a brainstorming idea. If we're composing the text to be formatted then it might be better to just control the format directly. We can't, for example, include the "(new) " or "(const) " prefix text when passing it to the formatter, so that might throw off the results. Using the formatter is probably more work than it's worth.
I don't know. I'd have to look at where |
Yeah, good point.
I'm not sure about diagnostics, but it is called in quite a few places - some of which I'm not certain where they'd be used (for example it's included in some of the protocol messages back to the client). I think it might be better to keep opt-in and just enable in specific places we know can handle it (and if over time this becomes all of them, the option could always be removed). |
SGTM |
I've got a change at https://dart-review.googlesource.com/c/sdk/+/202962/, here are some examples of how it looks (including the bad IntelliJ example from above): Right now it's enabled only for Hovers in LSP, and only for the main executable elements (function types within are kept on a single line.. I did initially wrap them and further indent, but it didn't seem like an improvement having multiple indent levels). |
It looks good and easier to read. Thank you :D |
@alexander-doroshko @jwren Any interest in having this text formatted on server for IntelliJ? |
Sure. I'm not aware of any reasons not to be interested in this :). I'm ready to add a switch to the Dart plugin to tweak behavior based on the SDK version. |
@alexander-doroshko is there anywhere other than hovers that you also do this formatting? If so, it may be worth enabling them in those places at the same time (so far for LSP I only enabled it for hovers). |
I don't remember other places. Probably only hovers. |
Fixes Dart-Code/Dart-Code#3357. Change-Id: I999ca8d3ffb7311ea4f60586e75160ae87292a77 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202962 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
@alexander-doroshko I have a change to enable this for non-LSP here: https://dart-review.googlesource.com/c/sdk/+/202971/ I've also increased the protocol version (to |
Thanks! I'll check and answer later today. |
Go ahead and land it! I'll publish the plugin updates shortly. There won't be dramatic problems until people update the plugin. |
…cription() starting from SDK 2.14 Dart-Code/Dart-Code#3357 GitOrigin-RevId: 878d64731513d0677aa8d69dc29bb023475fc8de
…cription() starting from SDK 2.14 Dart-Code/Dart-Code#3357 (cherry picked from commit 878d64731513d0677aa8d69dc29bb023475fc8de) IJ-CR-10012 GitOrigin-RevId: 744917b9b8ad262c800886958df7cd5281333cd5
I would expect so. It would likely be included in some 2.14 pre-release builds (those made after it lands), but not in others (those that have already shipped). I don't know if that's important to you though. Using the protocol version would be most reliable, but I don't know if that's as simple for you. I'll let you know/close this issue once it's merged. |
This has landed in the SDK in dart-lang/sdk@d75becf :-) It'll show up automatically in VS Code when using an SDK that includes that change (it doesn't need any changes here in the Dart extension). |
…cription() starting from SDK 2.14 Dart-Code/Dart-Code#3357 (cherry picked from commit 878d64731513d0677aa8d69dc29bb023475fc8de) IJ-CR-10012 GitOrigin-RevId: 61c8962331240a964e317899b4e192dcbf39552d
…cription() starting from SDK 2.14 Dart-Code/Dart-Code#3357 (cherry picked from commit 878d64731513d0677aa8d69dc29bb023475fc8de) IJ-CR-10012 GitOrigin-RevId: fd64c39676d31ef851f3d5477ff0749274a4fcd9
in android studio

in vscode

The text was updated successfully, but these errors were encountered: