Add crates.nvim keymaps

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

View File

@ -1 +1,23 @@
require('crates').setup()
local crates = require('crates')
local opts = { silent = true }
crates.setup()
vim.keymap.set('n', '<leader>ct', crates.toggle, { silent = true, desc = "Rust [C]rate [T]oggle" })
vim.keymap.set('n', '<leader>cr', crates.reload, { silent = true, desc = "Rust [C]rate [R]eload"})
vim.keymap.set('n', '<leader>cv', crates.show_versions_popup, { silent = true, desc = "Rust [C]rate show [V]ersions" })
vim.keymap.set('n', '<leader>cf', crates.show_features_popup, { silent = true, desc = "Rust [C]rate show [F]eatures" })
vim.keymap.set('n', '<leader>cd', crates.show_dependencies_popup, { silent = true, desc = "Rust [C]rate show [D]ependencies" })
vim.keymap.set('n', '<leader>cu', crates.update_crate, { silent = true, desc = "Rust [C]rate [U]pdate (to newest compatible version)" })
vim.keymap.set('v', '<leader>cu', crates.update_crates, { silent = true, desc = "Rust [C]rates [U]pdate (to newest compatible versions)" })
vim.keymap.set('n', '<leader>ca', crates.update_all_crates, { silent = true, desc = "Rust [C]rates update [A]ll (to newest compatible versions)" })
vim.keymap.set('n', '<leader>cU', crates.upgrade_crate, { silent = true, desc = "Rust [C]rate [U]pgrade" })
vim.keymap.set('v', '<leader>cU', crates.upgrade_crates, { silent = true, desc = "Rust [C]rates [U]pgrade" })
vim.keymap.set('n', '<leader>cA', crates.upgrade_all_crates, { silent = true, desc = "Rust [C]rates upgrade [A]ll" })
vim.keymap.set('n', '<leader>cH', crates.open_homepage, { silent = true, desc = "Rust [C]rate open [H]omepage" })
vim.keymap.set('n', '<leader>cR', crates.open_repository, { silent = true, desc = "Rust [C]rate open [R]epository" })
vim.keymap.set('n', '<leader>cD', crates.open_documentation, { silent = true, desc = "Rust [C]rate open [D]ocumentation" })
vim.keymap.set('n', '<leader>cC', crates.open_crates_io, { silent = true, desc = "Rust [C]rate open [C]rates.io" })

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)