nvim: Add support for LSP in status line

Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
This commit is contained in:
Sanchayan Maity 2020-09-02 14:45:27 +05:30
parent 99a858df26
commit d59e74f588
3 changed files with 29 additions and 4 deletions

View file

@ -64,6 +64,7 @@ Plug 'voldikss/vim-floaterm'
" LSP
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/diagnostic-nvim'
Plug 'nvim-lua/lsp-status.nvim'
" Language support & syntax highlighting
" Haskell
Plug 'neovimhaskell/haskell-vim'

View file

@ -1,4 +1,7 @@
local nvim_lsp = require('nvim_lsp')
local diagnostic = require('diagnostic')
local completion = require('completion')
local lsp_status = require('lsp-status')
-- Taken from https://www.reddit.com/r/neovim/comments/gyb077/nvimlsp_peek_defination_javascript_ttserver/
function preview_location(location, context, before_context)
@ -42,10 +45,11 @@ function peek_definition()
end
end
local on_attach = function(_, bufnr)
local on_attach = function(client, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
require'diagnostic'.on_attach()
require'completion'.on_attach()
diagnostic.on_attach(client, bufnr)
completion.on_attach(client, bufnr)
lsp_status.on_attach(client, bufnr)
local opts = { noremap=true, silent=true }
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
@ -69,7 +73,18 @@ end
local servers = { 'hls', 'purescriptls', 'rust_analyzer' }
for _, lsp in ipairs(servers) do
lsp_status.register_progress()
lsp_status.config({
status_symbol = '',
indicator_errors = 'e',
indicator_warnings = 'w',
indicator_info = 'i',
indicator_hint = 'h',
indicator_ok = '✔️',
spinner_frames = { '', '', '', '', '', '', '', '' },
})
nvim_lsp[lsp].setup {
on_attach = on_attach,
on_attach = on_attach,
capabilities = lsp_status.capabilities
}
end

View file

@ -33,12 +33,20 @@ function! GetFileStatus()
return len(l:status) > 0 ? ' ' . l:status : ''
endfunction
function! LspStatus() abort
if luaeval('#vim.lsp.buf_get_clients() > 0')
return luaeval("require('lsp-status').status()")
endif
return ''
endfunction
function! ActiveStatus() abort
let statusline=""
let statusline.="%1*\ %{winnr()}\ "
let statusline.="%4*\ %{GetFileStatus()}"
let statusline.="%2*\ %Y\ "
let statusline.="%3*%<%f"
let statusline.="%4%\ %{LspStatus()}"
let statusline.="%="
let statusline.="%4*\ %{GetCursorPosition()}\ (%3p%%)"
return statusline
@ -50,6 +58,7 @@ function! PassiveStatus() abort
let statusline.="%8*\ %{GetFileStatus()}"
let statusline.="%6*\ %Y\ "
let statusline.="%7*%<%f"
let statusline.="%8%\ %{LspStatus()}"
let statusline.="%="
let statusline.="%8*\ %{GetCursorPosition()}\ (%3p%%)"
return statusline