From f0945d0b3b1fd00b920698d165e08f161a7ab0e8 Mon Sep 17 00:00:00 2001 From: Andreas Louv Date: Sat, 20 May 2023 21:38:34 +0200 Subject: [PATCH] Add the server config "processDiagHandler" --- autoload/lsp/diag.vim | 7 ++++++- autoload/lsp/lsp.vim | 6 ++++++ autoload/lsp/lspserver.vim | 2 ++ doc/lsp.txt | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index f812c40..cf74879 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -251,7 +251,7 @@ enddef # process a diagnostic notification message from the LSP server # Notification: textDocument/publishDiagnostics # Param: PublishDiagnosticsParams -export def DiagNotification(lspserver: dict, uri: string, newDiags: list>): void +export def DiagNotification(lspserver: dict, uri: string, diags_arg: list>): void # Diagnostics are disabled for this server if lspserver.features->has_key('diagnostics') && !lspserver.features.diagnostics return @@ -264,6 +264,11 @@ export def DiagNotification(lspserver: dict, uri: string, newDiags: list> = diags_arg + if lspserver.processDiagHandler != null_function + newDiags = lspserver.processDiagHandler(diags_arg) + endif + # TODO: Is the buffer (bnr) always a loaded buffer? Should we load it here? var lastlnum: number = bnr->getbufinfo()[0].linecount diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index b2f6dd3..edecb3f 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -612,6 +612,11 @@ export def AddServer(serverList: list>) customNotificationHandlers = server.customNotificationHandlers endif + var ProcessDiagHandler: func = null_function + if server->has_key('processDiagHandler') + ProcessDiagHandler = server.processDiagHandler + endif + var features: dict = {} if server->has_key('features') features = server.features @@ -661,6 +666,7 @@ export def AddServer(serverList: list>) server.runIfSearch, server.runUnlessSearch, customNotificationHandlers, + ProcessDiagHandler, features, server.debug) var ftypes = server.filetype diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index 89501a2..ccd3c4d 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -1505,6 +1505,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, runIfSearchFiles: list, runUnlessSearchFiles: list, customNotificationHandlers: dict, + ProcessDiagHandler: func, features: dict, debug_arg: bool): dict var lspserver: dict = { id: GetUniqueServerId(), @@ -1514,6 +1515,7 @@ export def NewLspServer(name_arg: string, path_arg: string, args: list, syncInit: isSync, initializationOptions: initializationOptions, customNotificationHandlers: customNotificationHandlers, + processDiagHandler: ProcessDiagHandler, features: features, running: false, ready: false, diff --git a/doc/lsp.txt b/doc/lsp.txt index 7ce342a..2cf47b7 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -320,6 +320,13 @@ Additionally the following configurations can be made: omnicompl (Optional) a boolean value that enables (true) or disables (false) omni-completion for this file types. By default this is set to "v:true". + *lsp-cfg-processDiagHandler* + processDiagHandler + (Optional) A |Funcref| or |lambda| that takes a list of + language server diagnostics and returns a new list of + filtered, or otherwise changed diagnostics. Can be used + to remove unwanted diagnostics, prefix the diagnostics + text, etc. *lsp-cfg-syncInit* syncInit (Optional) for language servers (e.g. rust analyzer, gopls, etc.) that take time to initialize and reply to -- 2.48.1