Skip to content

Implement refactor: Move file #548

Closed

Description

@DanTup

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 multiple MOVE_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).

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    in editorRelates to code editing or language features
    on Feb 8, 2018
  2. added this to the On Deck milestone on Feb 8, 2018
  3. DanTup commented on Feb 12, 2018

    @DanTup
    MemberAuthor

    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

  4. DanTup commented on Feb 21, 2018

    @DanTup
    MemberAuthor

    Maybe this should be hooked into rename and move in the explorer?

    microsoft/vscode#43768

  5. modified the milestones: On Deck, Backlog on Feb 21, 2018
  6. modified the milestones: Backlog, On Deck on Oct 30, 2018
  7. DanTup commented on Oct 30, 2018

    @DanTup
    MemberAuthor

    I've started work on adding this to the server, but it's not complete yet. See dart-lang/sdk#33605.

  8. 49 remaining items

  9. bsutton commented on May 25, 2020

    @bsutton

    This workspace actually only has one folder.

    In the explorer tab I see:
    (workspace)

    • .vscode
      • settings.json.

    This settings file has the import option.

    If I open the above noted folder directly the import management works.

  10. bsutton commented on May 25, 2020

    @bsutton

    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 :)

  11. MarsGoatz commented on Jul 12, 2020

    @MarsGoatz

    Fantastic! Thank you for this extension!

  12. ericdallo commented on Aug 7, 2020

    @ericdallo

    @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

  13. DanTup commented on Aug 7, 2020

    @DanTup
    MemberAuthor

    @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.

  14. ericdallo commented on Aug 7, 2020

    @ericdallo

    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 😔

  15. DanTup commented on Aug 12, 2020

    @DanTup
    MemberAuthor

    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.

  16. ericdallo commented on Aug 12, 2020

    @ericdallo

    I see, thank you @DanTup for the help on that :)

  17. om-ha commented on Oct 2, 2021

    @om-ha

    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).

    Is there a way to do this programmatically?

  18. DanTup commented on Oct 6, 2021

    @DanTup
    MemberAuthor

    @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.

  19. bsutton commented on Oct 6, 2021

    @bsutton

    @om-ha
    This may help:
    https://pub.dev/packages/drtimport

    It's only 'lightly' maintained.

  20. cedvdb commented on Dec 1, 2021

    @cedvdb

    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

  21. DanTup commented on Dec 1, 2021

    @DanTup
    MemberAuthor

    @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!

  22. tanphat110699 commented on Apr 6, 2022

    @tanphat110699

    @DanTup Sir, can this feature support delete/rename folder? This will be awesome! Thank you so much.

  23. DanTup commented on Apr 6, 2022

    @DanTup
    MemberAuthor

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions