neovim: add lspconfig, move compe config

This commit is contained in:
FollieHiyuki 2021-07-12 04:20:58 +03:00
parent e6e5b3149f
commit 5ab3184378
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
8 changed files with 297 additions and 104 deletions

View File

@ -67,9 +67,24 @@ wk.register({
},
-- Naming common keys
['['] = {name = 'Block motions (previous)'},
[']'] = {name = 'Block motions (next)'},
g = {name = 'Goto motions'},
['['] = {
name = 'Block motions (previous)',
d = 'Previous diagnostics',
g = 'Previous git hunk'
},
[']'] = {
name = 'Block motions (next)',
d = 'Next diagnostics',
g = 'Next git hunk'
},
g = {
name = 'Goto motions',
d = 'Go to definition',
D = 'Go to declaration',
i = 'Go to implementation',
r = 'Go to references'
},
K = {name = 'Hover'},
z = {name = 'Misc utils'},
-- Don't need to show bufferline numbers
@ -119,8 +134,9 @@ wk.register({
j = {':Telescope symbols<CR>', 'Pick emojis'},
k = {':Telescope keymaps<CR>', 'Normal keymaps'},
m = {':Telescope marks<CR>', 'Bookmarks'},
n = {':Telescope man_pages<CR>', 'Man pages'},
o = {':Telescope oldfiles<CR>', 'Recent files'},
p = {':Telescope man_pages<CR>', 'Man pages'},
p = {':Telescope project display_type=full<CR>', 'Projects'},
r = {':Telescope reloader<CR>', 'Reload lua modules'},
s = {':Telescope treesitter<CR>', 'Treesitter'},
t = {':Telescope<CR>', 'Telescope'},
@ -131,15 +147,35 @@ wk.register({
},
l = {
name = 'LSP'
name = 'LSP',
a = 'Add workspace folder',
d = 'Type definition',
e = 'Line diagnostics',
l = 'List workspace folders',
n = 'Rename in buffer',
o = 'Format buffer',
q = 'Set diagnostics loclist',
r = 'Remove workspace folder',
s = 'Signature help',
f = {
name = 'Telescope',
a = {':Telescope lsp_code_actions<CR>', 'Code actions'},
A = {':Telescope lsp_range_code_actions<CR>', 'Range code actions'},
d = {':Telescope lsp_document_diagnostics<CR>', 'Buffer diagnostics'},
D = {':Telescope lsp_workspace_diagnostics<CR>', 'Workspace diagnostics'},
e = {':Telescope lsp_dynamic_workspace_symbols<CR>', 'Dynamic workspace symbols'},
i = {':Telescope lsp_implementations<CR>', 'Implementations'},
n = {':Telescope lsp_definitions<CR>', 'Definitions'},
r = {':Telescope lsp_references<CR>', 'References'},
s = {':Telescope lsp_document_symbols<CR>', 'Buffer symbols'},
S = {':Telescope lsp_workspace_symbols<CR>', 'Workspace symbols'}
}
},
-- Git
g = {
name = 'Git',
b = 'Blame current line',
j = 'Next hunk',
k = 'Previous hunk',
p = 'Preview hunk',
r = 'Reset hunk',
R = 'Reset all hunks in buffer',
@ -176,54 +212,3 @@ wk.register({
s = 'Stage hunk'
}
}, {mode = 'v', prefix = '<leader>'})
----------------
-- nvim-compe --
----------------
-- Use (S-)Tab in completion menu
-- See https://github.com/L3MON4D3/Luasnip/issues/1#issuecomment-835241958
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local function prequire(...)
local status, lib = pcall(require, ...)
if (status) then return lib end
return nil
end
local luasnip = prequire('luasnip')
local check_back_space = function()
local col = vim.fn.col('.') - 1
return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
end
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t '<C-n>'
elseif luasnip and luasnip.expand_or_jumpable() then
return t '<Plug>luasnip-expand-or-jump'
elseif check_back_space() then
return t '<Tab>'
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t '<C-p>'
elseif luasnip and luasnip.jumpable(-1) then
return t '<Plug>luasnip-jump-prev'
else
return t '<S-Tab>'
end
end
vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.tab_complete()', {expr = true, noremap = true, silent = true})
vim.api.nvim_set_keymap('s', '<Tab>', 'v:lua.tab_complete()', {expr = true, noremap = true, silent = true})
vim.api.nvim_set_keymap('i', '<S-Tab>', 'v:lua.s_tab_complete()', {expr = true, noremap = true, silent = true})
vim.api.nvim_set_keymap('s', '<S-Tab>', 'v:lua.s_tab_complete()', {expr = true, noremap = true, silent = true})
vim.api.nvim_set_keymap('i', '<C-Space>', 'compe#complete()', {expr = true, noremap = true, silent = true})
vim.api.nvim_set_keymap('i', '<C-e>', 'compe#close(\'<C-e>\')', {expr = true, noremap = true, silent = true})

View File

@ -1,4 +1,4 @@
return require('compe').setup {
require('compe').setup {
enabled = true,
autocomplete = true,
debug = false,
@ -7,11 +7,57 @@ return require('compe').setup {
source = {
path = true,
buffer = true,
-- calc = true,
calc = false,
nvim_lsp = true,
nvim_lua = true,
nvim_lua = false,
vsnip = false,
luasnip = true,
-- tags = true,
utilsnips = false,
tags = false,
spell = true
}
}
-- Use (S-)Tab in completion menu
-- See https://github.com/neovim/nvim-lspconfig/wiki/Snippets
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col('.') - 1
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t '<C-n>'
elseif require('luasnip').expand_or_jumpable() then
return t '<Plug>luasnip-expand-or-jump'
elseif check_back_space() then
return t '<Tab>'
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t '<C-p>'
elseif require('luasnip').jumpable(-1) then
return t '<Plug>luasnip-jump-prev'
else
return t '<S-Tab>'
end
end
vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.tab_complete()', {expr = true})
vim.api.nvim_set_keymap('s', '<Tab>', 'v:lua.tab_complete()', {expr = true})
vim.api.nvim_set_keymap('i', '<S-Tab>', 'v:lua.s_tab_complete()', {expr = true})
vim.api.nvim_set_keymap('s', '<S-Tab>', 'v:lua.s_tab_complete()', {expr = true})
vim.api.nvim_set_keymap('i', '<C-Space>', 'compe#complete()', {expr = true})
vim.api.nvim_set_keymap('i', '<C-e>', 'compe#close(\'<C-e>\')', {expr = true})

View File

@ -12,8 +12,8 @@ return require('gitsigns').setup {
noremap = true,
buffer = true,
['n <leader>gj'] = {expr = true, '&diff ? \'<leader>gj\' : \'<cmd>lua require"gitsigns.actions".next_hunk()<CR>\''},
['n <leader>gk'] = {expr = true, '&diff ? \'<leader>gk\' : \'<cmd>lua require"gitsigns.actions".prev_hunk()<CR>\''},
['n ]g'] = {expr = true, '&diff ? \']g\' : \'<cmd>lua require"gitsigns.actions".next_hunk()<CR>\''},
['n [g'] = {expr = true, '&diff ? \'[g\' : \'<cmd>lua require"gitsigns.actions".prev_hunk()<CR>\''},
['n <leader>gs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
['v <leader>gs'] = '<cmd>lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',

View File

@ -0,0 +1,124 @@
local lspconf = require('lspconfig')
local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local opts = {noremap = true, silent = true}
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', '<leader>ls', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<leader>la', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>lr', '<Cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>ll', '<Cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<leader>ld', '<Cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<leader>ln', '<Cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', 'gr', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>le', '<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>lq', '<Cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
if client.resolved_capabilities.document_formatting then
buf_set_keymap('n', '<leader>lo', '<Cmd>lua vim.lsp.buf.formatting()<CR>', opts)
elseif client.resolved_capabilities.document_range_formatting then
buf_set_keymap('n', '<leader>lo', '<Cmd>lua vim.lsp.buf.range_formatting()<CR>', opts)
end
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
---------------------------
-- Server configurations --
---------------------------
-- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md
-- C/C++
lspconf.clangd.setup {
on_attach = on_attach,
capabilities = capabilities,
filetypes = {'c', 'cpp'},
cmd = {
'clangd',
'-j=2',
'--background-index',
'--clang-tidy',
'--completion-style=detailed',
'--pch-storage=memory',
'--header-insertion=iwyu',
'--header-insertion=decorators'
}
}
-- Lua
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, 'lua/?.lua')
table.insert(runtime_path, 'lua/?/init.lua')
lspconf.sumneko_lua.setup {
on_attach = on_attach,
cmd = {
vim.fn.stdpath('data') .. '/lsp/lua-language-server/bin/Linux/lua-language-server',
'-E',
vim.fn.stdpath('data') .. '/lsp/lua-language-server/main.lua'
},
settings = {
Lua = {
diagnostics = {
globals = {'vim'}
},
runtime = {
version = 'LuaJIT',
path = runtime_path
},
workspace = {
library = vim.api.nvim_get_runtime_file('', true),
maxPreload = 100000,
preloadFileSize = 100000
},
telemetry = {
enable = false
}
}
}
}
-- Go
lspconf.gopls.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = {'gopls', '--remote=auto'},
init_options = {
usePlaceholders = true,
completeUnimported = true
}
}
-- Others
local servers = {
'dockerls',
'bashls',
'pyright',
'tsserver',
'html',
'cmake',
'rust_analyzer'
}
for _, server in ipairs(servers) do
lspconf[server].setup {
on_attach = on_attach,
capabilities = capabilities
}
end
-- Replace the default lsp diagnostic letters with prettier symbols
-- vim.fn.sign_define('LspDiagnosticsSignError', {text = '', numhl = 'LspDiagnosticsDefaultError'})
-- vim.fn.sign_define('LspDiagnosticsSignWarning', {text = '', numhl = 'LspDiagnosticsDefaultWarning'})
-- vim.fn.sign_define('LspDiagnosticsSignInformation', {text = '', numhl = 'LspDiagnosticsDefaultInformation'})
-- vim.fn.sign_define('LspDiagnosticsSignHint', {text = '', numhl = 'LspDiagnosticsDefaultHint'})

View File

@ -25,6 +25,9 @@ local function telescope_setup()
}
},
extensions = {
project = {
base_dirs = {{'~/Code', max_depth = 2}}
},
fzf = {
fuzzy = true,
override_generic_sorter = false,
@ -33,7 +36,7 @@ local function telescope_setup()
}
}
}
require('telescope').load_extension('project')
require('telescope').load_extension('fzf')
end

View File

@ -10,7 +10,7 @@ end
vim.cmd [[packadd packer.nvim]]
return require('packer').startup(
function()
function(use)
use {'wbthomason/packer.nvim', opt = true}
-----------------
@ -66,7 +66,8 @@ return require('packer').startup(
use {
'lewis6991/gitsigns.nvim',
event = {'BufRead', 'BufNewFile'},
requires = 'nvim-lua/plenary.nvim',
wants = 'plenary.nvim',
requires = {{'nvim-lua/plenary.nvim', opt = true}},
config = function()
require('modules.gitgutter')
end
@ -118,12 +119,12 @@ return require('packer').startup(
---------
-- LSP --
---------
use { -- TODO: config + colors
use {
'neovim/nvim-lspconfig',
event = 'BufReadPre'
}
use { -- TODO: lua, python, clang
'kabouzeid/nvim-lspinstall'
event = 'BufReadPre',
config = function()
require('modules.lsp')
end
}
use {
'hrsh7th/nvim-compe',
@ -146,17 +147,25 @@ return require('packer').startup(
use {
'nvim-telescope/telescope.nvim',
cmd = 'Telescope',
wants = {
'popup.nvim',
'plenary.nvim',
'telescope-symbols.nvim',
'telescope-project.nvim',
'telescope-fzf-native.nvim'
},
requires = {
'nvim-lua/popup.nvim',
'nvim-lua/plenary.nvim',
'nvim-telescope/telescope-symbols.nvim',
{'nvim-telescope/telescope-fzf-native.nvim', run = 'make'}
{'nvim-lua/popup.nvim', opt = true},
{'nvim-lua/plenary.nvim', opt = true},
{'nvim-telescope/telescope-symbols.nvim', opt = true},
{'nvim-telescope/telescope-project.nvim', opt = true},
{'nvim-telescope/telescope-fzf-native.nvim', run = 'make', opt = true}
},
config = function()
require('modules.telescope-nvim')
end
}
use { -- TODO: colors + config + custom telescope menu
use { -- TODO: colors + config
'pwntester/octo.nvim',
cmd = 'Octo',
wants = 'telescope.nvim',
@ -167,9 +176,13 @@ return require('packer').startup(
use { -- TODO: config + colors
'TimUntersberger/neogit',
cmd = 'Neogit',
wants = {
'diffview.nvim',
'plenary.nvim'
},
requires = {
-- 'sindrets/diffview.nvim',
'nvim-lua/plenary.nvim'
{'nvim-lua/plenary.nvim', opt = true},
{'sindrets/diffview.nvim', opt = true}
}
}
use {
@ -199,6 +212,14 @@ return require('packer').startup(
})
end
}
use {
'machakann/vim-sandwich',
event = 'BufRead'
}
use {
'junegunn/vim-easy-align',
keys = 'ga'
}
use {
'terrortylor/nvim-comment',
keys = 'gc',
@ -208,7 +229,17 @@ return require('packer').startup(
}
use {
'windwp/nvim-ts-autotag',
ft = {'html', 'xml', 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'svelte', 'php'},
ft = {
'html',
'xml',
'javascript',
'javascriptreact',
'typescript',
'typescriptreact',
'vue',
'svelte',
'php'
},
wants = 'nvim-treesitter',
config = function()
require('nvim-treesitter.configs').setup {
@ -218,6 +249,10 @@ return require('packer').startup(
}
end
}
use {
'ahmedkhalf/lsp-rooter.nvim',
after = 'nvim-lspconfig'
}
use {
'iamcco/markdown-preview.nvim',
run = 'cd app && yarn install',
@ -238,10 +273,9 @@ return require('packer').startup(
require('modules.terminal')
end
}
-- Just for benchmarking
use {'tweekmonster/startuptime.vim', cmd = 'StartupTime'}
-- TODO: trouble.nvim, lspsaga, orgmode.nvim, lspkind, TrueZen/zen-mode, nvim-lint, vim-spectre, nvim-dap, lsp-rooter, hop.nvim, dial.nvim
-- TODO: trouble.nvim, lspsaga, orgmode.nvim, lspkind, TrueZen/zen-mode, nvim-lint, vim-spectre, nvim-dap, hop.nvim, dial.nvim, asynctasks.nvim
end
)

View File

@ -0,0 +1,23 @@
#!/bin/sh -e
current_path="$PWD"
luals_path="$HOME/.local/share/nvim/lsp/lua-language-server"
# Clone / Update
if [ -d "$luals_path" ]; then
cd $luals_path
git pull --rebase
else
git clone https://github.com/sumneko/lua-language-server.git $luals_path
fi
cd $luals_path
git submodule update --init --recursive
# Build
cd 3rd/luamake
./compile/install.sh
cd ../..
./3rd/luamake/luamake rebuild
cd $current_path

View File

@ -1,22 +0,0 @@
#!/bin/sh -e
# clone the repo
git clone https://github.com/sumneko/lua-language-server.git
cd lua-language-server
git submodule update --init --recursive
# build
# You need `ninja`
cd 3rd/luamake
ninja -f ninja/linux.ninja
cd ../..
./3rd/luamake/luamake rebuild
cd ../
# For coc.nvim
mkdir -pv ~/.local/share/nvim/lsp
cp -rf lua-language-server ~/.local/share/nvim/lsp/ && echo "copied 'lua-language-server' -> ~/.local/share/nvim/lsp/lua-language-server"
# For Doom Emacs
mkdir -pv ~/.config/emacs-config/doom/.local/etc/lsp
mv -fv lua-language-server ~/.config/emacs/.local/etc/lsp/