add rename

neovim_0_5
ray-x 3 years ago
parent b56ca88390
commit 72ecc85842

@ -103,7 +103,7 @@ local setups = {
},
settings = {
gopls = {
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
flags = {allow_incremental_sync = true, debounce_text_changes = 500},
analyses = {unusedparams = true, unreachable = false},
codelenses = {
generate = true, -- show the `go generate` lens.
@ -125,7 +125,7 @@ local setups = {
end
},
clangd = {
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
flags = {allow_incremental_sync = true, debounce_text_changes = 500},
cmd = {
"clangd", "--background-index", "--suggest-missing-includes", "--clang-tidy",
"--header-insertion=iwyu"
@ -151,7 +151,7 @@ local setups = {
procMacro = {enable = true}
}
},
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
flags = {allow_incremental_sync = true, debounce_text_changes = 500}
},
sqls = {
filetypes = {"sql"},
@ -160,7 +160,7 @@ local setups = {
highlight.diagnositc_config_sign()
require"sqls".setup {picker = "telescope"} -- or default
end,
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
flags = {allow_incremental_sync = true, debounce_text_changes = 500},
settings = {
cmd = {"sqls", "-config", "$HOME/.config/sqls/config.yml"}
-- alterantively:
@ -176,7 +176,7 @@ local setups = {
cmd = {"lua-language-server"},
filetypes = {"lua"},
on_attach = on_attach,
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
flags = {allow_incremental_sync = true, debounce_text_changes = 500},
settings = {
Lua = {
runtime = {
@ -194,8 +194,8 @@ local setups = {
workspace = {
-- Make the server aware of Neovim runtime files
library = library,
maxPreload = 256,
preloadFileSize = 50000
maxPreload = 1000,
preloadFileSize = 10000
},
telemetry = {enable = false}
}
@ -204,7 +204,7 @@ local setups = {
pyright = {
cmd = {"pyright-langserver", "--stdio"},
filetypes = {"python"},
flags = { allow_incremental_sync = true, debounce_text_changes = 500},
flags = {allow_incremental_sync = true, debounce_text_changes = 500},
settings = {
python = {
analysis = {
@ -222,7 +222,7 @@ local setups = {
index = {threads = 2},
clang = {excludeArgs = {"-frounding-math"}}
},
flags = { allow_incremental_sync = true },
flags = {allow_incremental_sync = true}
}
}
@ -234,7 +234,10 @@ local servers = {
"terraformls"
}
local default_cfg = {on_attach = on_attach, flags = { allow_incremental_sync = true, debounce_text_changes = 500 },}
local default_cfg = {
on_attach = on_attach,
flags = {allow_incremental_sync = true, debounce_text_changes = 500}
}
-- check and load based on file type
local function load_cfg(ft, client, cfg, loaded)
@ -294,10 +297,8 @@ local function wait_lsp_startup(ft, retry, lsp_opts)
if lsp_opts[lspclient] ~= nil then
-- log(lsp_opts[lspclient], cfg)
cfg = vim.tbl_deep_extend("force", cfg, lsp_opts[lspclient])
trace(cfg)
end
load_cfg(ft, lspclient, cfg, loaded)
::continue::
end

@ -33,6 +33,7 @@ local key_maps = {
{key = "K", func = "hover({ popup_opts = { border = single }})"},
{key = "ga", mode = "n", func = "code_action()"},
{key = "ga", mode = "v", func = "range_code_action()"}, {key = "<Leader>re", func = "rename()"},
{key = "<Space>rn", func = "require('navigator.rename').rename()"},
{key = "<Leader>gi", func = "incoming_calls()"}, {key = "<Leader>go", func = "outgoing_calls()"},
{key = "gi", func = "implementation()"}, {key = "gt", func = "type_definition()"},
{key = "gL", func = "diagnostic.show_line_diagnostics({ popup_opts = { border = single }})"},

@ -0,0 +1,43 @@
-- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/rename.lua
local M = {}
local util = require "navigator.util"
local rename_prompt = "Rename -> "
M.rename = function()
local current_name = vim.fn.expand("<cword>")
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(bufnr, "buftype", "prompt")
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe")
vim.api.nvim_buf_add_highlight(bufnr, -1, "RenamePrompt", 0, 0, #rename_prompt)
vim.fn.prompt_setprompt(bufnr, rename_prompt)
local winnr = vim.api.nvim_open_win(bufnr, true, {
relative = "cursor",
width = 50,
height = 1,
row = -3,
col = 1,
style = "minimal",
border = "single"
})
vim.api.nvim_win_set_option(winnr, "winhl", "Normal:Floating")
util.map("n", "<ESC>", "<cmd>bd!<CR>", {silent = true, buffer = true})
util.map({"n", "i"}, "<CR>", "<cmd>lua require('navigator.rename').callback()<CR>",
{silent = true, buffer = true})
util.map("i", "<BS>", "<ESC>xi", {silent = true, buffer = true})
vim.cmd(string.format("normal i%s", current_name))
end
M.callback = function()
local new_name = vim.trim(vim.fn.getline("."):sub(#rename_prompt + 1, -1))
vim.cmd [[stopinsert]]
vim.cmd [[bd!]]
if #new_name == 0 or new_name == vim.fn.expand("<cword>") then
return
end
local params = vim.lsp.util.make_position_params()
params.newName = new_name
vim.lsp.buf_request(0, "textDocument/rename", params)
end
M.rename()
-- M.callback()
return M

@ -28,6 +28,31 @@ function M.get_data_from_file(filename, startLine)
return {data = data, line = displayLine}
end
M.merge = function(t1, t2)
for k, v in pairs(t2) do
t1[k] = v
end
return t1
end
M.map = function(modes, key, result, options)
options = M.merge({noremap = true, silent = false, expr = false, nowait = false}, options or {})
local buffer = options.buffer
options.buffer = nil
if type(modes) ~= "table" then
modes = {modes}
end
for i = 1, #modes do
if buffer then
vim.api.nvim_buf_set_keymap(0, modes[i], key, result, options)
else
vim.api.nvim_set_keymap(modes[i], key, result, options)
end
end
end
function M.get_base(path)
local len = #path
for i = len, 1, -1 do

Loading…
Cancel
Save