lsp-dart
lsp-dart copied to clipboard
[Feature Request] Wrap the widget under the point into another widget(e.g. container)
Basically, we have the similar feature in left flutter outline window, as following screenshot.

but, i think it not conveniently because find the widget under the point in this outline window is not so easy anyway, so i consider, we can improve this two different way.
- Following current editing widget in flutter outline window, that is, when we are editing a Container, we can active that Container in flutter outline async, because we are a issue as we discussed on #127, if this is not possible for performance reason, we can try 2
- Add a right menu sub-item to enable wrap element on the point into the following default right click menu.

You can do this with eglot using eglot-code-actions
Via code actions this is possible as well using lsp-mode
It's not clear to me what is the feature requested @zw963, code actions already provide wrapping widget

Wired, It still not works for me ...



That's weird indeed, all those cases work for me, @DanTup is there anything on the server-side that may not return "wrap widget" code actions?
I'm not sure without a repro. I notice in the screenshots above there's a difference with return Foo() vs final app = Foo();.. does that change things?
If not, some exact code this repros on and a log of the LSP traffic might help figure it out.
You are correct @DanTup !
I don't get wrap widget code actions if trying on a widget that belongs to a variable: final foo = MaterialApp();
I suppose this is expected as the server has no easy way to know this is the return of the build method or a widget
I think it was just a bug. I don't see any reason to restrict them to where the widget is being returned. There was code and tests for the following:
Widget w;
w = Container();
I think it was just an oversight that variable declarations weren't also handled. I've opened a change at https://dart-review.googlesource.com/c/sdk/+/248125. Once landed, it will show up in a future Dart/Flutter SDK release.
I try record IO in the last wrappered example.
[Trace - 10:17:59 AM] Sending request 'textDocument/codeAction - (40)'.
Params: {
"textDocument": {
"uri": "file:///home/zw963/test_project/lib/app.dart"
},
"range": {
"start": {
"line": 199,
"character": 16
},
"end": {
"line": 199,
"character": 16
}
},
"context": {
"diagnostics": []
}
}
[Trace - 10:17:59 AM] Received response 'textDocument/codeAction - (40)' in 17ms.
Result: [
{
"title": "Sort Members",
"kind": "source.sortMembers",
"command": {
"title": "Sort Members",
"command": "edit.sortMembers",
"arguments": [
"/home/zw963/test_project/lib/app.dart"
]
}
},
{
"title": "Organize Imports",
"kind": "source.organizeImports",
"command": {
"title": "Organize Imports",
"command": "edit.organizeImports",
"arguments": [
"/home/zw963/test_project/lib/app.dart"
]
}
},
{
"title": "Fix All",
"kind": "source.fixAll",
"command": {
"title": "Fix All",
"command": "edit.fixAll",
"arguments": [
"/home/zw963/test_project/lib/app.dart"
]
}
},
{
"title": "Extract Method",
"kind": "refactor.extract",
"command": {
"title": "Extract Method",
"command": "refactor.perform",
"arguments": [
"EXTRACT_METHOD",
"/home/zw963/test_project/lib/app.dart",
0,
6228,
0,
null
]
}
},
{
"title": "Extract Local Variable",
"kind": "refactor.extract",
"command": {
"title": "Extract Local Variable",
"command": "refactor.perform",
"arguments": [
"EXTRACT_LOCAL_VARIABLE",
"/home/zw963/test_project/lib/app.dart",
0,
6228,
0,
null
]
}
},
{
"title": "Extract Widget",
"kind": "refactor.extract",
"command": {
"title": "Extract Widget",
"command": "refactor.perform",
"arguments": [
"EXTRACT_WIDGET",
"/home/zw963/test_project/lib/app.dart",
0,
6228,
0,
null
]
}
}
]
Yep, i can make it works when i try to directly show action on following returned widget instead.

Following is lsp output log
http://dpaste.com/E78YBYJTY
Another strange things is, when i select widget use region, then show action, it get different result.

Awesome @DanTup thank you! @zw963 we can keep this open until the fix on dart-sdk is merged