diff --git a/ocaml-eglot-req.el b/ocaml-eglot-req.el index 6a22b98..66aa755 100644 --- a/ocaml-eglot-req.el +++ b/ocaml-eglot-req.el @@ -94,10 +94,9 @@ A potential IDENTIFIER can be given and MARKUP-KIND can be parametrized." ;;; Concrete requests -(defun ocaml-eglot-req--jump (target) - "Execute the `ocamllsp/jump' request with a given TARGET." - (let ((params (append (ocaml-eglot-req--TextDocumentPositionParams) - `(:target, target)))) +(defun ocaml-eglot-req--jump () + "Execute the `ocamllsp/jump' request." + (let ((params (ocaml-eglot-req--TextDocumentPositionParams))) (ocaml-eglot-req--send :ocamllsp/jump params))) (defun ocaml-eglot-req--construct (depth with-local-value) diff --git a/ocaml-eglot-util.el b/ocaml-eglot-util.el index bfc1f2e..8c87c65 100644 --- a/ocaml-eglot-util.el +++ b/ocaml-eglot-util.el @@ -93,14 +93,6 @@ "Format MARKUP according to LSP's spec." (eglot--format-markup markup)) -;; Jump features - -(defun ocaml-eglot-util--extract-jump-position (jump-result) - "Extracts the position of a JUMP-RESULT of the LSP server." - (let ((target-vec (cl-getf jump-result :jumps))) - (when (> (length target-vec) 0) - (let ((real-target (aref target-vec 0))) - (cl-getf real-target :position))))) (provide 'ocaml-eglot-util) ;;; ocaml-eglot-util.el ends here diff --git a/ocaml-eglot.el b/ocaml-eglot.el index 0a5dcf3..5151ddb 100644 --- a/ocaml-eglot.el +++ b/ocaml-eglot.el @@ -211,20 +211,25 @@ If there is no available holes, it returns the first one of HOLES." ;; Jump to source elements -(defun ocaml-eglot-jump (target) - "Jumps to the begining of the closest fun/let/match/module/module-type. -The target is specified giving TARGET." - (interactive - (list (completing-read - "target: " - '("fun" "let" "match" "module" - "module-type" "match-next-case" - "match-prev-case")))) +(defun ocaml-eglot-jump () + "Jumps to the the closest fun/let/match/module/module-type/match-case." + (interactive) (eglot--server-capable-or-lose :experimental :ocamllsp :handleJump) - (let* ((jumps (ocaml-eglot-req--jump target)) - (position (ocaml-eglot-util--extract-jump-position jumps))) - (unless position (eglot--error "No matching target")) - (ocaml-eglot-util--jump-to position))) + (let ((jumps-result (cl-getf (ocaml-eglot-req--jump) :jumps))) + (when (<= (length jumps-result) 0) + (eglot--error "No matching target")) + (let* ((jumps + (mapcar + (lambda (jump) + (let ((key (cl-getf jump :target)) + (value (cl-getf jump :position))) + (cons key value))) + jumps-result)) + (selected (completing-read "Target: " jumps)) + (position (alist-get selected jumps nil nil #'string-equal))) + (if position + (ocaml-eglot-util--jump-to position) + (eglot--error "Target not found"))))) ;; Search by type or polarity