neovim-config/lua/plugins/rust-tools-nvim.lua

52 lines
1.9 KiB
Lua
Raw Normal View History

2022-10-06 04:44:41 +00:00
local rt = require('rust-tools')
local lsp_on_attach = require('plugins.lsp.on_attach')
local nvim_cmp_capabilities = require('plugins.nvim-cmp').capabilities
local extension_path = vim.env.HOME .. '/vscode-lldb/extension/'
local codelldb_path = extension_path .. 'adapter/codelldb'
local liblldb_path = extension_path .. 'lldb/lib/liblldb.so'
rt.setup({
tools = {
runnables = {
use_telescope = true
},
},
server = {
capabilities = nvim_cmp_capabilities,
on_attach = function(client, bufnr)
lsp_on_attach(client, bufnr)
vim.keymap.set('n', '<C-space>', rt.hover_actions.hover_actions, { buffer = bufnr, desc = "Show hover actions under cursor" })
2022-10-06 04:44:41 +00:00
-- Code action groups
vim.keymap.set('n', '<leader>a', rt.code_action_group.code_action_group, { buffer = bufnr, desc = "Show code actions under cursor" })
vim.keymap.set('n', '<leader>rc', rt.open_cargo_toml.open_cargo_toml, { buffer = bufnr, desc = "Open Cargo.toml for current project" })
vim.keymap.set('n', '<leader>rp', rt.parent_module.parent_module, { buffer = bufnr, desc = "Go to parent Rust module" })
vim.keymap.set('n', '<leader>rm', rt.expand_macro.expand_macro, { buffer = bufnr, desc = "Expand Rust macro" })
2022-10-06 04:44:41 +00:00
end,
settings = {
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
2023-12-01 20:26:00 +00:00
['rust-analyzer'] = {
2022-10-06 04:44:41 +00:00
-- enable clippy on save
checkOnSave = {
2023-12-01 20:26:00 +00:00
command = 'clippy'
2022-10-06 04:44:41 +00:00
},
}
},
},
dap = {
adapter = require('rust-tools.dap').get_codelldb_adapter(
codelldb_path,
liblldb_path
)
}
})
vim.api.nvim_create_autocmd('BufRead', {
group = vim.api.nvim_create_augroup('CmpSourceCargo', { clear = true }),
pattern = 'Cargo.toml',
callback = function()
require('cmp').setup.buffer({ sources = { { name = 'crates' } } })
end,
})