4 changed files with 118 additions and 72 deletions
@ -1,6 +1,30 @@
|
||||
local lspconfig = require("lspconfig") |
||||
vim.lsp.config("clangd", { |
||||
cmd = { |
||||
vim.fn.stdpath("data") .. "/mason/bin/clangd", |
||||
"--background-index", |
||||
"--clang-tidy", |
||||
}, |
||||
|
||||
lspconfig.clangd.setup({ |
||||
cmd = { "clangd", "--background-index", "--clang-tidy" }, |
||||
filetypes = { "c", "cpp", "objc", "objcpp" }, |
||||
|
||||
root_markers = { |
||||
"compile_commands.json", |
||||
"compile_flags.txt", |
||||
"CMakeLists.txt", |
||||
"meson.build", |
||||
".git", |
||||
}, |
||||
|
||||
on_attach = function(client, bufnr) |
||||
require("lsp_signature").on_attach({ |
||||
bind = true, |
||||
floating_window = true, |
||||
hint_enable = true, |
||||
handler_opts = { |
||||
border = "rounded", |
||||
}, |
||||
}, bufnr) |
||||
end, |
||||
}) |
||||
|
||||
vim.lsp.enable("clangd") |
||||
|
||||
@ -1,59 +1,88 @@
|
||||
-- Credit to https://rsdlt.github.io/ for this code. |
||||
|
||||
local cmp = require'cmp' |
||||
local cmp = require("cmp") |
||||
|
||||
cmp.setup({ |
||||
-- Enable LSP snippets |
||||
snippet = { |
||||
expand = function(args) |
||||
vim.fn["vsnip#anonymous"](args.body) |
||||
vim.fn["vsnip#anonymous"](args.body) |
||||
end, |
||||
}, |
||||
mapping = { |
||||
['<C-p>'] = cmp.mapping.select_prev_item(), |
||||
['<C-n>'] = cmp.mapping.select_next_item(), |
||||
-- Add tab support |
||||
['<S-Tab>'] = cmp.mapping.select_prev_item(), |
||||
['<Tab>'] = cmp.mapping.select_next_item(), |
||||
['<C-S-f>'] = cmp.mapping.scroll_docs(-4), |
||||
['<C-f>'] = cmp.mapping.scroll_docs(4), |
||||
['<C-Space>'] = cmp.mapping.complete(), |
||||
['<C-e>'] = cmp.mapping.close(), |
||||
['<CR>'] = cmp.mapping.confirm({ |
||||
|
||||
mapping = cmp.mapping.preset.insert({ |
||||
["<C-p>"] = cmp.mapping.select_prev_item(), |
||||
["<C-n>"] = cmp.mapping.select_next_item(), |
||||
|
||||
["<C-f>"] = cmp.mapping.scroll_docs(4), |
||||
["<C-b>"] = cmp.mapping.scroll_docs(-4), |
||||
|
||||
["<C-Space>"] = cmp.mapping.complete(), |
||||
["<C-e>"] = cmp.mapping.abort(), |
||||
|
||||
["<CR>"] = cmp.mapping.confirm({ |
||||
behavior = cmp.ConfirmBehavior.Insert, |
||||
select = true, |
||||
}) |
||||
}, |
||||
-- Installed sources: |
||||
sources = { |
||||
{ name = 'path' }, -- file paths |
||||
{ name = 'nvim_lsp', keyword_length = 3 }, -- from language server |
||||
{ 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 = 'buffer', keyword_length = 2 }, -- source current buffer |
||||
{ name = 'vsnip', keyword_length = 2 }, -- nvim-cmp source for vim-vsnip |
||||
{ name = 'calc'}, -- source for math calculation |
||||
}, |
||||
select = false, |
||||
}), |
||||
|
||||
["<Tab>"] = cmp.mapping(function(fallback) |
||||
if cmp.visible() then |
||||
cmp.select_next_item() |
||||
elseif vim.fn == 1 then |
||||
vim.fn.feedkeys( |
||||
vim.api.nvim_replace_termcodes("<Plug>(vsnip-jump-next)", true, true, true), |
||||
"" |
||||
) |
||||
else |
||||
fallback() |
||||
end |
||||
end, { "i", "s" }), |
||||
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback) |
||||
if cmp.visible() then |
||||
cmp.select_prev_item() |
||||
elseif vim.fn["vsnip#jumpable"](-1) == 1 then |
||||
vim.fn.feedkeys( |
||||
vim.api.nvim_replace_termcodes("<Plug>(vsnip-jump-prev)", true, true, true), |
||||
"" |
||||
) |
||||
else |
||||
fallback() |
||||
end |
||||
end, { "i", "s" }), |
||||
}), |
||||
|
||||
sources = cmp.config.sources({ |
||||
{ name = "nvim_lsp", keyword_length = 2 }, |
||||
{ name = "path" }, |
||||
{ name = "vsnip", keyword_length = 2 }, |
||||
}, { |
||||
{ name = "buffer", keyword_length = 5 }, |
||||
}), |
||||
|
||||
window = { |
||||
completion = cmp.config.window.bordered(), |
||||
documentation = cmp.config.window.bordered(), |
||||
completion = cmp.config.window.bordered(), |
||||
documentation = cmp.config.window.bordered(), |
||||
}, |
||||
|
||||
formatting = { |
||||
fields = {'menu', 'abbr', 'kind'}, |
||||
format = function(entry, item) |
||||
local menu_icon ={ |
||||
nvim_lsp = 'λ', |
||||
vsnip = '⋗', |
||||
buffer = 'Ω', |
||||
path = '•', |
||||
} |
||||
item.menu = menu_icon[entry.source.name] |
||||
return item |
||||
end, |
||||
fields = { "abbr", "kind", "menu" }, |
||||
format = function(entry, item) |
||||
local menu_icon = { |
||||
nvim_lsp = "λ", |
||||
vsnip = "⋗", |
||||
buffer = "Ω", |
||||
path = "•", |
||||
} |
||||
|
||||
item.menu = menu_icon[entry.source.name] or entry.source.name |
||||
return item |
||||
end, |
||||
}, |
||||
|
||||
preselect = cmp.PreselectMode.None, |
||||
|
||||
completion = { |
||||
completeopt = "menu,menuone,noinsert,noselect", |
||||
}, |
||||
-- This will let enter work like expected and tab can be used to pick a suggestion. |
||||
preselect = cmp.PreselectMode.None |
||||
}) |
||||
|
||||
-- This also prevents enter from selecting the first suggestion. |
||||
vim.o.completeopt = "menuone,noselect,preview" |
||||
vim.o.completeopt = "menu,menuone,noinsert,noselect" |
||||
|
||||
|
||||
@ -1,19 +1,11 @@
|
||||
local rt = require("rust-tools") |
||||
|
||||
rt.setup({ |
||||
server = { |
||||
on_attach = function(_, bufnr) |
||||
-- Hover actions |
||||
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr }) |
||||
-- Code action groups |
||||
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr }) |
||||
end, |
||||
settings = { |
||||
['rust-analyzer'] = { |
||||
checkOnSave = { |
||||
command = "clippy" |
||||
} |
||||
} |
||||
} |
||||
vim.lsp.config("rust_analyzer", { |
||||
settings = { |
||||
["rust-analyzer"] = { |
||||
check = { |
||||
command = "clippy", |
||||
}, |
||||
}, |
||||
}, |
||||
}) |
||||
|
||||
vim.lsp.enable("rust_analyzer") |
||||
|
||||
Loading…
Reference in new issue