comparison .chezmoitemplates/init.lua @ 602:31157c048f16

Load renamed locations into quickfix list
author Zeger Van de Vannet <zegervdv@me.com>
date Wed, 13 Jul 2022 08:40:34 +0200
parents 837e6ed64a90
children aeb516cf7688
comparison
equal deleted inserted replaced
601:837e6ed64a90 602:31157c048f16
410 } 410 }
411 end, 411 end,
412 } 412 }
413 use { 413 use {
414 'smjonas/inc-rename.nvim', 414 'smjonas/inc-rename.nvim',
415 config = function() require('inc_rename').setup() end, 415 config = function()
416 require('inc_rename').setup {
417 post_hook = function(result)
418 local changed = {}
419 for uri, changes in pairs(result.changes or result.documentChanges) do
420 local bufnr = vim.uri_to_bufnr(uri)
421 for _, edits in ipairs(changes) do
422 table.insert(changed, {
423 bufnr = bufnr,
424 lnum = edits.range.start.line + 1,
425 col = edits.range.start.character + 1,
426 text = vim.api.nvim_buf_get_lines(bufnr, edits.range.start.line, edits.range.start.line + 1, false)[1],
427 })
428 end
429 end
430 vim.fn.setqflist(changed, 'r')
431 end,
432 }
433 end,
416 } 434 }
417 435
418 use { 'vimjas/vim-python-pep8-indent', ft = { 'python' } } 436 use { 'vimjas/vim-python-pep8-indent', ft = { 'python' } }
419 437
420 use { 438 use {
918 }, 936 },
919 } 937 }
920 938
921 lsp.sumneko_lua.setup(luadev) 939 lsp.sumneko_lua.setup(luadev)
922 940
923 -- Populate quickfix with all locations of rename
924 function LspRename()
925 local params = vim.lsp.util.make_position_params()
926 params.newName = vim.fn.input('Rename: ', vim.fn.expand '<cword>')
927 vim.lsp.buf_request(0, 'textDocument/rename', params, function(err, result, ctx, ...)
928 vim.lsp.handlers['textDocument/rename'](err, result, ctx, ...)
929 local changed = {}
930 for uri, changes in pairs(result.changes) do
931 local bufnr = vim.uri_to_bufnr(uri)
932 for _, edits in ipairs(changes) do
933 table.insert(changed, {
934 bufnr = bufnr,
935 lnum = edits.range.start.line + 1,
936 col = edits.range.start.character + 1,
937 text = vim.api.nvim_buf_get_lines(bufnr, edits.range.start.line, edits.range.start.line + 1, false)[1],
938 })
939 end
940 end
941 vim.fn.setqflist(changed, 'r')
942 end)
943 end
944
945 vim.api.nvim_create_user_command('LspRename', LspRename, {})
946
947 local fd_quickfix = function(args) 941 local fd_quickfix = function(args)
948 local grepprg = vim.opt.grepprg 942 local grepprg = vim.opt.grepprg
949 local grepformat = vim.opt.grepformat 943 local grepformat = vim.opt.grepformat
950 944
951 vim.opt.grepprg = 'fd' 945 vim.opt.grepprg = 'fd'