Skip to content

Instantly share code, notes, and snippets.

@mbriggs
Created March 30, 2020 02:55
Show Gist options
  • Save mbriggs/c018dd48ba35253943e3659764d4a094 to your computer and use it in GitHub Desktop.
Save mbriggs/c018dd48ba35253943e3659764d4a094 to your computer and use it in GitHub Desktop.
(defun lsp--on-diagnostics (workspace params)
"Callback for textDocument/publishDiagnostics.
interface PublishDiagnosticsParams {
uri: string;
diagnostics: Diagnostic[];
}
PARAMS contains the diagnostics data.
WORKSPACE is the workspace that contains the diagnostics."
(let* ((file (lsp--uri-to-path (gethash "uri" params)))
(diagnostics (seq-map #'lsp--make-diag (gethash "diagnostics" params)))
(buffer (lsp--buffer-for-file file))
(workspace-diagnostics (lsp--workspace-diagnostics workspace))
(server (lsp--client-server-id (lsp--workspace-client workspace)))
(filter (lambda (d)
(and (eq server 'ts-ls)
(< (lsp-diagnostic-severity d) 3)))))
(if (seq-empty-p diagnostics)
(remhash file workspace-diagnostics)
(when (or lsp-report-if-no-buffer buffer)
(puthash file (-filter filter diagnostics) workspace-diagnostics)))
(run-hooks 'lsp-diagnostics-updated-hook)
(when buffer
(save-mark-and-excursion
(with-current-buffer buffer
(run-hooks 'lsp-after-diagnostics-hook))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment