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
Implement refactor: Move file #548
Comments
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: |
Maybe this should be hooked into rename and move in the explorer? |
I've started work on adding this to the server, but it's not complete yet. See dart-lang/sdk#33605. |
No news about it? Renaming file in dart project is a bit annoying since it breaks all the imports. |
Sorry, the work on this somewhat stalled due to other priorities and not many people asking for this. I think the work in the server supports renaming files, just not folders. It might be possible to wire just that bit up - I'll try and take a look soon. |
Just wanted to add my voice to this. Managing imports in dart/vscode is a pain. Moving or renaming a file takes significant effort to re-do each of the affected imports. |
The work is mostly done here, but it requires a VS Code feature that is currently part of the provisional API. In order to ship this, we need it to be moved to the stable API. The relevant issue is microsoft/vscode#43768. I'll ping again to see if there's any update. |
@DanTup Maybe you're already aware, but the APIs you were talking about have been moved to stable and are available in the latest version of VS Code (1.41.1). |
Ok, going to ship this behind a flag for vNext ( It only works for single-files and no folders, but that's probably better than nothing. When the VS Code issue is fixed, I think we can support multiple files, though it may be slow for large numbers (due to lots of round trips to the server). Supporting multiple files quickly and/or folders will probably be best done in the server along with LSP once it gets the API. I've opened some extra issues to track the other work:
|
Will this also work for imports which are using the absolute package: format? Ex: package:my_app/foo/bar.dart |
It should do - though I did find some issues (described in dart-lang/sdk#41889) that will need to be fixed - I think they're edge cases though. I'll make a test build later and post the link here if anyone wants to try it out before the release and provide feedback(/find more bugs 😬). |
There's a beta build here if you'd like to try it out: https://github.com/Dart-Code/Dart-Code/releases/tag/v3.11.0-beta.3 Download the .vsix file, then run Extensions: Install from VSIX from the VS Code command palette and select the file. Then set If you have VS Code set to auto-update extensions, when this version is released stable, you'll automatically be updated, so you don't need to worry about uninstalling (unless something is broken - but please file issues if it is!). |
Wow. OK! |
You the man. I generate my Now I can move the whole folder at once except for the This is great! Thank you SO much. |
@nhwilly great, glad to hear it'll help! I'll try to push on the remaining VS Code and analysis server issues when I can to handle the remaining cases. Thanks for nudging me to fix it up (there's no motivation like someone mentioning another editor 😄). |
I've manged to install the vsix. I have two project. I'm using the same settings file in both projects ( I copied it from the workspaces that doesn't work).
|
@bsutton in a multi-root workspace, it wouldn't be read from each folders own It should, however, be ready from the Thanks! |
This workspace actually only has one folder. In the explorer tab I see:
This settings file has the import option. If I open the above noted folder directly the import management works. |
Sorry, I've now added the setting it the .code.workspace file and the import management works :) |
Fantastic! Thank you for this extension! |
@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 |
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'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. |
I see, thank you @DanTup for the help on that :) |
Is it possible to move a file (and fix imports) programmatically from shell/bash CLI? UseCase: You have some auto-generated file Is there a way to do this programmatically? |
@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. |
@om-ha It's only 'lightly' maintained. |
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 |
@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! |
@DanTup Sir, can this feature support delete/rename folder? This will be awesome! Thank you so much. |
@tanphat110699 there's an open issue about that here: 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. |
Blocked on microsoft/vscode#43768 being finalised.
Update: The VS Code API works, however despite supporting multiple
files
, it is only ever fired once-per-file https://github.com/microsoft/vscode/blob/926fc23f139e4d1250dba494c6e825e4816e62f6/src/vs/workbench/api/common/extHostFileSystemEventService.ts#L148 concurrently. This results in multipleMOVE_FILE
calls to the analysis server, which currently only supports one refactor at a time (a new refactor cancels the previous).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).
The text was updated successfully, but these errors were encountered: