Skip to content

[Feature request] Update imports for the file after file is renamed #623

@sidlatau

Description

@sidlatau

Problem:

I am using this plugin for file rename/move operations. I would want to integrate these operations with LSP. Some LSP servers support functionality to update imports after the file is renamed or moved. Client sends workspace/willRenameFiles notification to LSP, which returns import changes. dartls supports this notification. I want a hook to file rename flow to be able to call LSP and apply returned results.

Possible implementation:

It would be nice to be able to setup this hook in neo-tree, possible implementation:
https://github.com/nvim-neo-tree/neo-tree.nvim/compare/v2.x...sidlatau:neo-tree.nvim:update-imports?expand=1

Then user needs to setup this hook:

neo_tree.setup {
    ...
    hooks = {
      on_rename_file = function(data)
        ("dart-lsp-refactorings").on_rename_file(data)
      end,
    },
}

where data is:

{
  source= "/path_to_source",
  destination = "/path_to_destination",
  callback = function()
    -- Function called to finish rename process
  end
}

Alternatives tried:

I tried to use events infrastructure in neo-tree, added new WILL_FILE_RENAME event, but problem with them is that they does not block a flow. When request reaches LSP about renamed file, server returns empty results, I suspect file is already renamed and server does not see it. In above provided solution I can control when actual rename occurs.

I think several such hooks could be useful - for file rename, file move, maybe even for operations with folders.

Would it be feasible to add such hooks to neo-tree?
I may create PR then.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions