-
Notifications
You must be signed in to change notification settings - Fork 318
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
Allow fold when function declaration is in multiple lines Dart #4269
Comments
I agree it's inconvenient not being able to fold an entire function declaration. Although there are some questions about the best way to do this. We can't start multiple folding regions on the same line (because editors will generally only show a single folding icon), so we need to decide what to do with the current parameter list region. Given the code:
There's currently a range for
@bwilkerson any opinions? My feeling is that we drop/replace the existing BODY range (that just covers the block) and push the parameters range to the first non-whitespace character of the following line (although the way I found to get at the indentation for that is |
No, I don't have any opinion here. I don't use code folding, so I have no experience to draw on, and I haven't really paid any attention to what our current support looks like. I do have to wonder, though, what use case prompted us to support folding for parameter lists and why we chose to fold function bodies rather than the whole function (maybe because we fold parameter lists and couldn't have overlapping regions?). If we know why we support what we support we might at least know if changing it will break an important use case. |
I did some digging earlier to see if I could find if there was a reason for going this route, and could not find anything. I think it's likely it was somewhat accidental - in dart-lang/sdk@4604300 I used FunctionBody to fold functions/methods/constructors and none of my tests had multi-line parameter lists (and parameter folding was added much later in dart-lang/sdk@d3082bc). I'm also not a heavy user of it so don't have too strong an opinion, but this issue did remind me that I had tried to fold methods before and it didn't feel quite right (but being just an extra click I probably didn't think too much about it). |
@airherna that issue has been fixed (via #4121) and will ship in an upcoming SDK release. There was a change in VS Code that changed how it handled ranges where one started on the same line that another started (which is the case for the parameter list and the function body in your example). If used to allow them, but now it drops one of them. So using the latest (bleeding edge) code your example above has a fold for the function body: The reason the parameter folding is gone now, is that we "shrunk" it to not overlap with the function body, and it was left as only a single line so it was removed. In the case where it was still multiple lines, it would still get a folding region: However, I still think it's a little clumsy to have to fold two regions and it's left looking like this: |
I have some changes that I think make this work as well as we can. We'll add "function body" folding ranges for the whole declaration instead of just from the The result is that whole functions can be folded, and if the parameters are more than two lines (which dartfmt seems to always then push the start onto the next line) then they'll be foldable within that: Nov-17-2022.15-34-02.mp4Since VS Code only supports line folding, you'll always see the entire line when folding (eg. |
That sounds good to me. Another data point would be to see how other language servers handle this case (assuming that any do). |
TypeScript (which I generally use as a template because it's maintained by the VS Code team) does fold the whole declaration, but doesn't allow folding of parameter lists: Nov-17-2022.16-34-20.mp4I think there may be some value in folding parameter lists (I suspect on average Flutter code has longer parameter lists and/or more likely has them split over a larger number of lines) but I'm not against removing them if they feel redundant. Review on the way shortly. |
…nly bodies) Fixes Dart-Code/Dart-Code#4269. Change-Id: I137a105d119c3387a2f319a34c420380e4b97e5d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/270401 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
With dart-lang/sdk@35d3015, whole function declarations (instead of just bodies) can be folded. There are also some other minor tweaks to ranges to improve handling of parameter lists when they start on the same line as the declaration (so they can still be folded). This change is in the Dart language server so the fixes will show up with a future SDK update (rather than a Dart VS Code extension update). |
Type: Bug
I'm filing this issue in the Dart extension because I have not been able to reproduce this exact behavior in languages like Python or C, even with the same parameter formatting. It's relevant because this type of formatting is provided by dartfmt and makes the fold feature useless.
Environment:
OS: Windows
Version: 1.73.1
Reproducibility rate: 100%
Steps to reproduce:
Future function(String param1,
String param2, String param3) async {
// content
// content
// content
}
Expected Result:
The function folds and all the content and parameters are hidden.
Actual Result:
Only the function parameters are folded and the content stays visible.
Extension version: 3.52.1
VS Code version: Code 1.73.1 (6261075646f055b99068d3688932416f2346dd3b, 2022-11-09T04:27:29.066Z)
OS version: Windows_NT x64 10.0.22000
Modes:
Sandboxed: No
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: