2021-09-03 01:18:44 -07:00
|
|
|
local M = {}
|
|
|
|
|
2021-09-15 21:42:31 -07:00
|
|
|
-- lsp_signature >>>
|
|
|
|
M.signature = function()
|
2021-09-03 01:18:44 -07:00
|
|
|
cfg = {
|
2021-10-27 04:40:14 -07:00
|
|
|
toggle_key = '<M-x>'
|
2021-09-03 01:18:44 -07:00
|
|
|
}
|
2021-10-27 04:40:14 -07:00
|
|
|
require "lsp_signature".setup(cfg)
|
2021-09-15 21:42:31 -07:00
|
|
|
end -- <<<
|
2021-09-03 01:18:44 -07:00
|
|
|
|
2021-09-15 21:42:31 -07:00
|
|
|
-- lspinstall >>>
|
|
|
|
M.lspinstall = function() --
|
2021-09-03 01:18:44 -07:00
|
|
|
local function setup_servers()
|
|
|
|
require'lspinstall'.setup()
|
|
|
|
local servers = require'lspinstall'.installed_servers()
|
|
|
|
for _, server in pairs(servers) do
|
|
|
|
require'lspconfig'[server].setup{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
setup_servers()
|
|
|
|
-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
|
|
|
|
require'lspinstall'.post_install_hook = function ()
|
|
|
|
setup_servers() -- reload installed servers
|
|
|
|
vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
|
|
|
|
end
|
2021-09-15 21:42:31 -07:00
|
|
|
end -- <<<
|
2021-09-03 01:18:44 -07:00
|
|
|
|
2021-09-15 21:42:31 -07:00
|
|
|
-- treesitter >>>
|
|
|
|
M.treesitter = function()
|
2021-09-25 02:19:19 -07:00
|
|
|
require'nvim-treesitter.configs'.setup {
|
|
|
|
-- install the necessary parsers
|
|
|
|
ensure_installed = {
|
|
|
|
"bash",
|
|
|
|
"c",
|
|
|
|
"cmake",
|
|
|
|
"comment",
|
|
|
|
"cpp",
|
|
|
|
"css",
|
|
|
|
"dockerfile",
|
|
|
|
"html",
|
|
|
|
"javascript",
|
|
|
|
"json",
|
2021-12-04 03:18:58 -08:00
|
|
|
"jsonc",
|
2021-09-25 02:19:19 -07:00
|
|
|
"lua",
|
|
|
|
"python",
|
|
|
|
"r",
|
|
|
|
"regex",
|
|
|
|
"rst",
|
|
|
|
"rust",
|
|
|
|
"toml",
|
|
|
|
"vim",
|
|
|
|
},
|
|
|
|
--ignore_install = { "javascript", "java" }, -- List of parsers to ignore installing
|
2021-09-03 01:18:44 -07:00
|
|
|
highlight = {
|
2021-09-06 17:56:58 -07:00
|
|
|
enable = true, -- false will disable the whole extension
|
|
|
|
},
|
2021-09-25 02:19:19 -07:00
|
|
|
indent = {
|
|
|
|
enable = true
|
|
|
|
},
|
2021-09-06 17:56:58 -07:00
|
|
|
incremental_selection = {
|
|
|
|
enable = true,
|
|
|
|
keymaps = {
|
|
|
|
init_selection = 'gnn',
|
|
|
|
node_incremental = 'grn',
|
|
|
|
scope_incremental = 'grc',
|
|
|
|
node_decremental = 'grm',
|
|
|
|
},
|
2021-09-03 01:18:44 -07:00
|
|
|
},
|
2021-09-06 17:56:58 -07:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-09-03 01:18:44 -07:00
|
|
|
}
|
2021-09-15 21:42:31 -07:00
|
|
|
end -- <<<
|
2021-09-06 17:56:58 -07:00
|
|
|
|
2021-09-15 21:42:31 -07:00
|
|
|
-- cmp >>>
|
|
|
|
M.cmp = function()
|
2021-09-10 02:45:00 -07:00
|
|
|
-- nvim-cmp supports additional completion capabilities
|
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
2021-09-10 01:40:44 -07:00
|
|
|
-- nvim-cmp setup
|
2021-09-06 17:56:58 -07:00
|
|
|
local cmp = require 'cmp'
|
|
|
|
cmp.setup {
|
|
|
|
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,
|
2021-09-21 01:18:10 -07:00
|
|
|
select = false,
|
2021-09-06 17:56:58 -07:00
|
|
|
},
|
2021-11-25 04:30:58 -08:00
|
|
|
['<CR>'] = cmp.mapping.confirm {
|
|
|
|
behavior = cmp.ConfirmBehavior.Replace,
|
|
|
|
-- select = true,
|
|
|
|
},
|
2021-09-06 17:56:58 -07:00
|
|
|
['<Tab>'] = function(fallback)
|
2021-10-14 03:37:07 -07:00
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_next_item()
|
2021-09-06 17:56:58 -07:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
['<S-Tab>'] = function(fallback)
|
2021-10-14 03:37:07 -07:00
|
|
|
if cmp.visible() then
|
|
|
|
cmp.select_prev_item()
|
2021-09-06 17:56:58 -07:00
|
|
|
else
|
|
|
|
fallback()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
sources = {
|
|
|
|
{ name = 'path' },
|
2021-11-25 04:30:58 -08:00
|
|
|
{ name = 'nvim_lua' },
|
2021-11-22 01:12:19 -08:00
|
|
|
{ name = 'nvim_lsp' },
|
2021-11-25 05:16:30 -08:00
|
|
|
{ name = 'treesitter' },
|
2021-09-06 17:56:58 -07:00
|
|
|
{ name = 'calc' },
|
2021-12-07 15:20:36 -08:00
|
|
|
-- { name = 'spell' },
|
2021-11-25 04:30:58 -08:00
|
|
|
{ name = 'buffer' },
|
2021-11-25 05:16:30 -08:00
|
|
|
{ name = 'cmdline' },
|
2021-09-06 17:56:58 -07:00
|
|
|
{ name = 'emoji' },
|
2021-09-03 01:18:44 -07:00
|
|
|
},
|
2021-11-25 05:16:30 -08:00
|
|
|
cmp.setup.cmdline('/', {
|
|
|
|
sources = {
|
|
|
|
{ name = 'buffer' }
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
cmp.setup.cmdline(':', {
|
|
|
|
sources = cmp.config.sources({
|
|
|
|
{ name = 'path' }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{ name = 'cmdline' }
|
|
|
|
})
|
|
|
|
}),
|
2021-09-06 17:56:58 -07:00
|
|
|
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 = ({
|
2021-10-14 03:37:07 -07:00
|
|
|
path = "[Path]",
|
2021-11-25 04:30:58 -08:00
|
|
|
nvim_lua = "[Lua]",
|
2021-11-22 01:12:19 -08:00
|
|
|
nvim_lsp = "[LSP]",
|
2021-11-25 05:16:30 -08:00
|
|
|
treesitter = "[TS]",
|
2021-10-14 03:37:07 -07:00
|
|
|
calc = "[Calc]",
|
|
|
|
spell = "[Spell]",
|
2021-11-25 05:16:30 -08:00
|
|
|
cmdline = "[cmdline]",
|
2021-11-25 04:30:58 -08:00
|
|
|
buffer = "[Buffer]",
|
2021-09-06 17:56:58 -07:00
|
|
|
})[entry.source.name]
|
|
|
|
return vim_item
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
}
|
2021-09-15 21:42:31 -07:00
|
|
|
end -- <<<
|
2021-09-03 01:18:44 -07:00
|
|
|
|
2021-09-15 21:42:31 -07:00
|
|
|
-- lspconfig >>>
|
|
|
|
M.lspconfig = function()
|
2021-09-03 01:18:44 -07:00
|
|
|
local nvim_lsp = require('lspconfig')
|
2021-11-03 00:52:59 -07:00
|
|
|
-- Keybinds for servers >>>
|
2021-09-03 01:18:44 -07:00
|
|
|
-- Use an on_attach function to only map the following keys
|
|
|
|
-- after the language server attaches to the current buffer
|
|
|
|
local on_attach = function(client, bufnr)
|
|
|
|
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
|
|
|
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
|
|
|
|
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
|
|
|
|
-- Mappings.
|
|
|
|
local opts = { noremap=true, silent=true }
|
|
|
|
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
2021-09-16 02:17:07 -07:00
|
|
|
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
|
|
|
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
|
|
|
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
|
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
|
|
|
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
|
|
|
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
|
|
|
buf_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
2021-11-03 00:52:59 -07:00
|
|
|
end -- <<<
|
2021-11-25 05:16:30 -08:00
|
|
|
local capabilities
|
|
|
|
if cmp ~= nil then -- only load this if cmp is loaded
|
|
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
|
|
|
end
|
|
|
|
|
2021-11-03 00:52:59 -07:00
|
|
|
-- Load servers >>>
|
2021-09-03 01:18:44 -07:00
|
|
|
-- Use a loop to conveniently call 'setup' on multiple servers and
|
|
|
|
-- map buffer local keybindings when the language server attaches
|
2021-09-22 03:19:20 -07:00
|
|
|
local lsp_servers = {
|
2021-12-07 15:20:36 -08:00
|
|
|
-- <lsp_name> = '<lsp_executable_name> (needs to be in path)',
|
2021-09-27 19:21:36 -07:00
|
|
|
clangd = 'clangd',
|
|
|
|
html = 'vscode-html-language-server',
|
|
|
|
bashls = 'bash-language-server',
|
2021-11-30 01:54:20 -08:00
|
|
|
rust_analyzer = 'rust-analyzer',
|
2021-12-07 15:20:36 -08:00
|
|
|
dockerls = 'docker-langserver',
|
2021-09-22 03:19:20 -07:00
|
|
|
}
|
|
|
|
for lsp, exe in pairs(lsp_servers) do
|
2021-11-20 21:02:54 -08:00
|
|
|
if (vim.fn.executable(exe) == 1) then
|
2021-09-22 03:19:20 -07:00
|
|
|
nvim_lsp[lsp].setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
flags = {
|
|
|
|
debounce_text_changes = 150,
|
|
|
|
}
|
2021-09-03 01:18:44 -07:00
|
|
|
}
|
2021-09-22 03:19:20 -07:00
|
|
|
end
|
2021-09-03 01:18:44 -07:00
|
|
|
end
|
2021-11-19 18:16:17 -08:00
|
|
|
-- Custom servers
|
2021-11-03 00:52:59 -07:00
|
|
|
-- lua >>>
|
|
|
|
local sumneko_root_path
|
|
|
|
local sumneko_binary
|
|
|
|
if (vim.fn.exepath('lua-language-server') ~= '') then
|
|
|
|
-- If you installed this with your package manager
|
|
|
|
sumneko_root_path = '/usr/lib/lua-language-server/bin/Linux'
|
|
|
|
sumneko_binary = vim.fn.exepath('lua-language-server')
|
|
|
|
else
|
|
|
|
-- If you installed this with lspinstall
|
|
|
|
sumneko_root_path = vim.fn.getenv 'HOME' .. '/.local/share/nvim/lspinstall/lua/sumneko-lua/extension/server'
|
|
|
|
sumneko_binary = sumneko_root_path .. '/lua-language-server'
|
|
|
|
end
|
|
|
|
|
2021-11-15 21:44:52 -08:00
|
|
|
-- From kickstart.nvim:
|
2021-11-25 04:30:58 -08:00
|
|
|
if (vim.fn.executable(sumneko_binary) == 1) then
|
2021-11-15 21:44:52 -08:00
|
|
|
-- Make runtime files discoverable to the server
|
|
|
|
local runtime_path = vim.split(package.path, ';')
|
|
|
|
table.insert(runtime_path, 'lua/?.lua')
|
|
|
|
table.insert(runtime_path, 'lua/?/init.lua')
|
2021-12-03 01:03:00 -08:00
|
|
|
|
2021-11-15 21:44:52 -08:00
|
|
|
require('lspconfig').sumneko_lua.setup {
|
|
|
|
cmd = { sumneko_binary, '-E', sumneko_root_path .. '/main.lua' },
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
|
|
|
version = 'LuaJIT',
|
|
|
|
-- Setup your lua path
|
|
|
|
path = runtime_path,
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
-- Get the language server to recognize the `vim` global
|
|
|
|
globals = { 'vim' },
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
library = vim.api.nvim_get_runtime_file('', true),
|
|
|
|
},
|
|
|
|
-- Do not send telemetry data containing a randomized but unique identifier
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
2021-11-03 00:52:59 -07:00
|
|
|
},
|
|
|
|
},
|
2021-11-15 21:44:52 -08:00
|
|
|
}
|
|
|
|
end
|
2021-11-03 00:52:59 -07:00
|
|
|
-- lua <<<
|
|
|
|
-- Load servers <<<
|
2021-09-15 21:42:31 -07:00
|
|
|
end -- <<<
|
|
|
|
|
2021-09-03 01:18:44 -07:00
|
|
|
return M
|
|
|
|
|
2021-09-06 17:56:58 -07:00
|
|
|
-- vim:fdm=marker:fmr=>>>,<<<:expandtab:tabstop=3:sw=3
|
2021-09-03 01:18:44 -07:00
|
|
|
|