Skip to content

Commit

Permalink
Fix cider-jump-to-var with no symbol at point
Browse files Browse the repository at this point in the history
  Also, make `cider-jump-to-var` and `cider-stacktrace-navigate` use common
  workhorse.
  • Loading branch information
vspinu committed Aug 31, 2014
1 parent a34e0d4 commit b130451
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
38 changes: 24 additions & 14 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -682,24 +682,34 @@ When called interactively, this operates on point."
(cider-jump-to buffer (cons line nil))
(message "Cannot find resource %s" path)))

(defun cider-jump-to-var (var &optional line)
"Jump to the definition of VAR, optionally at a specific LINE.
When called interactively, this operates on point, or falls back to a prompt."
(interactive (list (cider-read-symbol-name "Symbol: " 'identity)))
(cider-ensure-op-supported "info")
(-if-let (info (cider-var-info var))
(-if-let* ((file (cadr (assoc "file" info)))
(line (or line (cadr (assoc "line" info))))
(buffer (cider-find-file file)))
(cider-jump-to buffer (cons line nil))
(defun cider--jump-to-loc-from-info (info &optional other-buffer)
"Jump to location give by INFO.
INFO object is returned by `cider-var-info' or `cider-member-info'.
OTHER-BUFFER is passed to `cider-jamp-to'."
(-if-let* ((file (cadr (assoc "file" info)))
(line (cadr (assoc "line" info)))
(buffer (cider-find-file file)))
(cider-jump-to buffer (cons line nil) other-buffer)
;; var was created interactively and has no file info
(-if-let* ((ns (cadr (assoc "ns" info)))
(name (cadr (assoc "name" info)))
(buffer (cider-find-buffer ns))
(pos (cider-locate-def name buffer)))
(cider-jump-to buffer pos)
(message "No source available for %s" var)))
(message "Symbol %s not resolved" var)))
(pos (cider-locate-def name buffer line)))
(cider-jump-to buffer pos other-buffer)
(-if-let (name (cadr (assoc "name" info)))
(message "No location found for %s" name)
(message "No source info")))))

(defun cider-jump-to-var (&optional var line)
"Jump to the definition of VAR, optionally at a specific LINE.
When called interactively, this operates on point, or falls back to a prompt."
(interactive)
(cider-ensure-op-supported "info")
(cider-read-symbol-name
"Symbol: " (lambda (var)
(-if-let (info (cider-var-info var))
(cider--jump-to-loc-from-info info)
(message "Symbol %s not resolved" var)))))

(define-obsolete-function-alias 'cider-jump 'cider-jump-to-var "0.7.0")
(defalias 'cider-jump-back 'pop-tag-mark)
Expand Down
20 changes: 6 additions & 14 deletions cider-stacktrace.el
Original file line number Diff line number Diff line change
Expand Up @@ -401,20 +401,12 @@ it wraps to 0."
(let* ((var (button-get button 'var))
(class (button-get button 'class))
(method (button-get button 'method))
(line (button-get button 'line))
(info (if var
(cider-var-info var)
(cider-member-info class method))))
(-if-let* ((file (cadr (assoc "file" info)))
(buffer (cider-find-file file)))
(cider-jump-to buffer (cons line nil))
;; when no file info, find the location by regexp search
(-if-let* ((ns (cadr (assoc "ns" info)))
(name (cadr (assoc "name" info)))
(buffer (cider-find-buffer ns))
(pos (cider-locate-def name buffer line)))
(cider-jump-to buffer pos)
(message "No source info")))))
(info (or (and var (cider-var-info var))
(and class method (cider-member-info class method))))
;; stacktrace returns more accurate line numbers
(info (cons `("line" ,(button-get button 'line))
info)))
(cider--jump-to-loc-from-info info t)))

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

0 comments on commit b130451

Please sign in to comment.