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: provide diff-rename by exposing LSP TextEdits conversion functions #281

Closed

Conversation

jedrzejboczar
Copy link

Python LSP (pylsp) resolves rename as a single TextEdit of the whole buffer. I found your diff feature of conform.nvim and wanted to adopt it for textDocument/rename. This only includes small changes to conform.nvim and exposes some functions that can be used to easily wrap the LSP rename handler, e.g.

local diff_rename = require('conform.lsp_format').wrap_rename_handler(vim.lsp.handlers["textDocument/rename"])
vim.lsp.handlers["textDocument/rename"] = diff_rename

-- In my config I actually have something like
vim.lsp.handlers["textDocument/rename"] = function(err, result, ctx, config)
    diff_rename(err, result, ctx, config)
    if result then 
        fill_quickfix_list_and_briefly_highlight_all_changes(result)
    end
end

Not sure if you want to include it in conform.nvim as it is not strictly about formatting, but if not then I'll just copy the code to my config an use it there. Still it seems like this is a small change to what conform.nvim already does. And maybe it could be useful for other LSP actions that apply text edits?

@github-actions github-actions bot requested a review from stevearc January 26, 2024 21:44
@jedrzejboczar
Copy link
Author

I fixed stylua, as for typecheck maybe you could include the types from /usr/share/nvim/runtime/lua/vim/lsp/_meta/protocol.lua when type-checking in CI?

Copy link
Owner

@stevearc stevearc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep conform narrowly focused on formatting. This seems to mostly be an effort to re-use the logic that diffs two blocks of text and produces LSP TextEdit objects. I would be receptive to two ideas around that:

  1. upstreaming the logic into Neovim itself, where it could be used to fix the behavior of all of these formatting/workspace operations
  2. light refactoring to make it easier to call that function as a library

@stevearc stevearc closed this Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants