move nvim-cmp setup to comp.lua
This commit is contained in:
@@ -152,6 +152,7 @@ require("user.file-tree")
|
|||||||
require("user.treesitter")
|
require("user.treesitter")
|
||||||
require("user.telescope")
|
require("user.telescope")
|
||||||
require("user.git")
|
require("user.git")
|
||||||
|
require("user.comp")
|
||||||
require("user.lsp")
|
require("user.lsp")
|
||||||
require("user.comment")
|
require("user.comment")
|
||||||
require("user.snippets")
|
require("user.snippets")
|
||||||
|
|||||||
109
neovim/.config/nvim/lua/user/comp.lua
Normal file
109
neovim/.config/nvim/lua/user/comp.lua
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
local cmp = require("cmp")
|
||||||
|
|
||||||
|
local kind_icons = {
|
||||||
|
Text = "",
|
||||||
|
Method = "",
|
||||||
|
Function = "",
|
||||||
|
Constructor = "",
|
||||||
|
Field = "",
|
||||||
|
Variable = "",
|
||||||
|
Class = "ﴯ",
|
||||||
|
Interface = "",
|
||||||
|
Module = "",
|
||||||
|
Property = "ﰠ",
|
||||||
|
Unit = "",
|
||||||
|
Value = "",
|
||||||
|
Enum = "",
|
||||||
|
Keyword = "",
|
||||||
|
Snippet = "",
|
||||||
|
Color = "",
|
||||||
|
File = "",
|
||||||
|
Reference = "",
|
||||||
|
Folder = "",
|
||||||
|
EnumMember = "",
|
||||||
|
Constant = "",
|
||||||
|
Struct = "",
|
||||||
|
Event = "",
|
||||||
|
Operator = "",
|
||||||
|
TypeParameter = "",
|
||||||
|
}
|
||||||
|
|
||||||
|
local completion_trigger = "<C-space>"
|
||||||
|
if vim.fn.has("win32") == 1 then
|
||||||
|
completion_trigger = "<C-y>"
|
||||||
|
end
|
||||||
|
|
||||||
|
cmp.setup({
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
require("luasnip").lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
mapping = {
|
||||||
|
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
|
||||||
|
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
|
||||||
|
[completion_trigger] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.close()
|
||||||
|
else
|
||||||
|
cmp.complete()
|
||||||
|
end
|
||||||
|
end),
|
||||||
|
["<TAB>"] = cmp.mapping.confirm({
|
||||||
|
select = true,
|
||||||
|
behavior = cmp.SelectBehavior.Insert,
|
||||||
|
}),
|
||||||
|
["<A-j>"] = cmp.mapping.scroll_docs(4),
|
||||||
|
["<A-k>"] = cmp.mapping.scroll_docs(-4),
|
||||||
|
},
|
||||||
|
sources = cmp.config.sources({
|
||||||
|
{ name = "nvim_lsp" },
|
||||||
|
{ name = "luasnip" },
|
||||||
|
}, {
|
||||||
|
{ name = "path" },
|
||||||
|
{ name = "buffer" },
|
||||||
|
}),
|
||||||
|
completion = {
|
||||||
|
completeopt = "menu,menuone,noselect,noinsert,preview",
|
||||||
|
},
|
||||||
|
experimental = {
|
||||||
|
ghost_text = true,
|
||||||
|
},
|
||||||
|
sorting = {
|
||||||
|
comparators = {
|
||||||
|
cmp.config.compare.score,
|
||||||
|
cmp.config.compare.sort_text,
|
||||||
|
cmp.config.compare.kind,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
documentation = {
|
||||||
|
border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
|
||||||
|
zindex = 999,
|
||||||
|
format = { "markdown" },
|
||||||
|
},
|
||||||
|
formatting = {
|
||||||
|
format = function(entry, vim_item)
|
||||||
|
vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind)
|
||||||
|
vim_item.menu = ({
|
||||||
|
buffer = "[Buffer]",
|
||||||
|
luasnip = "[Snippet]",
|
||||||
|
nvim_lua = "[Lua]",
|
||||||
|
path = "[File]",
|
||||||
|
})[entry.source.name]
|
||||||
|
|
||||||
|
return vim_item
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
cmp.setup.cmdline("/", {
|
||||||
|
sources = {
|
||||||
|
{ name = "cmdline" },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
cmp.setup.cmdline(":", {
|
||||||
|
sources = {
|
||||||
|
{ name = "cmdline" },
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -1,36 +1,7 @@
|
|||||||
local lsp_installer = require("nvim-lsp-installer")
|
local lsp_installer = require("nvim-lsp-installer")
|
||||||
local cmp = require("cmp")
|
|
||||||
local null_ls = require("null-ls")
|
local null_ls = require("null-ls")
|
||||||
local util = require("lspconfig").util
|
local util = require("lspconfig").util
|
||||||
|
|
||||||
local kind_icons = {
|
|
||||||
Text = "",
|
|
||||||
Method = "",
|
|
||||||
Function = "",
|
|
||||||
Constructor = "",
|
|
||||||
Field = "",
|
|
||||||
Variable = "",
|
|
||||||
Class = "ﴯ",
|
|
||||||
Interface = "",
|
|
||||||
Module = "",
|
|
||||||
Property = "ﰠ",
|
|
||||||
Unit = "",
|
|
||||||
Value = "",
|
|
||||||
Enum = "",
|
|
||||||
Keyword = "",
|
|
||||||
Snippet = "",
|
|
||||||
Color = "",
|
|
||||||
File = "",
|
|
||||||
Reference = "",
|
|
||||||
Folder = "",
|
|
||||||
EnumMember = "",
|
|
||||||
Constant = "",
|
|
||||||
Struct = "",
|
|
||||||
Event = "",
|
|
||||||
Operator = "",
|
|
||||||
TypeParameter = "",
|
|
||||||
}
|
|
||||||
|
|
||||||
local formatting = null_ls.builtins.formatting
|
local formatting = null_ls.builtins.formatting
|
||||||
local diagnostics = null_ls.builtins.diagnostics
|
local diagnostics = null_ls.builtins.diagnostics
|
||||||
|
|
||||||
@@ -61,86 +32,6 @@ vim.api.nvim_create_autocmd("BufWritePre", {
|
|||||||
callback = vim.lsp.buf.formatting_sync,
|
callback = vim.lsp.buf.formatting_sync,
|
||||||
})
|
})
|
||||||
|
|
||||||
local completion_trigger = "<C-space>"
|
|
||||||
if vim.fn.has("win32") == 1 then
|
|
||||||
completion_trigger = "<C-y>"
|
|
||||||
end
|
|
||||||
|
|
||||||
cmp.setup({
|
|
||||||
snippet = {
|
|
||||||
expand = function(args)
|
|
||||||
require("luasnip").lsp_expand(args.body)
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
mapping = {
|
|
||||||
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
|
|
||||||
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
|
|
||||||
[completion_trigger] = cmp.mapping(function(fallback)
|
|
||||||
if cmp.visible() then
|
|
||||||
cmp.close()
|
|
||||||
else
|
|
||||||
cmp.complete()
|
|
||||||
end
|
|
||||||
end),
|
|
||||||
["<TAB>"] = cmp.mapping.confirm({
|
|
||||||
select = true,
|
|
||||||
behavior = cmp.SelectBehavior.Insert,
|
|
||||||
}),
|
|
||||||
["<A-j>"] = cmp.mapping.scroll_docs(4),
|
|
||||||
["<A-k>"] = cmp.mapping.scroll_docs(-4),
|
|
||||||
},
|
|
||||||
sources = cmp.config.sources({
|
|
||||||
{ name = "nvim_lsp" },
|
|
||||||
{ name = "luasnip" },
|
|
||||||
}, {
|
|
||||||
{ name = "path" },
|
|
||||||
{ name = "buffer" },
|
|
||||||
}),
|
|
||||||
completion = {
|
|
||||||
completeopt = "menu,menuone,noselect,noinsert,preview",
|
|
||||||
},
|
|
||||||
experimental = {
|
|
||||||
ghost_text = true,
|
|
||||||
},
|
|
||||||
sorting = {
|
|
||||||
comparators = {
|
|
||||||
cmp.config.compare.score,
|
|
||||||
cmp.config.compare.sort_text,
|
|
||||||
cmp.config.compare.kind,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
documentation = {
|
|
||||||
border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
|
|
||||||
zindex = 999,
|
|
||||||
format = { "markdown" },
|
|
||||||
},
|
|
||||||
formatting = {
|
|
||||||
format = function(entry, vim_item)
|
|
||||||
vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind)
|
|
||||||
vim_item.menu = ({
|
|
||||||
buffer = "[Buffer]",
|
|
||||||
luasnip = "[Snippet]",
|
|
||||||
nvim_lua = "[Lua]",
|
|
||||||
path = "[File]",
|
|
||||||
})[entry.source.name]
|
|
||||||
|
|
||||||
return vim_item
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.cmdline("/", {
|
|
||||||
sources = {
|
|
||||||
{ name = "cmdline" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
cmp.setup.cmdline(":", {
|
|
||||||
sources = {
|
|
||||||
{ name = "cmdline" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user