-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: LSP renaming did not work in some cases
There were some edge cases that caused issues when renaming files with LSP servers. Hopefully fix all of them by using the implementation that's also shared by neotree and nvim-tree: https://github.com/antosha417/nvim-lsp-file-operations Thanks @chaozwn for suggesting the fix! Closes <#80>
- Loading branch information
1 parent
b892534
commit 85a8e60
Showing
8 changed files
with
36 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,14 @@ | ||
local M = {} | ||
|
||
---@param path string | ||
local function notify_file_was_deleted(path) | ||
-- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willDeleteFiles | ||
local method = 'workspace/willDeleteFiles' | ||
|
||
local clients = vim.lsp.get_clients({ | ||
method = method, | ||
bufnr = vim.api.nvim_get_current_buf(), | ||
}) | ||
|
||
for _, client in ipairs(clients) do | ||
local resp = client.request_sync(method, { | ||
files = { | ||
{ | ||
uri = vim.uri_from_fname(path), | ||
}, | ||
}, | ||
}, 1000, 0) | ||
|
||
if resp and resp.result ~= nil then | ||
vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding) | ||
end | ||
end | ||
end | ||
|
||
---@param path string | ||
local function notify_delete_complete(path) | ||
-- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didDeleteFiles | ||
local method = 'workspace/didDeleteFiles' | ||
local will_delete = require('lsp-file-operations.will-delete') | ||
local did_delete = require('lsp-file-operations.did-delete') | ||
|
||
local clients = vim.lsp.get_clients({ | ||
method = method, | ||
bufnr = vim.api.nvim_get_current_buf(), | ||
}) | ||
|
||
for _, client in ipairs(clients) do | ||
-- NOTE: this returns nothing, so no need to do anything with the response | ||
client.request_sync(method, { | ||
files = { | ||
{ | ||
uri = vim.uri_from_fname(path), | ||
}, | ||
}, | ||
}, 1000, 0) | ||
end | ||
end | ||
local M = {} | ||
|
||
-- Send a notification to LSP servers, letting them know that yazi just deleted some files | ||
-- Send a notification to LSP servers, letting them know that yazi just deleted | ||
-- some files. Execute any changes that the LSP says are needed in other files. | ||
---@param path string | ||
function M.file_deleted(path) | ||
notify_file_was_deleted(path) | ||
notify_delete_complete(path) | ||
will_delete.callback({ fname = path }) | ||
did_delete.callback({ fname = path }) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,15 @@ | ||
local M = {} | ||
|
||
---@param from string | ||
---@param to string | ||
local function notify_file_was_renamed(from, to) | ||
-- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_willRenameFiles | ||
local method = 'workspace/willRenameFiles' | ||
|
||
local clients = vim.lsp.get_clients({ | ||
method = method, | ||
bufnr = vim.api.nvim_get_current_buf(), | ||
}) | ||
|
||
for _, client in ipairs(clients) do | ||
local resp = client.request_sync(method, { | ||
files = { | ||
{ | ||
oldUri = vim.uri_from_fname(from), | ||
newUri = vim.uri_from_fname(to), | ||
}, | ||
}, | ||
}, 1000, 0) | ||
|
||
if resp and resp.result ~= nil then | ||
vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding) | ||
end | ||
end | ||
end | ||
|
||
---@param from string | ||
---@param to string | ||
local function notify_rename_complete(from, to) | ||
-- https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didRenameFiles | ||
local method = 'workspace/didRenameFiles' | ||
local will_rename = require('lsp-file-operations.will-rename') | ||
local did_rename = require('lsp-file-operations.did-rename') | ||
|
||
local clients = vim.lsp.get_clients({ | ||
method = method, | ||
bufnr = vim.api.nvim_get_current_buf(), | ||
}) | ||
|
||
for _, client in ipairs(clients) do | ||
-- NOTE: this returns nothing, so no need to do anything with the response | ||
client.request_sync(method, { | ||
files = { | ||
oldUri = vim.uri_from_fname(from), | ||
newUri = vim.uri_from_fname(to), | ||
}, | ||
}, 1000, 0) | ||
end | ||
end | ||
local M = {} | ||
|
||
-- Send a notification to LSP servers, letting them know that yazi just renamed some files | ||
-- Send a notification to LSP servers, letting them know that yazi just renamed | ||
-- some files. Execute any changes that the LSP says are needed in other files. | ||
---@param from string | ||
---@param to string | ||
function M.file_renamed(from, to) | ||
notify_file_was_renamed(from, to) | ||
notify_rename_complete(from, to) | ||
will_rename.callback({ old_name = from, new_name = to }) | ||
did_rename.callback({ old_name = from, new_name = to }) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters