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" }, |
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({ |
cmp.setup({ |
||||||
-- Enable LSP snippets |
|
||||||
snippet = { |
snippet = { |
||||||
expand = function(args) |
expand = function(args) |
||||||
vim.fn["vsnip#anonymous"](args.body) |
vim.fn["vsnip#anonymous"](args.body) |
||||||
end, |
end, |
||||||
}, |
}, |
||||||
mapping = { |
|
||||||
['<C-p>'] = cmp.mapping.select_prev_item(), |
mapping = cmp.mapping.preset.insert({ |
||||||
['<C-n>'] = cmp.mapping.select_next_item(), |
["<C-p>"] = cmp.mapping.select_prev_item(), |
||||||
-- Add tab support |
["<C-n>"] = cmp.mapping.select_next_item(), |
||||||
['<S-Tab>'] = cmp.mapping.select_prev_item(), |
|
||||||
['<Tab>'] = cmp.mapping.select_next_item(), |
["<C-f>"] = cmp.mapping.scroll_docs(4), |
||||||
['<C-S-f>'] = cmp.mapping.scroll_docs(-4), |
["<C-b>"] = cmp.mapping.scroll_docs(-4), |
||||||
['<C-f>'] = cmp.mapping.scroll_docs(4), |
|
||||||
['<C-Space>'] = cmp.mapping.complete(), |
["<C-Space>"] = cmp.mapping.complete(), |
||||||
['<C-e>'] = cmp.mapping.close(), |
["<C-e>"] = cmp.mapping.abort(), |
||||||
['<CR>'] = cmp.mapping.confirm({ |
|
||||||
|
["<CR>"] = cmp.mapping.confirm({ |
||||||
behavior = cmp.ConfirmBehavior.Insert, |
behavior = cmp.ConfirmBehavior.Insert, |
||||||
select = true, |
select = false, |
||||||
}) |
}), |
||||||
}, |
|
||||||
-- Installed sources: |
["<Tab>"] = cmp.mapping(function(fallback) |
||||||
sources = { |
if cmp.visible() then |
||||||
{ name = 'path' }, -- file paths |
cmp.select_next_item() |
||||||
{ name = 'nvim_lsp', keyword_length = 3 }, -- from language server |
elseif vim.fn == 1 then |
||||||
{ name = 'nvim_lsp_signature_help'}, -- display function signatures with current parameter emphasized |
vim.fn.feedkeys( |
||||||
{ name = 'nvim_lua', keyword_length = 2}, -- complete neovim's Lua runtime API such vim.lsp.* |
vim.api.nvim_replace_termcodes("<Plug>(vsnip-jump-next)", true, true, true), |
||||||
{ 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 |
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 = { |
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 = { "abbr", "kind", "menu" }, |
||||||
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] or entry.source.name |
||||||
return item |
return item |
||||||
end, |
end, |
||||||
}, |
}, |
||||||
-- This will let enter work like expected and tab can be used to pick a suggestion. |
|
||||||
preselect = cmp.PreselectMode.None |
preselect = cmp.PreselectMode.None, |
||||||
|
|
||||||
|
completion = { |
||||||
|
completeopt = "menu,menuone,noinsert,noselect", |
||||||
|
}, |
||||||
}) |
}) |
||||||
|
|
||||||
-- This also prevents enter from selecting the first suggestion. |
vim.o.completeopt = "menu,menuone,noinsert,noselect" |
||||||
vim.o.completeopt = "menuone,noselect,preview" |
|
||||||
|
|||||||
@ -1,19 +1,11 @@ |
|||||||
local rt = require("rust-tools") |
vim.lsp.config("rust_analyzer", { |
||||||
|
|
||||||
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 = { |
settings = { |
||||||
['rust-analyzer'] = { |
["rust-analyzer"] = { |
||||||
checkOnSave = { |
check = { |
||||||
command = "clippy" |
command = "clippy", |
||||||
} |
}, |
||||||
} |
}, |
||||||
} |
|
||||||
}, |
}, |
||||||
}) |
}) |
||||||
|
|
||||||
|
vim.lsp.enable("rust_analyzer") |
||||||
|
|||||||
Loading…
Reference in new issue