feat(nvim/cmp): connect rust-tools
This commit is contained in:
parent
abbbb93cef
commit
4771957859
@ -1,12 +1,32 @@
|
|||||||
|
-- Set completeopt to have a better completion experience
|
||||||
|
-- :help completeopt
|
||||||
|
-- menuone: popup even when there's only one match
|
||||||
|
-- noinsert: Do not insert text until a selection is made
|
||||||
|
-- noselect: Do not select, force to select one from the menu
|
||||||
|
-- shortness: avoid showing extra messages when using completion
|
||||||
|
-- updatetime: set updatetime for CursorHold
|
||||||
|
vim.opt.completeopt = {'menuone', 'noselect', 'noinsert'}
|
||||||
|
vim.opt.shortmess = vim.opt.shortmess + {c = true}
|
||||||
|
vim.api.nvim_set_option('updatetime', 300)
|
||||||
|
|
||||||
|
-- Fixed column for diagnostics to appear
|
||||||
|
-- Show autodiagnostic popup on cursor hover_range
|
||||||
|
-- Goto previous / next diagnostic warning / error
|
||||||
|
-- Show inlay_hints more frequently
|
||||||
|
vim.cmd([[
|
||||||
|
set signcolumn=yes
|
||||||
|
autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false })
|
||||||
|
]])
|
||||||
|
|
||||||
|
vim.opt.spell = true
|
||||||
|
vim.opt.spelllang = {'en_us'}
|
||||||
-- Completion Plugin Setup
|
-- Completion Plugin Setup
|
||||||
local cmp = require'cmp'
|
local cmp = require 'cmp'
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
-- Enable LSP snippets
|
-- Enable LSP snippets
|
||||||
snippet = {
|
snippet = {expand = function(args) vim.fn["vsnip#anonymous"](args.body) end},
|
||||||
expand = function(args)
|
-- <C> = CTRL
|
||||||
vim.fn["vsnip#anonymous"](args.body)
|
-- <S> = SHIFT
|
||||||
end,
|
|
||||||
},
|
|
||||||
mapping = {
|
mapping = {
|
||||||
['<C-p>'] = cmp.mapping.select_prev_item(),
|
['<C-p>'] = cmp.mapping.select_prev_item(),
|
||||||
['<C-n>'] = cmp.mapping.select_next_item(),
|
['<C-n>'] = cmp.mapping.select_next_item(),
|
||||||
@ -19,34 +39,41 @@ cmp.setup({
|
|||||||
['<C-e>'] = cmp.mapping.close(),
|
['<C-e>'] = cmp.mapping.close(),
|
||||||
['<CR>'] = cmp.mapping.confirm({
|
['<CR>'] = cmp.mapping.confirm({
|
||||||
behavior = cmp.ConfirmBehavior.Insert,
|
behavior = cmp.ConfirmBehavior.Insert,
|
||||||
select = true,
|
select = true
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
-- Installed sources:
|
-- Installed sources:
|
||||||
sources = {
|
sources = {
|
||||||
{ name = 'path' }, -- file paths
|
{name = 'path'}, -- file paths
|
||||||
{ name = 'nvim_lsp', keyword_length = 3 }, -- from language server
|
{name = 'nvim_lsp', keyword_length = 3}, -- from language server
|
||||||
{ name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized
|
{name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized
|
||||||
{ name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.*
|
{name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.*
|
||||||
{ name = 'buffer', keyword_length = 2 }, -- source current buffer
|
{name = 'buffer', keyword_length = 2}, -- source current buffer
|
||||||
{ name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip
|
{name = 'vsnip', keyword_length = 2}, -- nvim-cmp source for vim-vsnip
|
||||||
{ name = 'calc'}, -- source for math calculation
|
{name = 'calc'}, -- source for math calculation
|
||||||
|
{
|
||||||
|
name = 'spell',
|
||||||
|
option = {
|
||||||
|
keep_all_entries = false,
|
||||||
|
enable_in_context = function() return true end
|
||||||
|
}
|
||||||
|
}, {name = 'conventionalcommits'}
|
||||||
},
|
},
|
||||||
window = {
|
window = {
|
||||||
completion = cmp.config.window.bordered(),
|
completion = cmp.config.window.bordered(),
|
||||||
documentation = cmp.config.window.bordered(),
|
documentation = cmp.config.window.bordered()
|
||||||
},
|
},
|
||||||
formatting = {
|
formatting = {
|
||||||
fields = {'menu', 'abbr', 'kind'},
|
fields = {'menu', 'abbr', 'kind'},
|
||||||
format = function(entry, item)
|
format = function(entry, item)
|
||||||
local menu_icon ={
|
local menu_icon = {
|
||||||
nvim_lsp = 'λ',
|
nvim_lsp = 'λ',
|
||||||
vsnip = '⋗',
|
vsnip = '⋗',
|
||||||
buffer = 'Ω',
|
buffer = 'Ω',
|
||||||
path = '🖫',
|
path = '🖫'
|
||||||
}
|
}
|
||||||
item.menu = menu_icon[entry.source.name]
|
item.menu = menu_icon[entry.source.name]
|
||||||
return item
|
return item
|
||||||
end,
|
end
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
|
20
init.lua
20
init.lua
@ -109,7 +109,6 @@ dap.listeners.before.event_exited["dapui_config"] = function() dapui.close() end
|
|||||||
-- Setup language servers.
|
-- Setup language servers.
|
||||||
local lspconfig = require('lspconfig')
|
local lspconfig = require('lspconfig')
|
||||||
|
|
||||||
|
|
||||||
-- Global mappings.
|
-- Global mappings.
|
||||||
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
||||||
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float)
|
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float)
|
||||||
@ -127,25 +126,26 @@ vim.api.nvim_create_autocmd('LspAttach', {
|
|||||||
|
|
||||||
-- Buffer local mappings.
|
-- Buffer local mappings.
|
||||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||||
local opts = { buffer = ev.buf }
|
local opts = {buffer = ev.buf}
|
||||||
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
||||||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
||||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
||||||
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
|
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
|
||||||
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
||||||
vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, opts)
|
vim.keymap
|
||||||
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, opts)
|
.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, opts)
|
||||||
|
vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder,
|
||||||
|
opts)
|
||||||
vim.keymap.set('n', '<leader>wl', function()
|
vim.keymap.set('n', '<leader>wl', function()
|
||||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||||
end, opts)
|
end, opts)
|
||||||
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, opts)
|
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, opts)
|
||||||
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
||||||
vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts)
|
vim.keymap.set({'n', 'v'}, '<leader>ca', vim.lsp.buf.code_action, opts)
|
||||||
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
||||||
vim.keymap.set('n', '<leader>f', function()
|
vim.keymap.set('n', '<leader>f',
|
||||||
vim.lsp.buf.format { async = true }
|
function() vim.lsp.buf.format {async = true} end, opts)
|
||||||
end, opts)
|
end
|
||||||
end,
|
|
||||||
})
|
})
|
||||||
|
require("completion")
|
||||||
require("rust")
|
require("rust")
|
||||||
|
125
rust.lua
125
rust.lua
@ -1,10 +1,10 @@
|
|||||||
local rt = require("rust-tools")
|
local rt = require("rust-tools")
|
||||||
|
local nvim_lsp = require 'lspconfig'
|
||||||
|
local c = vim.lsp.protocol.make_client_capabilities()
|
||||||
local deps = require("nvim-deps")
|
local deps = require("nvim-deps")
|
||||||
|
|
||||||
rt.setup(
|
rt.setup({
|
||||||
{
|
|
||||||
tools = { -- rust-tools options
|
tools = { -- rust-tools options
|
||||||
|
|
||||||
-- how to execute terminal commands
|
-- how to execute terminal commands
|
||||||
-- options right now: termopen / quickfix / toggleterm / vimux
|
-- options right now: termopen / quickfix / toggleterm / vimux
|
||||||
executor = require("rust-tools.executors").termopen,
|
executor = require("rust-tools.executors").termopen,
|
||||||
@ -50,7 +50,7 @@ rt.setup(
|
|||||||
right_align_padding = 7,
|
right_align_padding = 7,
|
||||||
|
|
||||||
-- The color of the hints
|
-- The color of the hints
|
||||||
highlight = "Comment",
|
highlight = "Comment"
|
||||||
},
|
},
|
||||||
|
|
||||||
-- options same as lsp hover / vim.lsp.util.open_floating_preview()
|
-- options same as lsp hover / vim.lsp.util.open_floating_preview()
|
||||||
@ -59,14 +59,10 @@ rt.setup(
|
|||||||
-- the border that is used for the hover window
|
-- the border that is used for the hover window
|
||||||
-- see vim.api.nvim_open_win()
|
-- see vim.api.nvim_open_win()
|
||||||
border = {
|
border = {
|
||||||
{ "╭", "FloatBorder" },
|
{"╭", "FloatBorder"}, {"─", "FloatBorder"},
|
||||||
{ "─", "FloatBorder" },
|
{"╮", "FloatBorder"}, {"│", "FloatBorder"},
|
||||||
{ "╮", "FloatBorder" },
|
{"╯", "FloatBorder"}, {"─", "FloatBorder"},
|
||||||
{ "│", "FloatBorder" },
|
{"╰", "FloatBorder"}, {"│", "FloatBorder"}
|
||||||
{ "╯", "FloatBorder" },
|
|
||||||
{ "─", "FloatBorder" },
|
|
||||||
{ "╰", "FloatBorder" },
|
|
||||||
{ "│", "FloatBorder" },
|
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Maximal width of the hover window. Nil means no max.
|
-- Maximal width of the hover window. Nil means no max.
|
||||||
@ -77,7 +73,7 @@ rt.setup(
|
|||||||
|
|
||||||
-- whether the hover action window gets automatically focused
|
-- whether the hover action window gets automatically focused
|
||||||
-- default: false
|
-- default: false
|
||||||
auto_focus = false,
|
auto_focus = false
|
||||||
},
|
},
|
||||||
|
|
||||||
-- settings for showing the crate graph based on graphviz and the dot
|
-- settings for showing the crate graph based on graphviz and the dot
|
||||||
@ -100,62 +96,16 @@ rt.setup(
|
|||||||
-- Is used for input validation and autocompletion
|
-- Is used for input validation and autocompletion
|
||||||
-- Last updated: 2021-08-26
|
-- Last updated: 2021-08-26
|
||||||
enabled_graphviz_backends = {
|
enabled_graphviz_backends = {
|
||||||
"bmp",
|
"bmp", "cgimage", "canon", "dot", "gv", "xdot", "xdot1.2",
|
||||||
"cgimage",
|
"xdot1.4", "eps", "exr", "fig", "gd", "gd2", "gif", "gtk",
|
||||||
"canon",
|
"ico", "cmap", "ismap", "imap", "cmapx", "imap_np", "cmapx_np",
|
||||||
"dot",
|
"jpg", "jpeg", "jpe", "jp2", "json", "json0", "dot_json",
|
||||||
"gv",
|
"xdot_json", "pdf", "pic", "pct", "pict", "plain", "plain-ext",
|
||||||
"xdot",
|
"png", "pov", "ps", "ps2", "psd", "sgi", "svg", "svgz", "tga",
|
||||||
"xdot1.2",
|
"tiff", "tif", "tk", "vml", "vmlz", "wbmp", "webp", "xlib",
|
||||||
"xdot1.4",
|
"x11"
|
||||||
"eps",
|
}
|
||||||
"exr",
|
}
|
||||||
"fig",
|
|
||||||
"gd",
|
|
||||||
"gd2",
|
|
||||||
"gif",
|
|
||||||
"gtk",
|
|
||||||
"ico",
|
|
||||||
"cmap",
|
|
||||||
"ismap",
|
|
||||||
"imap",
|
|
||||||
"cmapx",
|
|
||||||
"imap_np",
|
|
||||||
"cmapx_np",
|
|
||||||
"jpg",
|
|
||||||
"jpeg",
|
|
||||||
"jpe",
|
|
||||||
"jp2",
|
|
||||||
"json",
|
|
||||||
"json0",
|
|
||||||
"dot_json",
|
|
||||||
"xdot_json",
|
|
||||||
"pdf",
|
|
||||||
"pic",
|
|
||||||
"pct",
|
|
||||||
"pict",
|
|
||||||
"plain",
|
|
||||||
"plain-ext",
|
|
||||||
"png",
|
|
||||||
"pov",
|
|
||||||
"ps",
|
|
||||||
"ps2",
|
|
||||||
"psd",
|
|
||||||
"sgi",
|
|
||||||
"svg",
|
|
||||||
"svgz",
|
|
||||||
"tga",
|
|
||||||
"tiff",
|
|
||||||
"tif",
|
|
||||||
"tk",
|
|
||||||
"vml",
|
|
||||||
"vmlz",
|
|
||||||
"wbmp",
|
|
||||||
"webp",
|
|
||||||
"xlib",
|
|
||||||
"x11",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
-- all the opts to send to nvim-lspconfig
|
-- all the opts to send to nvim-lspconfig
|
||||||
@ -165,16 +115,39 @@ rt.setup(
|
|||||||
-- standalone file support
|
-- standalone file support
|
||||||
-- setting it to false may improve startup time
|
-- setting it to false may improve startup time
|
||||||
standalone = true,
|
standalone = true,
|
||||||
cmd = { (deps.rust_analyzer_path .. "/bin/rust-analyzer") },
|
cmd = {(deps.rust_analyzer_path .. "/bin/rust-analyzer")},
|
||||||
|
capabilities = require("cmp_nvim_lsp").default_capabilities(c),
|
||||||
|
on_attach = function(_, bufnr)
|
||||||
|
local keymap_opts = {buffer = bufnr}
|
||||||
|
-- Hover actions
|
||||||
|
vim.keymap.set("n", "<leader>h", rt.hover_actions.hover_actions,
|
||||||
|
keymap_opts)
|
||||||
|
-- Code action groups
|
||||||
|
vim.keymap.set("n", "<leader>as",
|
||||||
|
rt.code_action_group.code_action_group, keymap_opts)
|
||||||
|
vim.keymap.set('n', '<leader>c', rt.open_cargo_toml.open_cargo_toml)
|
||||||
|
vim.keymap.set("n", "g0", vim.lsp.buf.document_symbol, keymap_opts)
|
||||||
|
local diag_float_grp = vim.api.nvim_create_augroup(
|
||||||
|
"DiagnosticFloat", {clear = true})
|
||||||
|
vim.api.nvim_create_autocmd("CursorHold", {
|
||||||
|
callback = function()
|
||||||
|
vim.diagnostic.open_float(nil, {focusable = false})
|
||||||
|
end,
|
||||||
|
group = diag_float_grp
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Goto previous/next diagnostic warning/error
|
||||||
|
vim.keymap.set("n", "g[", vim.diagnostic.goto_prev, keymap_opts)
|
||||||
|
vim.keymap.set("n", "g]", vim.diagnostic.goto_next, keymap_opts)
|
||||||
|
end
|
||||||
}, -- rust-analyzer options
|
}, -- rust-analyzer options
|
||||||
|
|
||||||
-- debugging stuff
|
-- debugging stuff
|
||||||
dap = {
|
dap = {
|
||||||
adapter = {
|
adapter = {
|
||||||
type = "executable",
|
type = "executable",
|
||||||
command = deps.lldb_path .. "lldb-vscode",
|
command = deps.lldb_path .. "/bin/lldb-vscode",
|
||||||
name = "rt_lldb",
|
name = "rt_lldb"
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user