You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The implement this reasonably (and without causing a potentially-large number of sequential requests to the server) we need to either have the server support multiple files, or do more work on the server (eg. via LSP).
I don't think putting refactors on the lightbulb is a good idea, as they show up so frequently that there will just be bulbs everywhere always. I suggest these go on the context menu:
@ericdallo currently LSP doesn't have the events required for this - there's an issue at microsoft/language-server-protocol#984 to try and spec it. I think it should be relatively straight forward (just copying VS Code's API, and the waitFor can just be handled by waiting for the response from the server), though I haven't thought about it too much just yet.
It makes sense @DanTup, meanwhile do you think it worths implement this as a custom method on dart-sdk analysis like the other methods like closingLabels and outline?
I really miss that feature on lsp-dart 😔
I'd prefer to avoid a custom method if we can get it in the spec fairly quickly, as a custom method would likely have to hang around for a long time (as editors may start depending on it).
I'll take a look at making a proposal for LSP to get feedback - I think it should be a fairly simple request.
Is it possible to move a file (and fix imports) programmatically from shell/bash CLI?
UseCase: You have some auto-generated file *.g.dart that gets saved somewhere you don't like, you want to move this auto-generated file to another path within your /lib directory. However within this file, some imports are relative. Moving the file from VS Code UI auto-fixes the imports (option called updateImportsOnRename from settings.json, official docs here).
@om-ha unfortunately not. For the renames to work, the analysis server needs to be told about them before they happen. You could perhaps automate it within a VS Code extension that does the move (which would trigger the APIs that talk to the language server), but that's not very ad-hoc.
@cedvdb I haven't seen any reports of this. Can you reliably reproduce it? It's possible that if the refactor takes too long VS Code times it out and just proceeds with the rename without waiting for the edits, but I'm not certain.
A log file could be useful (captured with Dart: Capture Analysis Server Logs) though note it'll include parts of your source code (so don't share them from any sensitive projects). Please file a new issue with the logs or more info. Thanks!
A lot of the work is done (for single-folder renames), but I'm waiting for a VS Code LSP client release (which I expect in the next month or two) which has support for proper cancellations. Without that, if you rename a large folder and it takes a long time to compute the edits for updating imports, you are unable to cancel it and that's not a very good experience.
Activity
DanTup commentedon Feb 12, 2018
I don't think putting refactors on the lightbulb is a good idea, as they show up so frequently that there will just be bulbs everywhere always. I suggest these go on the context menu:
microsoft/vscode#9827
DanTup commentedon Feb 21, 2018
Maybe this should be hooked into rename and move in the explorer?
microsoft/vscode#43768
DanTup commentedon Oct 30, 2018
I've started work on adding this to the server, but it's not complete yet. See dart-lang/sdk#33605.
49 remaining items
bsutton commentedon May 25, 2020
This workspace actually only has one folder.
In the explorer tab I see:
(workspace)
This settings file has the import option.
If I open the above noted folder directly the import management works.
bsutton commentedon May 25, 2020
Sorry,
ignore my last comment I scanned over your comment a little too quickly.
I've now added the setting it the .code.workspace file and the import management works :)
MarsGoatz commentedon Jul 12, 2020
Fantastic! Thank you for this extension!
ericdallo commentedon Aug 7, 2020
@DanTup any idea to give LSP this support?
If dart-sdk could provide that via LSP we could use on other editors like lsp-dart
DanTup commentedon Aug 7, 2020
@ericdallo currently LSP doesn't have the events required for this - there's an issue at microsoft/language-server-protocol#984 to try and spec it. I think it should be relatively straight forward (just copying VS Code's API, and the
waitForcan just be handled by waiting for the response from the server), though I haven't thought about it too much just yet.ericdallo commentedon Aug 7, 2020
It makes sense @DanTup, meanwhile do you think it worths implement this as a custom method on dart-sdk analysis like the other methods like closingLabels and outline?
I really miss that feature on
lsp-dart😔DanTup commentedon Aug 12, 2020
I'd prefer to avoid a custom method if we can get it in the spec fairly quickly, as a custom method would likely have to hang around for a long time (as editors may start depending on it).
I'll take a look at making a proposal for LSP to get feedback - I think it should be a fairly simple request.
ericdallo commentedon Aug 12, 2020
I see, thank you @DanTup for the help on that :)
om-ha commentedon Oct 2, 2021
Is it possible to move a file (and fix imports) programmatically from shell/bash CLI?
UseCase: You have some auto-generated file
*.g.dartthat gets saved somewhere you don't like, you want to move this auto-generated file to another path within your/libdirectory. However within this file, some imports are relative. Moving the file from VS Code UI auto-fixes the imports (option calledupdateImportsOnRenamefromsettings.json, official docs here).Is there a way to do this programmatically?
DanTup commentedon Oct 6, 2021
@om-ha unfortunately not. For the renames to work, the analysis server needs to be told about them before they happen. You could perhaps automate it within a VS Code extension that does the move (which would trigger the APIs that talk to the language server), but that's not very ad-hoc.
bsutton commentedon Oct 6, 2021
@om-ha
This may help:
https://pub.dev/packages/drtimport
It's only 'lightly' maintained.
cedvdb commentedon Dec 1, 2021
This seems to be buggy lately, in multiple projects. Has anyone have had imports not updated ?
=> Dart SDK version: 2.16.0-10.0.dev
DanTup commentedon Dec 1, 2021
@cedvdb I haven't seen any reports of this. Can you reliably reproduce it? It's possible that if the refactor takes too long VS Code times it out and just proceeds with the rename without waiting for the edits, but I'm not certain.
A log file could be useful (captured with Dart: Capture Analysis Server Logs) though note it'll include parts of your source code (so don't share them from any sensitive projects). Please file a new issue with the logs or more info. Thanks!
tanphat110699 commentedon Apr 6, 2022
@DanTup Sir, can this feature support delete/rename folder? This will be awesome! Thank you so much.
DanTup commentedon Apr 6, 2022
@tanphat110699 there's an open issue about that here:
#2483
A lot of the work is done (for single-folder renames), but I'm waiting for a VS Code LSP client release (which I expect in the next month or two) which has support for proper cancellations. Without that, if you rename a large folder and it takes a long time to compute the edits for updating imports, you are unable to cancel it and that's not a very good experience.