summaryrefslogtreecommitdiff
path: root/cider-stacktrace.el
diff options
context:
space:
mode:
authorOleh Krehel <ohwoeowho@gmail.com>2018-01-15 22:19:34 +0100
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2018-01-15 23:19:34 +0200
commit7fa4340aee9ce7d3f80470355e2a9f48d76d788c (patch)
treeb905fa868d40c09544090d5068a018e57efcc317 /cider-stacktrace.el
parent32c25bee573dbec429e6df25357c8b526e2708fa (diff)
Java files are now linked in stack traces if paths are configured (#2167)
On Ubuntu: sudo apt install openjdk-8-source The zip is installed to /usr/lib/jvm/openjdk-8/src.zip. Download also this one: https://repo1.maven.org/maven2/org/clojure/clojure/1.8.0/clojure-1.8.0-sources.jar Extract both and configure e.g. like so: (setq cider-jdk-src-paths '("~/git/java/clojure-1.8.0-sources" "~/git/java/openjvm-8-src"))
Diffstat (limited to 'cider-stacktrace.el')
-rw-r--r--cider-stacktrace.el30
1 files changed, 28 insertions, 2 deletions
diff --git a/cider-stacktrace.el b/cider-stacktrace.el
index 0e0dd921..01df857f 100644
--- a/cider-stacktrace.el
+++ b/cider-stacktrace.el
@@ -561,6 +561,29 @@ Achieved by destructively manipulating the `cider-stacktrace-suppressed-errors'
(button-put button 'help-echo "Click to promote these stacktraces."))
(button-put button 'suppressed (not suppressed)))))
+(defcustom cider-jdk-src-paths '("/usr/lib/jvm/openjdk-8/src.zip")
+ "Used by `cider-stacktrace-navigate'.
+Zip files work, but it's better to extract them and put the directory paths here.
+Clojure sources here: https://repo1.maven.org/maven2/org/clojure/clojure/1.8.0/."
+ :package-version '(cider . "0.17.0")
+ :type '(list string))
+
+(defun cider-resolve-java-class (class)
+ "Return a zip path to a file that corresponds to CLASS."
+ (when class
+ (let ((file-name (concat (replace-regexp-in-string "\\." "/" class) ".java")))
+ (cl-find-if
+ 'file-exists-p
+ (mapcar
+ (lambda (d)
+ (cond ((file-directory-p d)
+ (expand-file-name file-name d))
+ ((and (file-exists-p d)
+ (member (file-name-extension d) '("jar" "zip")))
+ (format "zip:file:%s!/%s" d file-name))
+ (t (error "Unexpected archive: %s" d))))
+ cider-jdk-src-paths)))))
+
(defun cider-stacktrace-navigate (button)
"Navigate to the stack frame source represented by the BUTTON."
(let* ((var (button-get button 'var))
@@ -574,9 +597,12 @@ Achieved by destructively manipulating the `cider-stacktrace-suppressed-errors'
;; Set `line-shift' to the number of lines from the beginning of defn.
(line-shift (- (or (button-get button 'line) 0)
(or (nrepl-dict-get info "line") 1)))
+ (file (or
+ (and (null var) (cider-resolve-java-class class))
+ (nrepl-dict-get info "file")
+ (button-get button 'file)))
;; give priority to `info` files as `info` returns full paths.
- (info (nrepl-dict-put info "file" (or (nrepl-dict-get info "file")
- (button-get button 'file)))))
+ (info (nrepl-dict-put info "file" file)))
(cider--jump-to-loc-from-info info t)
(forward-line line-shift)
(back-to-indentation)))