Skip to content

Commit

Permalink
Exclude reflection warnings from error overlays
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Feb 1, 2024
1 parent d7c7d99 commit 213576e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
19 changes: 18 additions & 1 deletion cider-eval.el
Expand Up @@ -615,6 +615,8 @@ It delegates the actual error content to the eval or op handler."
(optional ":" (group-n 4 (one-or-more digit)))
" - "))

;; Please keep this in sync with `cider-clojure-compilation-error-regexp',
;; which is a subset of these regexes.
(defconst cider-clojure-compilation-regexp
(eval
`(rx bol (or ,cider-clojure-1.9-error
Expand All @@ -629,6 +631,21 @@ lol in this context, compiling:(/foo/core.clj:10:1)\"
\"Syntax error compiling at (src/workspace_service.clj:227:3).\"
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")

(defconst cider-clojure-compilation-error-regexp
(eval
`(rx bol (or ,cider-clojure-1.9-error
,cider-clojure-1.10-error
,cider-clojure-unexpected-error))
t)
"Like `cider-clojure-compilation-regexp',
but excluding warnings such as reflection warnings.
A few example values that will match:
\"CompilerException java.lang.RuntimeException: Unable to resolve symbol: \\
lol in this context, compiling:(/foo/core.clj:10:1)\"
\"Syntax error compiling at (src/workspace_service.clj:227:3).\"
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")

(defconst cider--clojure-execution-error-regexp
(append `(sequence
"Execution error "
Expand Down Expand Up @@ -922,7 +939,7 @@ depending on the PHASE."
(member phase (cider-clojure-compilation-error-phases))))
;; Only show overlays for things that do look like an exception (#3587):
(or (string-match-p cider-clojure-runtime-error-regexp err)
(string-match-p cider-clojure-compilation-regexp err)))
(string-match-p cider-clojure-compilation-error-regexp err)))
;; Display errors as temporary overlays
(let ((cider-result-use-clojure-font-lock nil)
(trimmed-err (funcall cider-inline-error-message-function err)))
Expand Down
39 changes: 20 additions & 19 deletions test/cider-error-parsing-tests.el
Expand Up @@ -117,31 +117,32 @@
(expect (col-num info) :to-equal 43)
(expect (face info) :to-equal 'cider-warning-highlight-face))))

(describe "The cider compilation regex"
(describe "The cider compilation regexes"
(it "Recognizes a clojure warning message"
(let ((clojure-compiler-warning "Reflection warning, /tmp/foo/src/foo/core.clj:14:1 - call to java.lang.Integer ctor can't be resolved."))
(expect clojure-compiler-warning :to-match cider-clojure-compilation-regexp)
(expect (progn (string-match cider-clojure-compilation-regexp clojure-compiler-warning)
(match-string 1 clojure-compiler-warning))
:to-equal "warning")))
(it "Recognizes a clojure-1.9 error message"
(let ((clojure-1.9-compiler-error "CompilerException java.lang.RuntimeException: Unable to resolve symbol: lol in this context, compiling:(/tmp/foo/src/foo/core.clj:10:1)"))
(expect clojure-1.9-compiler-error :to-match cider-clojure-compilation-regexp)
(expect (progn (string-match cider-clojure-compilation-regexp clojure-1.9-compiler-error)
(match-string 2 clojure-1.9-compiler-error))
:to-equal "/tmp/foo/src/foo/core.clj")))
(it "Recognizes a clojure-1.10 error message"
(let ((clojure-1.10-compiler-error "Syntax error compiling at (src/ardoq/service/workspace_service.clj:227:3)."))
(expect clojure-1.10-compiler-error :to-match cider-clojure-compilation-regexp)
(expect (progn (string-match cider-clojure-compilation-regexp clojure-1.10-compiler-error)
(match-string 2 clojure-1.10-compiler-error))
:to-equal "src/ardoq/service/workspace_service.clj")))
(it "Recognizes a clojure 'Unexpected error' message"
(let ((clojure-1.10-compiler-error "Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1)."))
(expect clojure-1.10-compiler-error :to-match cider-clojure-compilation-regexp)
(expect (progn (string-match cider-clojure-compilation-regexp clojure-1.10-compiler-error)
(match-string 2 clojure-1.10-compiler-error))
:to-equal "src/haystack/parser.cljc"))))
(dolist (regexp (list cider-clojure-compilation-regexp cider-clojure-compilation-error-regexp))
(it "Recognizes a clojure-1.9 error message"
(let ((clojure-1.9-compiler-error "CompilerException java.lang.RuntimeException: Unable to resolve symbol: lol in this context, compiling:(/tmp/foo/src/foo/core.clj:10:1)"))
(expect clojure-1.9-compiler-error :to-match regexp)
(expect (progn (string-match regexp clojure-1.9-compiler-error)
(match-string 2 clojure-1.9-compiler-error))
:to-equal "/tmp/foo/src/foo/core.clj")))
(it "Recognizes a clojure-1.10 error message"
(let ((clojure-1.10-compiler-error "Syntax error compiling at (src/ardoq/service/workspace_service.clj:227:3)."))
(expect clojure-1.10-compiler-error :to-match regexp)
(expect (progn (string-match regexp clojure-1.10-compiler-error)
(match-string 2 clojure-1.10-compiler-error))
:to-equal "src/ardoq/service/workspace_service.clj")))
(it "Recognizes a clojure 'Unexpected error' message"
(let ((clojure-1.10-compiler-error "Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1)."))
(expect clojure-1.10-compiler-error :to-match regexp)
(expect (progn (string-match regexp clojure-1.10-compiler-error)
(match-string 2 clojure-1.10-compiler-error))
:to-equal "src/haystack/parser.cljc")))))

(describe "cider-clojure-runtime-error-regexp"
(it "Recognizes a clojure-1.10 runtime error message"
Expand Down

0 comments on commit 213576e

Please sign in to comment.