Skip to content

Commit

Permalink
fix(neovim): and back to nvim-cmp again
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Dec 24, 2024
1 parent 500c056 commit 6752a51
Showing 1 changed file with 130 additions and 62 deletions.
192 changes: 130 additions & 62 deletions .config/nvim/lua/plugins/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,131 @@ local icons = {
}

return {
-- LSP
-- Completion
{
"neovim/nvim-lspconfig",
"hrsh7th/nvim-cmp",
dependencies = {
{
"saghen/blink.cmp", -- Better completion
version = "*",
dependencies = {
"giuxtaposition/blink-cmp-copilot",
"rafamadriz/friendly-snippets",
"L3MON4D3/LuaSnip",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lua",
"lukas-reineke/cmp-under-comparator",
},
config = function()
local luasnip = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load()
vim.opt.completeopt = { "menu", "menuone", "noselect" }

local cmp = require("cmp")
cmp.setup({
formatting = {
fields = { "abbr", "kind", "menu" },
format = require("lspkind").cmp_format({
mode = "symbol", -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters
ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
}),
},
opts = {
-- 'enter' for mappings similar to 'super-tab' but with 'enter' to accept
keymap = {
preset = "enter",
["<S-Tab>"] = { "select_prev", "fallback" },
["<Tab>"] = { "select_next", "fallback" },
-- ["<CR>"] = { "accept", "fallback" },
-- ["<C-e>"] = { "hide", "fallback" },
-- ["<C-space>"] = { "show", "show_documentation", "hide_documentation" },
-- ["<Tab>"] = { "snippet_forward", "fallback" },
-- ["<S-Tab>"] = { "snippet_backward", "fallback" },
-- ["<Up>"] = { "select_prev", "fallback" },
-- ["<Down>"] = { "select_next", "fallback" },
-- ["<C-b>"] = { "scroll_documentation_up", "fallback" },
-- ["<C-f>"] = { "scroll_documentation_down", "fallback" },
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<CR>"] = cmp.mapping.confirm({ select = false }),
["<Tab>"] = cmp.mapping(function(fallback)
local col = vim.fn.col(".") - 1

snippets = {
expand = function(snippet)
require("luasnip").lsp_expand(snippet)
end,
active = function(filter)
if filter and filter.direction then
return require("luasnip").jumpable(filter.direction)
end
return require("luasnip").in_snippet()
end,
jump = function(direction)
require("luasnip").jump(direction)
end,
},
if cmp.visible() then
cmp.select_next_item({ behavior = "select" })
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
elseif col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then
fallback()
else
cmp.complete()
end
end, { "i", "s" }),

["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item({ behavior = "select" })
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),

-- Go to next placeholder in the snippet
["<C-l>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, { "i", "s" }),
-- Go to previous placeholder in the snippet
["<C-h>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = {
{ name = "luasnip", priority = 100, max_item_count = 5 },
{ name = "nvim_lsp", priority = 90 },
{ name = "path", priority = 20 },
{ name = "buffer", priority = 10, keyword_length = 3, max_item_count = 8 },
{ name = "nvim_lua" },
{ name = "nvim_lsp_signature_help" },
},
})

sources = {
default = { "lsp", "path", "luasnip", "buffer", "copilot", "codecompanion" },
providers = {
codecompanion = {
name = "CodeCompanion",
module = "codecompanion.providers.completion.blink",
},
copilot = {
name = "copilot",
module = "blink-cmp-copilot",
},
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" },
{
name = "cmdline",
option = {
ignore_cmds = { "Man", "!" },
},
},
}),
sorting = {
comparators = {
cmp.config.compare.offset,
cmp.config.compare.exact,
cmp.config.compare.score,
cmp.config.compare.recently_used,
require("cmp-under-comparator").under,
cmp.config.compare.kind,
},
},
},
})

cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})
end,
},

-- LSP
{
"neovim/nvim-lspconfig",
dependencies = {
{ "hrsh7th/cmp-nvim-lsp" },
{
"williamboman/mason.nvim",
build = function()
Expand All @@ -79,21 +145,19 @@ return {
},
{ "williamboman/mason-lspconfig.nvim" },
},
config = function(_, opts)
config = function()
require("lspconfig.ui.windows").default_options.border = "single"
require("luasnip.loaders.from_vscode").lazy_load({ paths = { "~/.config/snippets" } })
vim.o.runtimepath = vim.o.runtimepath .. ",~/.dotfiles/.config/snippets"

require("ufo").setup()
local has_blink, blink = pcall(require, "blink.cmp")
local capabilities =
vim.tbl_deep_extend("force", has_blink and blink.get_lsp_capabilities() or {}, opts.capabilities or {}, {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
},
local capabilities = vim.tbl_deep_extend("force", require("cmp_nvim_lsp").default_capabilities(), {
textDocument = {
foldingRange = {
dynamicRegistration = false,
lineFoldingOnly = true,
},
})
},
})

local lspconfig_defaults = require("lspconfig").util.default_config
lspconfig_defaults.capabilities = vim.tbl_deep_extend("force", lspconfig_defaults.capabilities, capabilities)
Expand Down Expand Up @@ -339,6 +403,10 @@ return {
end,
},

-- Code snippets
"L3MON4D3/LuaSnip",
"rafamadriz/friendly-snippets",

-- Diagnostic signs
{
"ivanjermakov/troublesum.nvim",
Expand Down

0 comments on commit 6752a51

Please sign in to comment.