Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: textDocument/rename support #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ to change case of the current keyword, Coerce is simpler.
| Current keyword coerce | ✅ | ❌ | ✅ |
| Visual selection | ✅ | ✅ | ❌ |
| Motion selection | ✅ | ✅ | ❌ |
| LSP rename | | ✅ | ❌ |
| LSP rename | | ✅ | ❌ |
| Kebab case | ✅ | ✅ | ✅ |
| [Numeronym] “case” | ✅ | ❌ | ❌ |
| Custom case support | ✅ | ❌ | ❌ |
Expand Down
30 changes: 22 additions & 8 deletions lua/coerce/conversion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,28 @@ M.substitute = function(selected_region, apply)
local va = require("coerce.vim.api")
local selected_text_lines = va.nvim_buf_get_text(buffer, selected_region)
local transformed_text = apply(selected_text_lines[1])
vim.api.nvim_buf_set_text(
buffer,
selected_region.start_row,
selected_region.start_col,
selected_region.end_row - 1,
selected_region.end_col,
{ transformed_text }
)

local clients = vim.lsp.get_active_clients()
local any_client_supports_rename = false
for _, client in pairs(clients) do
if client.supports_method("textDocument/rename") then
any_client_supports_rename = true
break
end
end

if any_client_supports_rename then
vim.lsp.buf.rename(transformed_text)
else
vim.api.nvim_buf_set_text(
buffer,
selected_region.start_row,
selected_region.start_col,
selected_region.end_row - 1,
selected_region.end_col,
{ transformed_text }
)
end
end

--- Selects the current word.
Expand Down
Loading