From 65575378dd1186561cf5b7f385d21bf46f700c15 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Fri, 1 Dec 2023 15:26:01 -0500 Subject: [PATCH] Add crates.nvim keymaps --- lua/plugins/crates-nvim.lua | 24 +++++++++++++++++++++++- lua/plugins/lsp/on_attach.lua | 16 +++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lua/plugins/crates-nvim.lua b/lua/plugins/crates-nvim.lua index 1f9edce..4e6360d 100644 --- a/lua/plugins/crates-nvim.lua +++ b/lua/plugins/crates-nvim.lua @@ -1 +1,23 @@ -require('crates').setup() +local crates = require('crates') +local opts = { silent = true } + +crates.setup() + +vim.keymap.set('n', 'ct', crates.toggle, { silent = true, desc = "Rust [C]rate [T]oggle" }) +vim.keymap.set('n', 'cr', crates.reload, { silent = true, desc = "Rust [C]rate [R]eload"}) + +vim.keymap.set('n', 'cv', crates.show_versions_popup, { silent = true, desc = "Rust [C]rate show [V]ersions" }) +vim.keymap.set('n', 'cf', crates.show_features_popup, { silent = true, desc = "Rust [C]rate show [F]eatures" }) +vim.keymap.set('n', 'cd', crates.show_dependencies_popup, { silent = true, desc = "Rust [C]rate show [D]ependencies" }) + +vim.keymap.set('n', 'cu', crates.update_crate, { silent = true, desc = "Rust [C]rate [U]pdate (to newest compatible version)" }) +vim.keymap.set('v', 'cu', crates.update_crates, { silent = true, desc = "Rust [C]rates [U]pdate (to newest compatible versions)" }) +vim.keymap.set('n', 'ca', crates.update_all_crates, { silent = true, desc = "Rust [C]rates update [A]ll (to newest compatible versions)" }) +vim.keymap.set('n', 'cU', crates.upgrade_crate, { silent = true, desc = "Rust [C]rate [U]pgrade" }) +vim.keymap.set('v', 'cU', crates.upgrade_crates, { silent = true, desc = "Rust [C]rates [U]pgrade" }) +vim.keymap.set('n', 'cA', crates.upgrade_all_crates, { silent = true, desc = "Rust [C]rates upgrade [A]ll" }) + +vim.keymap.set('n', 'cH', crates.open_homepage, { silent = true, desc = "Rust [C]rate open [H]omepage" }) +vim.keymap.set('n', 'cR', crates.open_repository, { silent = true, desc = "Rust [C]rate open [R]epository" }) +vim.keymap.set('n', 'cD', crates.open_documentation, { silent = true, desc = "Rust [C]rate open [D]ocumentation" }) +vim.keymap.set('n', 'cC', crates.open_crates_io, { silent = true, desc = "Rust [C]rate open [C]rates.io" }) diff --git a/lua/plugins/lsp/on_attach.lua b/lua/plugins/lsp/on_attach.lua index eb2490e..acd395f 100644 --- a/lua/plugins/lsp/on_attach.lua +++ b/lua/plugins/lsp/on_attach.lua @@ -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('')) + elseif vim.tbl_contains({ 'man' }, filetype) then + vim.cmd('Man '..vim.fn.expand('')) + 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', '', vim.lsp.buf.signature_help, bufopts) vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts)