Update .config/nvim/lua/plugins/lsp.lua
This commit is contained in:
parent
193b1ce675
commit
4627e18006
1 changed files with 22 additions and 18 deletions
|
@ -36,17 +36,16 @@ return {
|
||||||
},
|
},
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
local cmp = require "cmp"
|
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
|
||||||
|
|
||||||
-- Setup cmp with options
|
-- Setup cmp with options
|
||||||
opts.snippet = {
|
opts.snippet = {
|
||||||
-- REQUIRED - you must specify a snippet engine
|
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
-- Uncomment and use the snippet engine you prefer:
|
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
||||||
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
|
|
||||||
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
|
||||||
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
|
|
||||||
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
|
|
||||||
vim.snippet.expand(args.body) -- For native Neovim snippets (Neovim v0.10+)
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,15 +54,27 @@ return {
|
||||||
['<C-f>'] = 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.abort(),
|
['<C-e>'] = cmp.mapping.abort(),
|
||||||
['<tab>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
['<tab>'] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item()
|
||||||
|
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()
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
})
|
})
|
||||||
|
|
||||||
opts.sources = cmp.config.sources({
|
opts.sources = cmp.config.sources({
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
{ name = 'vsnip' }, -- For vsnip users.
|
{ name = 'vsnip' }, -- For vsnip users.
|
||||||
-- { name = 'luasnip' }, -- For luasnip users.
|
|
||||||
-- { name = 'ultisnips' }, -- For ultisnips users.
|
|
||||||
-- { name = 'snippy' }, -- For snippy users.
|
|
||||||
}, {
|
}, {
|
||||||
{ name = 'buffer' },
|
{ name = 'buffer' },
|
||||||
{ name = 'nvim_lsp_signature_help' }
|
{ name = 'nvim_lsp_signature_help' }
|
||||||
|
@ -71,13 +82,6 @@ return {
|
||||||
|
|
||||||
return opts
|
return opts
|
||||||
end,
|
end,
|
||||||
keys = {
|
|
||||||
{ "<C-b>", function() require('cmp').mapping.scroll_docs(-4) end, mode = "i", desc = "Scroll docs up" },
|
|
||||||
{ "<C-f>", function() require('cmp').mapping.scroll_docs(4) end, mode = "i", desc = "Scroll docs down" },
|
|
||||||
{ "<C-Space>", function() require('cmp').mapping.complete() end, mode = "i", desc = "Trigger completion" },
|
|
||||||
{ "<C-e>", function() require('cmp').mapping.abort() end, mode = "i", desc = "Abort completion" },
|
|
||||||
{ "<Tab>", function() require('cmp').mapping.confirm({ select = true }) end, mode = "i", desc = "Confirm selection" },
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'numToStr/Comment.nvim',
|
'numToStr/Comment.nvim',
|
||||||
|
|
Loading…
Reference in a new issue