Add crates.nvim keymaps

This commit is contained in:
2023-12-01 15:26:01 -05:00
parent 46abe3df29
commit 65575378dd
2 changed files with 38 additions and 2 deletions

View File

@@ -1,3 +1,17 @@
-- From: https://github.com/Saecki/crates.nvim
local function show_documentation()
local filetype = vim.bo.filetype
if vim.tbl_contains({ 'vim','help' }, filetype) then
vim.cmd('h '..vim.fn.expand('<cword>'))
elseif vim.tbl_contains({ 'man' }, filetype) then
vim.cmd('Man '..vim.fn.expand('<cword>'))
elseif vim.fn.expand('%:t') == 'Cargo.toml' and require('crates').popup_available() then
require('crates').show_popup()
else
vim.lsp.buf.hover()
end
end
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
-- thallada: NOTE: copied also in lsp/init.lua since I can't figure out how to import it here
@@ -9,7 +23,7 @@ local on_attach = function(_, bufnr)
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap=true, silent=true, buffer=bufnr }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', 'K', show_documentation, bufopts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
vim.keymap.set('n', '<M-k>', vim.lsp.buf.signature_help, bufopts)
vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, bufopts)