Major neovim updates (mostly completion-related)

This commit is contained in:
PowerUser64 2021-09-06 17:56:58 -07:00
parent b01adf63d1
commit 8f9fcd34e2
4 changed files with 211 additions and 101 deletions

View file

@ -1,14 +1,13 @@
local M = {}
-- lsp_signature
M.signature = function()
M.signature = function() ---- lsp_signature >>>
cfg = {
Gse_lspsaga = true
}
end
-- <<<
-- lspinstall
M.lspinstall = function()
M.lspinstall = function() ---- lspinstall >>>
local function setup_servers()
require'lspinstall'.setup()
local servers = require'lspinstall'.installed_servers()
@ -25,77 +24,152 @@ M.lspinstall = function()
vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
end
end
-- <<<
-- treesitter
M.treesitter = function ()
require'nvim-treesitter.configs'.setup {
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
--ignore_install = { "javascript", "java" }, -- List of parsers to ignore installing
M.treesitter = function () ---- treesitter >>>
require('nvim-treesitter.configs').setup {
highlight = {
enable = true, -- false will disable the whole extension
-- disable = { "c", "rust" }, -- list of language that will be disabled
-- 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,
enable = true, -- false will disable the whole extension
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = 'gnn',
node_incremental = 'grn',
scope_incremental = 'grc',
node_decremental = 'grm',
},
},
indent = {
enable = true
}
enable = true,
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
},
}
-- require'nvim-treesitter.configs'.setup {
-- ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
-- --ignore_install = { "javascript", "java" }, -- List of parsers to ignore installing
-- highlight = {
-- enable = true, -- false will disable the whole extension
-- -- disable = { "c", "rust" }, -- list of language that will be disabled
-- -- 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,
-- },
-- indent = {
-- enable = true
-- }
-- }
end
-- <<<
M.cmp = function() ---- cmp >>>
-- nvim-cmp supports additional completion capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<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 vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n')
elseif luasnip.expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n')
elseif luasnip.jumpable(-1) then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '')
else
fallback()
end
end,
},
sources = {
{ name = 'path' },
{ name = 'buffer' },
{ name = 'calc' },
{ name = 'vsnip' },
{ name = 'nvim_lsp' },
{ name = 'spell' },
{ name = 'treesitter' },
{ name = 'emoji' },
},
formatting = {
format = function(entry, vim_item)
-- fancy icons and a name of kind
vim_item.kind = require("lspkind").presets.default[vim_item.kind] .. " " .. vim_item.kind
-- set a name for each source
vim_item.menu = ({
buffer = "[Buffer]",
nvim_lsp = "[LSP]",
luasnip = "[LuaSnip]",
nvim_lua = "[Lua]",
latex_symbols = "[Latex]",
})[entry.source.name]
return vim_item
end,
},
}
end
-- <<<
-- lspkind
M.lspkind = function()
require('lspkind').init({
-- enables text annotations
--
-- default: true
with_text = true,
-- default symbol map
-- can be either 'default' (requires nerd-fonts font) or
-- 'codicons' for codicon preset (requires vscode-codicons font)
--
-- default: 'default'
preset = 'codicons',
-- override preset symbols
--
-- default: {}
symbol_map = {
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 = ""
},
})
end
-- lspconfig
M.lspconfig = function()
M.lspconfig = function() ---- lspconfig >>>
local nvim_lsp = require('lspconfig')
-- Use an on_attach function to only map the following keys
@ -133,7 +207,7 @@ M.lspconfig = function()
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pyright', 'rust_analyzer', 'tsserver' }
local servers = { 'clangd', 'bash' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
@ -143,8 +217,9 @@ M.lspconfig = function()
}
end
end
-- <<<
return M
-- vim:expandtab:tabstop=3:sw=3
-- vim:fdm=marker:fmr=>>>,<<<:expandtab:tabstop=3:sw=3