Skip to content

Commit b6f5f02

Browse files
committed
Added customizable diagnostics filter
- Fixes #1520 - introduced `lsp-diagnostic-filter` which can be used to limit the reported diagnostics. Here it is sample filter to filter diagnostics from typescript ``` elisp (setq lsp-diagnostic-filter 'my/filter-typescript ) (lsp-defun my/filter-typescript ((params &as &PublishDiagnosticsParams :diagnostics) _workspace) (lsp:set-publish-diagnostics-params-diagnostics params (or (seq-filter (-lambda ((&Diagnostic :source?)) (not (string= "typescript" source?))) diagnostics) [])) params) ```
1 parent 41248b1 commit b6f5f02

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

lsp-mode.el

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,16 @@ WORKSPACE is the workspace that contains the progress token."
19031903

19041904
;; diagnostics
19051905

1906+
(defvar lsp-diagnostic-filter nil
1907+
"A a function which will be called with
1908+
`&PublishDiagnosticsParams' and `workspace' which can be used
1909+
to filter out the diagnostics. The function should return
1910+
`&PublishDiagnosticsParams'.
1911+
1912+
Common usecase are:
1913+
1. Filter the diagnostics for a particular language server.
1914+
2. Filter out the diagnostics under specific level.")
1915+
19061916
(defvar lsp-diagnostic-stats (ht))
19071917

19081918
(defun lsp-diagnostics (&optional current-workspace?)
@@ -1954,19 +1964,23 @@ The result format is vector [_ errors warnings infos hints] or nil."
19541964
(directory-file-name path)))))
19551965
(lsp-diagnostics--update-path path new-stats))))
19561966

1957-
(lsp-defun lsp--on-diagnostics (workspace (params &as
1958-
&PublishDiagnosticsParams :uri :diagnostics))
1967+
(defun lsp--on-diagnostics (workspace params)
19591968
"Callback for textDocument/publishDiagnostics.
19601969
interface PublishDiagnosticsParams {
19611970
uri: string;
19621971
diagnostics: Diagnostic[];
19631972
}
19641973
PARAMS contains the diagnostics data.
19651974
WORKSPACE is the workspace that contains the diagnostics."
1975+
(when lsp-diagnostic-filter
1976+
(setf params (funcall lsp-diagnostic-filter params workspace)))
1977+
19661978
(lsp--on-diagnostics-update-stats workspace params)
1967-
(let* ((lsp--virtual-buffer-mappings (ht))
1968-
(file (lsp--fix-path-casing (lsp--uri-to-path uri)))
1969-
(workspace-diagnostics (lsp--workspace-diagnostics workspace)))
1979+
1980+
(-let* (((&PublishDiagnosticsParams :uri :diagnostics) params)
1981+
(lsp--virtual-buffer-mappings (ht))
1982+
(file (lsp--fix-path-casing (lsp--uri-to-path uri)))
1983+
(workspace-diagnostics (lsp--workspace-diagnostics workspace)))
19701984

19711985
(if (seq-empty-p diagnostics)
19721986
(remhash file workspace-diagnostics)

0 commit comments

Comments
 (0)