autoload/lsp/diag.vim | 7 ++++++- autoload/lsp/lsp.vim | 6 ++++++ autoload/lsp/lspserver.vim | 2 ++ doc/lsp.txt | 7 +++++++ diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index f812c401aaf0e89cd44b82c37bb6df22b10479b3..cf74879b0484c84e57ce3fc88eea69c78e8819d2 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -251,7 +251,7 @@ # 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 @@ -262,6 +262,11 @@ var bnr: number = fname->bufnr() if bnr == -1 # Is this condition possible? return + endif + + var 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? diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index b2f6dd3e0bc4bbd57be11389573395d95f4ede18..edecb3ffba1ef3634aef4983e7951db4e3aa34e6 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -612,6 +612,11 @@ if server->has_key('customNotificationHandlers') 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 @@ server.rootSearch, 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 89501a2c02498566cf1bff55d69e22a35f8c09a8..ccd3c4d2492443287e6a02ca43c92cc84580d20e 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -1505,6 +1505,7 @@ rootSearchFiles: list, runIfSearchFiles: list, runUnlessSearchFiles: list, customNotificationHandlers: dict, + ProcessDiagHandler: func, features: dict, debug_arg: bool): dict var lspserver: dict = { id: GetUniqueServerId(), @@ -1514,6 +1515,7 @@ args: args, 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 7ce342a0a60210b4d96c845355ef86b8681d0a7a..2cf47b728783a6246cde1d86da0c2845161a49f0 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -320,6 +320,13 @@ *lsp-cfg-omnicompl* 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