Skip to content

Commit

Permalink
fix(lsp): only notifying lsp of renames for open buffers
Browse files Browse the repository at this point in the history
This fixes an error in the following case:

- in a directory containing many files, have only one file open in
  neovim (with other files in the directory not open)
- open yazi
- rename the directory containing the files

At this point, the LSP server would receive a notification of the
rename only for the file that was open in neovim, and not for the
other files in the directory. This would cause the LSP server to
only apply changes related to the one open file.
  • Loading branch information
mikavilpas committed Apr 21, 2024
1 parent 8ebbeae commit 85bac6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lua/yazi/event_handling.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local utils = require('yazi.utils')
local plenaryIterators = require('plenary.iterators')
local lsp_delete = require('yazi.lsp.delete')
local lsp_rename = require('yazi.lsp.rename')

local M = {}

Expand Down Expand Up @@ -63,6 +64,8 @@ function M.process_events_emitted_from_yazi(events)
for i, event in ipairs(events) do
if event.type == 'rename' then
---@cast event YaziRenameEvent
lsp_rename.file_renamed(event.data.from, event.data.to)

local rename_instructions =
M.get_buffers_that_need_renaming_after_yazi_exited(event.data)
for _, instruction in ipairs(rename_instructions) do
Expand All @@ -71,6 +74,8 @@ function M.process_events_emitted_from_yazi(events)
elseif event.type == 'move' then
---@cast event YaziMoveEvent
for _, item in ipairs(event.data.items) do
lsp_rename.file_renamed(item.from, item.to)

local rename_instructions =
M.get_buffers_that_need_renaming_after_yazi_exited(item)
for _, instruction in ipairs(rename_instructions) do
Expand Down
3 changes: 0 additions & 3 deletions lua/yazi/utils.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local fn = vim.fn
local RenameableBuffer = require('yazi.renameable_buffer')
local lsp_rename = require('yazi.lsp.rename')

local M = {}

Expand Down Expand Up @@ -173,8 +172,6 @@ function M.rename_or_close_buffer(instruction)
else
vim.api.nvim_buf_set_name(instruction.bufnr, instruction.path.filename)
end

lsp_rename.file_renamed(instruction.original_path, instruction.path.filename)
end

---@param prev_win integer
Expand Down

0 comments on commit 85bac6b

Please sign in to comment.