Skip to content

Commit b130451

Browse files
committed
Fix cider-jump-to-var with no symbol at point
Also, make `cider-jump-to-var` and `cider-stacktrace-navigate` use common workhorse.
1 parent a34e0d4 commit b130451

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

cider-interaction.el

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -682,24 +682,34 @@ When called interactively, this operates on point."
682682
(cider-jump-to buffer (cons line nil))
683683
(message "Cannot find resource %s" path)))
684684

685-
(defun cider-jump-to-var (var &optional line)
686-
"Jump to the definition of VAR, optionally at a specific LINE.
687-
When called interactively, this operates on point, or falls back to a prompt."
688-
(interactive (list (cider-read-symbol-name "Symbol: " 'identity)))
689-
(cider-ensure-op-supported "info")
690-
(-if-let (info (cider-var-info var))
691-
(-if-let* ((file (cadr (assoc "file" info)))
692-
(line (or line (cadr (assoc "line" info))))
693-
(buffer (cider-find-file file)))
694-
(cider-jump-to buffer (cons line nil))
685+
(defun cider--jump-to-loc-from-info (info &optional other-buffer)
686+
"Jump to location give by INFO.
687+
INFO object is returned by `cider-var-info' or `cider-member-info'.
688+
OTHER-BUFFER is passed to `cider-jamp-to'."
689+
(-if-let* ((file (cadr (assoc "file" info)))
690+
(line (cadr (assoc "line" info)))
691+
(buffer (cider-find-file file)))
692+
(cider-jump-to buffer (cons line nil) other-buffer)
695693
;; var was created interactively and has no file info
696694
(-if-let* ((ns (cadr (assoc "ns" info)))
697695
(name (cadr (assoc "name" info)))
698696
(buffer (cider-find-buffer ns))
699-
(pos (cider-locate-def name buffer)))
700-
(cider-jump-to buffer pos)
701-
(message "No source available for %s" var)))
702-
(message "Symbol %s not resolved" var)))
697+
(pos (cider-locate-def name buffer line)))
698+
(cider-jump-to buffer pos other-buffer)
699+
(-if-let (name (cadr (assoc "name" info)))
700+
(message "No location found for %s" name)
701+
(message "No source info")))))
702+
703+
(defun cider-jump-to-var (&optional var line)
704+
"Jump to the definition of VAR, optionally at a specific LINE.
705+
When called interactively, this operates on point, or falls back to a prompt."
706+
(interactive)
707+
(cider-ensure-op-supported "info")
708+
(cider-read-symbol-name
709+
"Symbol: " (lambda (var)
710+
(-if-let (info (cider-var-info var))
711+
(cider--jump-to-loc-from-info info)
712+
(message "Symbol %s not resolved" var)))))
703713

704714
(define-obsolete-function-alias 'cider-jump 'cider-jump-to-var "0.7.0")
705715
(defalias 'cider-jump-back 'pop-tag-mark)

cider-stacktrace.el

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -401,20 +401,12 @@ it wraps to 0."
401401
(let* ((var (button-get button 'var))
402402
(class (button-get button 'class))
403403
(method (button-get button 'method))
404-
(line (button-get button 'line))
405-
(info (if var
406-
(cider-var-info var)
407-
(cider-member-info class method))))
408-
(-if-let* ((file (cadr (assoc "file" info)))
409-
(buffer (cider-find-file file)))
410-
(cider-jump-to buffer (cons line nil))
411-
;; when no file info, find the location by regexp search
412-
(-if-let* ((ns (cadr (assoc "ns" info)))
413-
(name (cadr (assoc "name" info)))
414-
(buffer (cider-find-buffer ns))
415-
(pos (cider-locate-def name buffer line)))
416-
(cider-jump-to buffer pos)
417-
(message "No source info")))))
404+
(info (or (and var (cider-var-info var))
405+
(and class method (cider-member-info class method))))
406+
;; stacktrace returns more accurate line numbers
407+
(info (cons `("line" ,(button-get button 'line))
408+
info)))
409+
(cider--jump-to-loc-from-info info t)))
418410

419411
(defun cider-stacktrace-jump ()
420412
"Like `cider-jump', but uses the stack frame source at point, if available."

0 commit comments

Comments
 (0)