Pārlūkot izejas kodu

nixpkgs/neovim: rename with mini.files instead

Thomas Dy 1 mēnesi atpakaļ
vecāks
revīzija
045750d07f
2 mainītis faili ar 31 papildinājumiem un 37 dzēšanām
  1. 31 0
      .config/nixpkgs/neovim/autocmd.lua
  2. 0 37
      .config/nixpkgs/neovim/lsp.lua

+ 31 - 0
.config/nixpkgs/neovim/autocmd.lua

@@ -32,6 +32,37 @@ vim.api.nvim_create_autocmd('BufLeave', {
   command = 'stopinsert',
 })
 
+-- rename
+vim.api.nvim_create_autocmd('User', {
+  pattern = 'MiniFilesActionRename',
+  callback = function(opts)
+    local params = {
+      files = {{
+        oldUri = vim.uri_from_fname(opts.data.from),
+        newUri = vim.uri_from_fname(opts.data.to),
+      }}
+    }
+    local bufnr = vim.fn.bufadd(opts.data.to)
+
+    local clients = vim.lsp.get_clients({ bufnr = bufnr })
+    for _, client in ipairs(clients) do
+      if client:supports_method('workspace/willRenameFiles') then
+        local resp = client:request_sync('workspace/willRenameFiles', params, 5000, bufnr)
+        if resp and resp.result ~= nil then
+          vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding)
+        end
+      end
+    end
+
+    for _, client in ipairs(clients) do
+      if client:supports_method('workspace/didRenameFiles') then
+        client:notify('workspace/didRenameFiles', params)
+      end
+    end
+  end,
+  nested = true,
+})
+
 -- formatting
 vim.api.nvim_create_autocmd('BufWritePre', {
   callback = function(opts)

+ 0 - 37
.config/nixpkgs/neovim/lsp.lua

@@ -29,8 +29,6 @@ else
     }
   end
 
-  local base_on_attach = vim.lsp.config["ts_ls"].on_attach
-
   vim.lsp.config("ts_ls", {
     init_options = {
       completionDisableFilterText = true,
@@ -61,41 +59,6 @@ else
         settings = make_settings(),
       })
     end,
-    on_attach = function(client)
-      base_on_attach(client)
-      -- add custom commands, we follow upstream's Lsp* prefix convention
-
-      -- rename file with import renaming, this does no error checking
-      vim.api.nvim_buf_create_user_command(0, "LspRenameFile", function()
-        local source = vim.api.nvim_buf_get_name(0)
-
-        local function do_rename(target)
-          if target == nil then
-            return
-          end
-
-          -- rename the buffer
-          vim.lsp.util.rename(source, target)
-
-          -- ask LSP to rename imports
-          client:exec_cmd({
-            command = "_typescript.applyRenameFile",
-            arguments = {
-              {
-                sourceUri = vim.uri_from_fname(source),
-                targetUri = vim.uri_from_fname(target),
-              }
-            }
-          })
-        end
-
-        vim.ui.input({
-          prompt = "New Filename: ",
-          completion = "file",
-          default = source,
-        }, do_rename)
-      end, {})
-    end,
   })
   vim.lsp.enable("ts_ls")
 end