Function: claude-code-ide-diagnostics-handler

claude-code-ide-diagnostics-handler is a natively compiled function defined in claude-code-ide-diagnostics.el.

Signature

(claude-code-ide-diagnostics-handler PARAMS &optional SESSION)

Documentation

Handle getDiagnostics tool request with PARAMS.

Optional SESSION contains the MCP session context.

Source Code

;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide-diagnostics.el
(defun claude-code-ide-diagnostics-handler (params &optional session)
  "Handle getDiagnostics tool request with PARAMS.
Optional SESSION contains the MCP session context."
  (let* ((uri (alist-get 'uri params))
         (diagnostics-by-file '())
         (project-dir (when session
                        (claude-code-ide-mcp-session-project-dir session))))
    (claude-code-ide-debug "Diagnostics handler called with URI: %s, project-dir: %s" uri project-dir)
    (if (and uri (not (string-empty-p uri)))
        ;; Get diagnostics for specific file
        (let* ((file-path (claude-code-ide-uri-to-file-path uri))
               (buffer (get-file-buffer (expand-file-name file-path))))
          (when buffer
            (let ((diags (claude-code-ide-diagnostics-get-all buffer)))
              (when (> (length diags) 0)
                (push `((uri . ,uri)
                        (diagnostics . ,diags))
                      diagnostics-by-file)))))
      ;; Get diagnostics for all files in the session's project
      (let ((buffer-count 0)
            (checked-count 0))
        (dolist (buffer (buffer-list))
          (when-let* ((file (buffer-file-name buffer)))
            (setq buffer-count (1+ buffer-count))
            ;; Filter by project directory if session is available
            (when (or (not project-dir)
                      (string-prefix-p (expand-file-name project-dir)
                                       (expand-file-name file)))
              (setq checked-count (1+ checked-count))
              (claude-code-ide-debug "Checking buffer: %s" file)
              (let ((diags (claude-code-ide-diagnostics-get-all buffer)))
                (claude-code-ide-debug "Found %d diagnostics for %s" (length diags) file)
                (when (> (length diags) 0)
                  (push `((uri . ,(claude-code-ide-file-path-to-uri file))
                          (diagnostics . ,diags))
                        diagnostics-by-file))))))
        (claude-code-ide-debug "Checked %d/%d buffers with files" checked-count buffer-count)))
    ;; Return JSON-encoded string in content array format
    (let ((json-str (if diagnostics-by-file
                        (json-encode (vconcat (nreverse diagnostics-by-file)))
                      "[]")))
      (list `((type . "text")
              (text . ,json-str))))))