Last active
January 3, 2022 18:52
-
-
Save icholy/0c90319a7e9d04564a9565c20026b63d to your computer and use it in GitHub Desktop.
TypeScript LSP status in Airline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The TypeScript LSP server takes a while before it's responsive. This is a janky way of indicating the server status in | |
-- airline. It works by adding "..." to the statusline when the LSP connects, and then removing the "..." when the first | |
-- set of diagnostics come in. | |
vim.cmd([[ | |
let g:lsp_wait_added = 0 | |
let g:lsp_wait_done = 0 | |
function! LspWait(...) | |
let builder = a:1 | |
let context = a:2 | |
call builder.add_section('airline_b', '...') | |
return 0 | |
endfunction | |
]]) | |
local function on_attach(client, bufnr) | |
-- add the "..." to airline when the lsp server connects | |
vim.cmd([[ | |
if !g:lsp_wait_added | |
call airline#add_statusline_func('LspWait') | |
call airline#add_inactive_statusline_func('LspWait') | |
call airline#update_statusline() | |
let g:lsp_wait_added = 1 | |
endif | |
]]) | |
-- remove the "..." when the lsp server sends diagnostics for the first time | |
-- note: I originally wanted to listen for progress events, but typescript-language-server | |
-- doesn't seem to send any even when I specify the capabilities. | |
local handler = vim.lsp.handlers['textDocument/publishDiagnostics'] | |
vim.lsp.handlers['textDocument/publishDiagnostics'] = function (...) | |
vim.cmd([[ | |
if !g:lsp_wait_done | |
call airline#remove_statusline_func('LspWait') | |
call airline#update_statusline() | |
let g:lsp_wait_done = 1 | |
endif | |
]]) | |
if handler ~= nil then | |
handler(...) | |
end | |
end | |
end | |
lspconfig['tsserver'].setup({ | |
capabilities = capabilities, | |
on_attach = on_attach | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment