Skip to content

Commit

Permalink
fix!: update lsp mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Aug 15, 2024
1 parent aad4388 commit 62aad14
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
35 changes: 20 additions & 15 deletions root/.config/nvim/lua/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,16 @@ function M.lspconfig()
attach_codelens(client, bufnr)
end, M.get_capabilities())

vim.keymap.del("n", "]d")
vim.keymap.del("n", "[d")
vim.keymap.del("n", "]D")
vim.keymap.del("n", "[D")
-- remove default nvim lsp keymap
if vim.version.ge(vim.version(), { 0, 10, 0 }) then
vim.keymap.del("n", "]d")
vim.keymap.del("n", "[d")
vim.keymap.del("n", "]D")
vim.keymap.del("n", "[D")
vim.keymap.del({"x", "n"}, "gra")
vim.keymap.del("n", "grn")
vim.keymap.del("n", "grr")
end
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd("LspAttach", {
Expand All @@ -241,22 +247,21 @@ function M.lspconfig()
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = ev.buf }
vim.keymap.set("n", "grD", vim.lsp.buf.declaration, bufopts)
vim.keymap.set("n", "grd", vim.lsp.buf.definition, bufopts)
-- vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
vim.keymap.set("n", "gri", vim.lsp.buf.implementation, bufopts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
vim.keymap.set("n", "<leader>gD", vim.lsp.buf.declaration, bufopts)
vim.keymap.set("n", "<leader>gd", vim.lsp.buf.definition, bufopts)
vim.keymap.set("n", "<leader>K", vim.lsp.buf.hover, bufopts)
vim.keymap.set("n", "<leader>gi", vim.lsp.buf.implementation, bufopts)
vim.keymap.set("n", "<leader>sh", vim.lsp.buf.signature_help, bufopts)
-- vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, bufopts)
-- vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
-- vim.keymap.set("n", "<space>wl", function()
-- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
-- end, bufopts)
vim.keymap.set("n", "grt", vim.lsp.buf.type_definition, bufopts)
if vim.version.ge({ 0, 10, 0 }, vim.version()) then
vim.keymap.set("n", "grn", vim.lsp.buf.rename, bufopts)
vim.keymap.set({ "n", "x" }, "gra", vim.lsp.buf.code_action, bufopts)
vim.keymap.set("n", "grr", vim.lsp.buf.references, bufopts)
end
vim.keymap.set("n", "<leader>gt", vim.lsp.buf.type_definition, bufopts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
vim.keymap.set("n", "<leader>gr", vim.lsp.buf.references, bufopts)
-- range_code_action and range_formatting are deprecated
vim.keymap.set({ "n", "x" }, "<leader>ac", vim.lsp.buf.code_action, bufopts)
vim.keymap.set({ "n", "x" }, "<leader>fmt", function()
vim.lsp.buf.format({ async = true })
end, bufopts)
Expand Down
18 changes: 8 additions & 10 deletions root/.vim/vimrc.d/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ autocmd FileType python ++once call coc#config('python.formatting.provider', g:p
function! s:show_documentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction

Expand Down Expand Up @@ -44,23 +42,23 @@ nmap <silent> [de <Plug>(coc-diagnostic-prev-error)
nmap <silent> ]de <Plug>(coc-diagnostic-next-error)
" GoTo code navigation.
nmap <silent> grd <Plug>(coc-definition)
nmap <silent> grt <Plug>(coc-type-definition)
nmap <silent> gri <Plug>(coc-implementation)
nmap <silent> <leader>gd <Plug>(coc-definition)
nmap <silent> <leader>gt <Plug>(coc-type-definition)
nmap <silent> <leader>gi <Plug>(coc-implementation)
" See Also: :HelpRg mapping in root/.vim/vimrc.d/fzf.vim
nmap <silent> grr <Plug>(coc-references)
nmap <silent> <leader>gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> <leader>K :call <SID>show_documentation()<CR>
" Applying code actions to the selected code block
" Example: `<leader>aap` for current paragraph
xmap gra <Plug>(coc-codeaction-selected)
xmap <leader>ac <Plug>(coc-codeaction-selected)
" Remap keys for applying code actions at the cursor position
nmap gra <Plug>(coc-codeaction-cursor)
nmap <leader>ac <Plug>(coc-codeaction-cursor)
" Remap keys for apply code actions affect whole buffer
nmap grs <Plug>(coc-codeaction-source)
nmap <leader>as <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line
nmap <leader>qf <Plug>(coc-fix-current)
Expand All @@ -72,7 +70,7 @@ nmap <silent> <leader>re <Plug>(coc-codeaction-refactor-selected)
" Run the Code Lens action on the current line
nmap <leader>cl <Plug>(coc-codelens-action)
nmap grn <Plug>(coc-rename)
nmap <leader>rn <Plug>(coc-rename)
nmap <leader>fmt <Plug>(coc-format)
xmap <leader>fmt <Plug>(coc-format-selected)
Expand Down

0 comments on commit 62aad14

Please sign in to comment.