Function: claude-code-ide-mcp-handle-open-file
claude-code-ide-mcp-handle-open-file is a natively compiled function
defined in claude-code-ide-mcp-handlers.el.
Signature
(claude-code-ide-mcp-handle-open-file ARGUMENTS &optional SESSION)
Documentation
Open a file with optional text selection.
ARGUMENTS should contain:
- filePath: File path to open
- startLine (optional): Start line for selection
- endLine (optional): End line for selection
- startText (optional): Start text pattern for selection
- endText (optional): End text pattern for selection
Source Code
;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide-mcp-handlers.el
;;; Tool Handler Functions
(defun claude-code-ide-mcp-handle-open-file (arguments &optional _session)
"Open a file with optional text selection.
ARGUMENTS should contain:
- `filePath': File path to open
- `startLine' (optional): Start line for selection
- `endLine' (optional): End line for selection
- `startText' (optional): Start text pattern for selection
- `endText' (optional): End text pattern for selection"
(let ((path (alist-get 'filePath arguments))
(start-line (alist-get 'startLine arguments))
(end-line (alist-get 'endLine arguments))
(start-text (alist-get 'startText arguments))
(end-text (alist-get 'endText arguments)))
(unless path
(signal 'mcp-error '("Missing required parameter: filePath")))
(condition-case err
(progn
(find-file path)
;; Set up buffer cache hooks for the newly opened file
(with-current-buffer (current-buffer)
(claude-code-ide-mcp--setup-buffer-cache-hooks))
;; Text pattern selection takes precedence over line numbers
(cond
;; Both start and end text patterns provided
((and start-text end-text)
(goto-char (point-min))
(if (search-forward start-text nil t)
(let ((start-pos (match-beginning 0)))
(if (search-forward end-text nil t)
(let ((end-pos (match-end 0)))
(goto-char start-pos)
(push-mark end-pos t t)
(activate-mark))
;; End text not found, just go to start
(goto-char start-pos)))
;; Start text not found, fall back to line numbers if provided
(when start-line
(goto-char (point-min))
(forward-line (1- start-line))
(when end-line
(push-mark (point) t t)
(forward-line (- end-line start-line))
(end-of-line)
(activate-mark)))))
;; Only start text provided
(start-text
(goto-char (point-min))
(when (search-forward start-text nil t)
(goto-char (match-beginning 0))))
;; Line number selection
(start-line
(goto-char (point-min))
(forward-line (1- start-line))
(when end-line
(push-mark (point) t t)
(forward-line (- end-line start-line))
(end-of-line)
(activate-mark))))
;; Return in VS Code format
(list `((type . "text")
(text . "FILE_OPENED"))))
(error
(signal 'mcp-error (list (format "Failed to open file: %s"
(error-message-string err))))))))