Mercurial > dotfiles
comparison dot_config/nvim/init.lua @ 449:10fc275a8914
Add LspRename command to populate the quickfix list with changed lines
author | Zeger Van de Vannet <zegervdv@me.com> |
---|---|
date | Thu, 09 Sep 2021 18:01:35 +0200 |
parents | d847c4df584b |
children | f46d7731ae5e |
comparison
equal
deleted
inserted
replaced
448:d847c4df584b | 449:10fc275a8914 |
---|---|
686 }, | 686 }, |
687 } | 687 } |
688 | 688 |
689 lsp.sumneko_lua.setup(luadev) | 689 lsp.sumneko_lua.setup(luadev) |
690 | 690 |
691 -- Populate quickfix with all locations of rename | |
692 function LspRename() | |
693 local params = vim.lsp.util.make_position_params() | |
694 params.newName = vim.fn.input("Rename: ", vim.fn.expand('<cword>')) | |
695 vim.lsp.buf_request(0, 'textDocument/rename', params, function(err, result, ctx, ...) | |
696 vim.lsp.handlers['textDocument/rename'](err, result, ctx, ...) | |
697 local changed = {} | |
698 for uri, changes in pairs(result.changes) do | |
699 local bufnr = vim.uri_to_bufnr(uri) | |
700 for _, edits in ipairs(changes) do | |
701 table.insert(changed, { | |
702 bufnr = bufnr, | |
703 lnum = edits.range.start.line + 1, | |
704 col = edits.range.start.character + 1, | |
705 text = vim.api.nvim_buf_get_lines(bufnr, edits.range.start.line, edits.range.start.line + 1, false)[1], | |
706 }) | |
707 end | |
708 end | |
709 vim.fn.setqflist(changed, 'r') | |
710 end) | |
711 end | |
712 | |
713 vim.cmd [[command! LspRename lua LspRename()]] | |
714 | |
691 -- Try importing local config | 715 -- Try importing local config |
692 local ok, localconfig = pcall(require, 'localconfig') | 716 local ok, localconfig = pcall(require, 'localconfig') |
693 if ok then | 717 if ok then |
694 localconfig.setup { on_attach = on_attach, capabilities = capabilities } | 718 localconfig.setup { on_attach = on_attach, capabilities = capabilities } |
695 end | 719 end |