General completion/snips setup
configure - nvim-cmp - luasnips - nvim-treesitter
This commit is contained in:
parent
9425ad853e
commit
962d7f6971
90
after/plugin/completion.lua
Normal file
90
after/plugin/completion.lua
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
-- Configure Completion
|
||||||
|
|
||||||
|
vim.opt.completeopt = {"menu","menuone","noselect"}
|
||||||
|
vim.opt.shortmess:append "c"
|
||||||
|
|
||||||
|
local ok, lspkind = pcall(require, "lspkind")
|
||||||
|
if not ok then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
lspkind.init()
|
||||||
|
|
||||||
|
local luasnip = require("luasnip")
|
||||||
|
local cmp = require("cmp")
|
||||||
|
|
||||||
|
local has_words_before = function()
|
||||||
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
cmp.setup {
|
||||||
|
mapping = {
|
||||||
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item()
|
||||||
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
luasnip.expand_or_jump()
|
||||||
|
elseif has_words_before() then
|
||||||
|
cmp.complete()
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
|
||||||
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
["<C-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
|
||||||
|
["<C-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
|
||||||
|
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||||||
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||||
|
["<CR>"] = cmp.mapping(
|
||||||
|
cmp.mapping.confirm {
|
||||||
|
behavior = cmp.ConfirmBehavior.Insert,
|
||||||
|
select = true,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
sources = {
|
||||||
|
{name = "nvim_lua"},
|
||||||
|
{name = "nvim_lsp"},
|
||||||
|
{name = "path"},
|
||||||
|
{name = "luasnip"},
|
||||||
|
{
|
||||||
|
name = "buffer",
|
||||||
|
option = {
|
||||||
|
keyword_length = 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
require("luasnip").lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
experimental = {
|
||||||
|
native_menu = false,
|
||||||
|
ghost_text = true,
|
||||||
|
},
|
||||||
|
formatting = {
|
||||||
|
format = lspkind.cmp_format {
|
||||||
|
mode = 'symbol_text',
|
||||||
|
menu = {
|
||||||
|
buffer = "[BUF]",
|
||||||
|
nvim_lsp = "[LSP]",
|
||||||
|
nvim_lua = "[API]",
|
||||||
|
path = "[PTH]",
|
||||||
|
luasnip = "[SNP]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
21
after/plugin/luasnips.lua
Normal file
21
after/plugin/luasnips.lua
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
if not pcall(require,"luasnip") then
|
||||||
|
print("NO SNIPS?")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local ls = require "luasnip"
|
||||||
|
-- local types = require "luasnip.util.types"
|
||||||
|
|
||||||
|
|
||||||
|
ls.config.set_config{
|
||||||
|
|
||||||
|
-- remember the last snippet
|
||||||
|
history = true,
|
||||||
|
|
||||||
|
-- make dynamic snippets update with typing
|
||||||
|
updateevents = "TextChanged,TextChangedI",
|
||||||
|
|
||||||
|
--Autosnippets:
|
||||||
|
enable_autosnippets = true,
|
||||||
|
}
|
||||||
|
require("luasnip/loaders/from_vscode").load()
|
||||||
30
after/plugin/treesitter.lua
Normal file
30
after/plugin/treesitter.lua
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
if not pcall(require, "nvim-treesitter") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
require'nvim-treesitter.configs'.setup {
|
||||||
|
-- A list of parser names, or "all"
|
||||||
|
ensure_installed = { "c", "lua", "rust", "c_sharp", "markdown", "latex" },
|
||||||
|
|
||||||
|
-- Install parsers synchronously (only applied to `ensure_installed`)
|
||||||
|
sync_install = false,
|
||||||
|
|
||||||
|
highlight = {
|
||||||
|
-- `false` will disable the whole extension
|
||||||
|
enable = true,
|
||||||
|
|
||||||
|
-- Setting this to true will run `:h syntax` and tree-sitter at the same
|
||||||
|
-- time. Set this to `true` if you depend on 'syntax' being enabled (like
|
||||||
|
-- for indentation). Using this option may slow down your editor, and you
|
||||||
|
-- may see some duplicate highlights. Instead of true it can also be a list
|
||||||
|
-- of languages
|
||||||
|
additional_vim_regex_highlighting = false,
|
||||||
|
},
|
||||||
|
|
||||||
|
rainbow = {
|
||||||
|
enable = true,
|
||||||
|
extended_mode = true,
|
||||||
|
max_file_lines = nil,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user