Skip to content

Latest commit

 

History

History
63 lines (51 loc) · 1.81 KB

README.md

File metadata and controls

63 lines (51 loc) · 1.81 KB

dart-lsp-refactorings.nvim

Dart language server has setting to renameFilesWithClasses and to update imports updateImportsOnRename after files was renamed. But now imports are not updated. LSP server support workspace/willRenameFiles client request to get import changes. But Neovim LSP does not have support for this request. This plugin modifies lsp.buf.rename function to call workspace/willRenameFiles request before file rename and apply these changes after rename is done.

Installation

Using packer.nvim

use {'sidlatau/dart-lsp-refactorings.nvim' }

Usage

require("dart-lsp-refactorings").rename()

Call this function when you want rename class or anything else. If file will be renamed too, this function will update imports.


require("dart-lsp-refactorings").on_rename_file({
  source = "/source_file_path.dart",
  destination = "/destination_file_path.dart",
  callback = function()
    -- function to be called to finish file rename
  end
})

Hook function that get import changes and applies these changes before file rename. Example of using with neo-tree

neo_tree.setup {
  ...
  event_handlers = {
    {
      event = "before_file_rename",
      handler = function(args)
        local ok, refact = pcall(require, "dart-lsp-refactorings")
        if ok then
          refact.on_rename_file(args)
          return { handled = true }
        end
      end,
    },
    {
      event = "before_file_move",
      handler = function(args)
        local ok, refact = pcall(require, "dart-lsp-refactorings")
        if ok then
          refact.on_rename_file(args)
          return { handled = true }
        end
      end,
    },
  },
}