Skip to content

Commit

Permalink
chore: Upgrade from deprecated buf_request to buf_request_all for LSP (
Browse files Browse the repository at this point in the history
  • Loading branch information
johmsalas authored Dec 15, 2023
1 parent f270679 commit 6210060
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lua/textcase/plugin/conversion.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
local utils = require("textcase.shared.utils")
local lsp = vim.lsp

-- local flag_buf_request_all = vim.fn.has("nvim-0.10") == 1
local flag_buf_request_all = false

local M = {}

function M.replace_matches(match, source, dest, try_lsp, buf)
Expand Down Expand Up @@ -95,11 +92,21 @@ function M.do_lsp_rename(method)
local params = lsp.util.make_position_params()
params.newName = method(current_word)

if flag_buf_request_all then
-- lsp.buf_request_all(0, "textDocument/rename", params)
else
lsp.buf_request(0, "textDocument/rename", params)
end
lsp.buf_request_all(0, "textDocument/rename", params, function(results)
local total_files = 0
for client_id, response in pairs(results) do
if not response.error then
local client = vim.lsp.get_client_by_id(client_id)
vim.lsp.util.apply_workspace_edit(response.result, client.offset_encoding)

-- after the edits are applied, the files are not saved automatically.
-- let's remind ourselves to save those...
-- TODO: This will be modified to include only one of the clients count
total_files = vim.tbl_count(response.result.changes)
end
end
print(string.format("Changed %s file%s. To save them run ':wa'", total_files, total_files > 1 and "s" or ""))
end)
end
end

Expand Down

0 comments on commit 6210060

Please sign in to comment.