90 lines
2.3 KiB
Lua
90 lines
2.3 KiB
Lua
local Lsp = {}
|
|
|
|
Lsp.setup = function()
|
|
local luasnip = require("luasnip")
|
|
local cmp = require("cmp")
|
|
|
|
local has_words_before = function()
|
|
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
|
|
return false
|
|
end
|
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
|
return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil
|
|
end
|
|
|
|
cmp.setup({
|
|
snippet = {
|
|
expand = function(args)
|
|
luasnip.lsp_expand(args.body)
|
|
end,
|
|
},
|
|
window = {
|
|
completion = cmp.config.window.bordered(),
|
|
documentation = cmp.config.window.bordered(),
|
|
},
|
|
mapping = {
|
|
["<C-p>"] = function()
|
|
if luasnip.jumpable(-1) then
|
|
luasnip.jump(-1)
|
|
else
|
|
cmp.mapping.select_prev_item()
|
|
end
|
|
end,
|
|
["<C-n>"] = function()
|
|
if luasnip.expand_or_jumpable() then
|
|
luasnip.expand_or_jump()
|
|
else
|
|
cmp.mapping.select_next_item()
|
|
end
|
|
end,
|
|
["<C-d>"] = 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({
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
select = true,
|
|
}),
|
|
["<Tab>"] = function(fallback)
|
|
if cmp.visible() and has_words_before() then
|
|
cmp.select_next_item()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
["<S-Tab>"] = function(fallback)
|
|
if cmp.visible() and has_words_before() then
|
|
cmp.select_prev_item()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
},
|
|
sources = {
|
|
{ name = "copilot", group_index = 2 },
|
|
{ name = "nvim_lsp", group_index = 2 },
|
|
{ name = "luasnip", group_index = 2 },
|
|
},
|
|
})
|
|
|
|
vim.o.completeopt = "menuone,noselect"
|
|
vim.o.updatetime = 250
|
|
vim.cmd([[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]])
|
|
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
|
virtual_text = {
|
|
source = "if_many",
|
|
},
|
|
})
|
|
|
|
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" })
|
|
|
|
vim.lsp.handlers["textDocument/signatureHelp"] =
|
|
vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" })
|
|
|
|
vim.diagnostic.config({
|
|
float = { border = "rounded", zindex = 1 },
|
|
})
|
|
end
|
|
|
|
Lsp.setup()
|