Skip to content

Commit

Permalink
crates: add key mappings
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>

Former-commit-id: d6a2c15
Former-commit-id: df310a9
Former-commit-id: 1c4546b
  • Loading branch information
Avimitin committed Feb 21, 2023
1 parent 7027d95 commit 73bbd93
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lua/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ register("saecki/crates.nvim", {
border = "single",
},
})

-- Find buffer id for `Cargo.toml` file
local existing_buffer = vim.api.nvim_list_bufs()
local cargo_toml_buf_id = nil
for _, buf_id in ipairs(existing_buffer) do
local buf_name = vim.api.nvim_buf_get_name(buf_id)
local filename = vim.fn.fnamemodify(buf_name, ":t")
if filename == "Cargo.toml" then
cargo_toml_buf_id = buf_id
end
end
if cargo_toml_buf_id == nil then
return
end

local crates = require("crates")

-- this key mappings will only apply to the `Cargo.toml` file buffer
require("libs.keymap").buf_map(cargo_toml_buf_id, "n", {
{ "<leader>cu", crates.upgrade_crate, desc = "Upgrade crate under current cursor" },
{ "<leader>cv", crates.show_versions_popup, desc = "Show current crate versions" },
{ "<leader>cf", crates.show_features_popup, desc = "Show current crate features" },
{ "<leader>cR", crates.open_repository, desc = "Open source code in browser" },
{ "<leader>cD", crates.open_documentation, desc = "Open docs.rs in browser" },
})
end,
})

Expand Down

0 comments on commit 73bbd93

Please sign in to comment.