aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vim/.config/nvim/init.vim4
-rw-r--r--vim/.config/nvim/lua/lsp/init.lua91
-rw-r--r--vim/.vimrc35
3 files changed, 126 insertions, 4 deletions
diff --git a/vim/.config/nvim/init.vim b/vim/.config/nvim/init.vim
index f182e5b..43ad269 100644
--- a/vim/.config/nvim/init.vim
+++ b/vim/.config/nvim/init.vim
@@ -1,3 +1,7 @@
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc
+
+lua <<EOF
+local nvim_lsp = require('lsp')
+EOF
diff --git a/vim/.config/nvim/lua/lsp/init.lua b/vim/.config/nvim/lua/lsp/init.lua
new file mode 100644
index 0000000..2e2ea9f
--- /dev/null
+++ b/vim/.config/nvim/lua/lsp/init.lua
@@ -0,0 +1,91 @@
+local first_hover_code_i = 0
+local first_hover_code_line = -1
+local first_hover_code_col = -1
+local first_hover_code_prev = ''
+
+-- Returns the first code block from the markdown returned for the LSP request
+-- textDocument/hover. Multiple lines are joined with a space.
+function _G.lsp_first_hover_code()
+ --[[ NB: there is a bug that causes statusline to be reloaded continuously;
+ see https://github.com/neovim/neovim/issues/14303. It is not good to do a
+ sync request every time. Instead, keep track of line & col and only
+ update when either has changed. This should be fixed in nvim 0.5, after
+ which the first_hover_code_* variables and this logic can be removed. ]]
+
+ local line, col = unpack(vim.api.nvim_win_get_cursor(0))
+ if line == first_hover_code_line and col == first_hover_code_col then
+ return first_hover_code_prev
+ end
+ first_hover_code_line = line
+ first_hover_code_col = col
+
+ --[[ To check whether the bug has been fixed:
+ vim.api.nvim_echo({{'request '},{tostring(first_hover_code_i)},{tostring(line)}},false,{})
+ first_hover_code_i = first_hover_code_i + 1
+ --]]
+
+ if not vim.lsp.buf.server_ready() then return '' end
+
+ local responses = vim.lsp.buf_request_sync(
+ 0,
+ 'textDocument/hover',
+ vim.lsp.util.make_position_params(),
+ 1000
+ )
+
+ if not responses then return '' end
+
+ local full_result = ''
+ local markdown_started = false
+
+ for _, response in ipairs(responses) do
+ if response.result then
+ response = response.result.contents.value
+ for line in response:gmatch '[^\n]+' do
+ if line:sub(0,3) == '```' then
+ if markdown_started then
+ first_hover_code_prev = full_result
+ return full_result
+ else
+ markdown_started = true
+ end
+ else
+ full_result = full_result .. ' ' .. line
+ end
+ end
+ end
+ end
+
+ first_hover_code_prev = full_result
+ return full_result
+end
+
+local function on_attach (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
+
+ buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
+
+ local opts = {noremap=true, silent=true}
+
+ 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', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
+ buf_set_keymap('n', '<space>ca', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
+ buf_set_keymap('n', '<space>f', '<Cmd>lua vim.lsp.buf.formatting()<CR>', opts)
+ buf_set_keymap('n', '<space>t', '<Cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
+ buf_set_keymap('n', '<space>d', '<Cmd>lua vim.lsp.diagnostic.show_line_diagnostics {show_header=false}<CR>', opts)
+end
+
+local default_config = {
+ on_attach = on_attach
+}
+
+local servers = {
+ hls = {}
+}
+
+local nvim_lsp = require('lspconfig')
+for server, config in pairs(servers) do
+ nvim_lsp[server].setup(vim.tbl_deep_extend('force', default_config, config))
+end
diff --git a/vim/.vimrc b/vim/.vimrc
index f3aed99..4e25604 100644
--- a/vim/.vimrc
+++ b/vim/.vimrc
@@ -34,6 +34,10 @@ Plugin 'google/vim-searchindex' " shows '[N/M]' when searching
" Color schemes
Plugin 'NLKNguyen/papercolor-theme'
+if has('nvim')
+ Plugin 'neovim/nvim-lspconfig' " Language Server Protocol configs
+endif
+
call vundle#end()
" End Vundle
@@ -80,6 +84,7 @@ highlight SpellBad cterm=underline,bold ctermfg=black ctermbg=red
highlight SpellCap cterm=underline,bold ctermfg=black ctermbg=yellow
highlight SpellLocal cterm=underline,bold ctermfg=black ctermbg=blue
highlight SpellRare cterm=underline,bold ctermfg=black ctermbg=white
+
highlight ColorColumn ctermfg=black ctermbg=yellow
" The terminal background (set in .Xresources) is the background for that part
@@ -109,7 +114,26 @@ function! s:detect_terminal_line_border()
call s:set_terminal_line_border('1c1c1c')
endif
endfunction
-autocmd VimEnter,ColorScheme * call s:detect_terminal_line_border()
+
+function! s:colorscheme_changed()
+ call s:detect_terminal_line_border()
+
+ if has('nvim')
+ " See https://github.com/neovim/nvim-lspconfig/issues/516
+ lua require('vim.lsp.diagnostic')._define_default_signs_and_highlights()
+
+ highlight LspDiagnosticsDefaultError ctermfg=red
+ highlight LspDiagnosticsSignError ctermfg=red
+ highlight LspDiagnosticsDefaultWarning ctermfg=brown
+ highlight LspDiagnosticsSignWarning ctermfg=brown
+ highlight LspDiagnosticsDefaultInformation ctermfg=yellow
+ highlight LspDiagnosticsSignInformation ctermfg=yellow
+ highlight LspDiagnosticsDefaultHint ctermfg=yellow
+ highlight LspDiagnosticsSignHint ctermfg=yellow
+ endif
+endfunction
+
+autocmd VimEnter,ColorScheme * call s:colorscheme_changed()
" When we leave vim we restore the value set also in .Xresources
autocmd VimLeave * call s:set_terminal_line_border('002b36')
@@ -125,8 +149,8 @@ map <LocalLeader>s :syn sync fromstart<CR>
function! s:enable_automatic_background()
augroup bg
- autocmd bg BufEnter * set bg=dark | call s:detect_terminal_line_border()
- autocmd bg BufEnter *.bib,*.md,*.tex,*.txt set bg=light | call s:detect_terminal_line_border()
+ autocmd bg BufEnter * set background=dark | call s:colorscheme_changed()
+ autocmd bg BufEnter *.bib,*.md,*.tex,*.txt set background=light | call s:colorscheme_changed()
augroup END
endfunction
@@ -160,7 +184,10 @@ let g:VM_case_setting = 'sensitive'
" Don't let match-up mess up the statusline
let g:matchup_matchparen_status_offscreen=0
-" Clean
+" Status line based on LSP
+set statusline+=%{luaeval('lsp_first_hover_code()')}
+
+" Clean has no language server, we use the cloogletags statusline component
set statusline+=%{cleanvim#tags#statusline()}
" Git gutter