Browse Source

nixpkgs/neovim: add small delay before applying file rename

Thomas Dy 4 tháng trước cách đây
mục cha
commit
767014fc19
1 tập tin đã thay đổi với 20 bổ sung11 xóa
  1. 20 11
      .config/nixpkgs/neovim/config/lua/user/lsp.lua

+ 20 - 11
.config/nixpkgs/neovim/config/lua/user/lsp.lua

@@ -169,21 +169,30 @@ vim.api.nvim_create_autocmd('User', {
     }
     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)
+    -- delay a bit to allow LSP clients to attach
+    vim.defer_fn(function()
+      local clients = vim.lsp.get_clients({ bufnr = bufnr })
+      for _, client in ipairs(clients) do
+        vim.notify(client.name)
+        if client.name == 'dprint' then
+          goto continue
         end
+        if client:supports_method('workspace/willRenameFiles') then
+          vim.notify('lsp rename')
+          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
+        ::continue::
       end
-    end
 
-    for _, client in ipairs(clients) do
-      if client:supports_method('workspace/didRenameFiles') then
-        client:notify('workspace/didRenameFiles', params)
+      for _, client in ipairs(clients) do
+        if client:supports_method('workspace/didRenameFiles') then
+          client:notify('workspace/didRenameFiles', params)
+        end
       end
-    end
+    end, 100)
   end,
   nested = true,
 })