Skip to content

Commit ef9e9fc

Browse files
committed
Polish port-stacktrace
* `port-stacktrace-parse' is now a thin wrapper over `port-tooling--read-result' so the two parse-printed-map-or-nil paths share an implementation. * `port-stacktrace--locate-relative' anchors the search at the jack-in-detected project root (with `default-directory' as the fallback), so a stacktrace rendered from a sub-directory still resolves frames against the project's top-level `src/' tree. * Sync the `port-stacktrace-hide-clojure-internals' docstring with the actual prefix list in `port-stacktrace--noise-frame-p' (clojure.main, javax., jdk. were missing from the doc).
1 parent 34fc8e2 commit ef9e9fc

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

lisp/port-stacktrace.el

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
(require 'cl-lib)
2424
(require 'subr-x)
2525
(require 'port-client)
26+
(require 'port-tooling)
2627
(require 'port-xref)
2728

2829
(defgroup port-stacktrace nil
@@ -36,8 +37,9 @@
3637

3738
(defcustom port-stacktrace-hide-clojure-internals t
3839
"If non-nil, hide common Clojure/Java internal frames from the trace.
39-
Frames whose class starts with `clojure.lang.', `clojure.core',
40-
`java.', `sun.', or `nrepl.' are filtered out."
40+
Frames whose class starts with `clojure.lang.', `clojure.core$',
41+
`clojure.main', `java.', `javax.', `sun.', `jdk.', or `nrepl.'
42+
are filtered out (see `port-stacktrace--noise-frame-p')."
4143
:type 'boolean
4244
:group 'port-stacktrace)
4345

@@ -258,15 +260,24 @@ common project source roots."
258260
(port-xref--visit found line)
259261
(message "Port: cannot resolve %s to a local file" file))))))
260262

263+
(declare-function port-jack-in--detect-project-root "port-jack-in")
264+
261265
(defun port-stacktrace--locate-relative (file)
262-
"Try to locate a classpath-relative FILE under the current project."
263-
(let ((roots (list default-directory
264-
(expand-file-name "src" default-directory)
265-
(expand-file-name "test" default-directory)
266-
(expand-file-name "src/main/clojure" default-directory)
267-
(expand-file-name "src/test/clojure" default-directory))))
268-
(cl-loop for root in roots
269-
for candidate = (expand-file-name file root)
266+
"Try to locate a classpath-relative FILE under the current project.
267+
Anchors the search at the jack-in-detected project root when
268+
possible (so a stacktrace rendered from a sub-directory still
269+
resolves frames against the top-level `src/' tree), falling back
270+
to `default-directory'."
271+
(let* ((root (or (and (fboundp 'port-jack-in--detect-project-root)
272+
(port-jack-in--detect-project-root))
273+
default-directory))
274+
(roots (list root
275+
(expand-file-name "src" root)
276+
(expand-file-name "test" root)
277+
(expand-file-name "src/main/clojure" root)
278+
(expand-file-name "src/test/clojure" root))))
279+
(cl-loop for r in roots
280+
for candidate = (expand-file-name file r)
270281
when (file-exists-p candidate) return candidate)))
271282

272283
(defun port-stacktrace-next-frame ()
@@ -292,12 +303,10 @@ common project source roots."
292303

293304
(defun port-stacktrace-parse (val)
294305
"Parse VAL — a printed Throwable->map string — into an alist.
295-
Returns nil if VAL doesn't parse as a map."
296-
(when (stringp val)
297-
(condition-case _
298-
(let ((parsed (car (port-client--read val 0))))
299-
(and (consp parsed) (consp (car parsed)) parsed))
300-
(error nil))))
306+
Returns nil if VAL isn't a string or doesn't parse as a map.
307+
A thin wrapper around `port-tooling--read-result' so the two
308+
parse-as-map paths share an implementation."
309+
(and (stringp val) (port-tooling--read-result val)))
301310

302311
(defun port-stacktrace-pop-from-result (result)
303312
"Display a stacktrace buffer for an `:err' RESULT from the tool socket.

0 commit comments

Comments
 (0)