From: shane.xb.qian Date: Wed, 26 Oct 2022 11:34:41 +0000 (+0800) Subject: feat: add LspServerStatus(ft) func to detect ft lsp server was running or not X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=9b3388397c33b20159eb5cbbd193d53b02fa3e92;p=vim-lsp.git feat: add LspServerStatus(ft) func to detect ft lsp server was running or not --- diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index e911e21..9442717 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -97,19 +97,6 @@ export def EnableServerTrace() util.ServerTrace(true) enddef -# Get LSP server status for filetype 'ftype'. -# Return true if running, otherwise false if not found or not running. -# But lsp init for cur 'buf' maybe not done yet even this func return true, -# check 'g:LspServerReady()' for that instead. -def g:LspServerStatus(ftype: string): bool - for [ft, lspserver] in ftypeServerMap->items() - if ftype ==# ft - return lspserver.running - endif - endfor - return v:false -enddef - # Show information about all the LSP servers export def ShowServers() for [ftype, lspserver] in ftypeServerMap->items() @@ -124,6 +111,17 @@ export def ShowServers() endfor enddef +# Get LSP server status for filetype 'ftype' +# Return true if running, or false if not found or not running +export def ServerStatus(ftype: string): bool + for [ft, lspserver] in ftypeServerMap->items() + if ftype ==# ft + return lspserver.running + endif + endfor + return v:false +enddef + # Go to a definition using "textDocument/definition" LSP request export def GotoDefinition(peek: bool) var lspserver: dict = CurbufGetServerChecked() diff --git a/plugin/lsp.vim b/plugin/lsp.vim index f0df9da..64da174 100644 --- a/plugin/lsp.vim +++ b/plugin/lsp.vim @@ -26,6 +26,10 @@ def g:LspServerReady(): bool return lsp.ServerReady() enddef +def g:LspServerStatus(ftype: string): bool + return lsp.ServerStatus(ftype) +enddef + # Command line completion function for the LspSetTrace command. def LspServerTraceComplete(arglead: string, cmdline: string, cursorpos: number): list var l = ['off', 'messages', 'verbose']