Function: claude-code-ide-mcp--get-current-selection

claude-code-ide-mcp--get-current-selection is a natively compiled function defined in claude-code-ide-mcp.el.

Signature

(claude-code-ide-mcp--get-current-selection)

Documentation

Build the current selection payload for the selection_changed notification.

Returns an alist with text, filePath, and selection keys matching the CLI's SelectionChangedSchema.

Source Code

;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide-mcp.el
(defun claude-code-ide-mcp--get-current-selection ()
  "Build the current selection payload for the selection_changed notification.
Returns an alist with `text', `filePath', and `selection' keys matching
the CLI's SelectionChangedSchema."
  (let ((file-path (or (buffer-file-name) "")))
    (if (use-region-p)
        (let* ((start (region-beginning))
               (end (region-end))
               (text (buffer-substring-no-properties start end))
               (start-line (line-number-at-pos start))
               (end-line (line-number-at-pos end))
               (start-col (save-excursion
                            (goto-char start)
                            (1+ (current-column))))
               (end-col (save-excursion
                          (goto-char end)
                          (1+ (current-column)))))
          `((text . ,text)
            (filePath . ,file-path)
            (selection . ((start . ((line . ,start-line)
                                    (character . ,start-col)))
                          (end . ((line . ,end-line)
                                  (character . ,end-col)))))))
      ;; No selection - return cursor position
      (let* ((cursor-line (line-number-at-pos))
             (cursor-col (1+ (current-column))))
        `((text . "")
          (filePath . ,file-path)
          (selection . ((start . ((line . ,cursor-line)
                                  (character . ,cursor-col)))
                        (end . ((line . ,cursor-line)
                                (character . ,cursor-col))))))))))