clojure-emacs / refactor-nrepl

nREPL middleware to support refactorings in an editor agnostic way
Eclipse Public License 1.0
256 stars 69 forks source link

Refactor nrepl is failing to build AST for certain valid entries in the code #389

Closed rmuslimov closed 1 year ago

rmuslimov commented 1 year ago

Issue

refactor-nrepl is failing to build AST tree for valid clojure case. Issue occurs when user works with external lib (pronto)

Expected behavior

  1. Add pronto defmapper definition to code (https://github.com/AppsFlyer/pronto)
    (p/defmapper user-mapper [com.plato.proto.Common$User])
  2. Run "cljr-rename-symbol" for any entry in the code.
  3. Notice that generation fails with exception
    at nrepl.middleware$wrap_conj_descriptor$fn__13594.invoke(middlERROR: Unhandled REPL handler exception processing message {:dir /Users/rmuslimov/workspace/plato/, :prefix-rewriting true, :ns plato.adapters.morse.core, :name show-keyboard, :file /Users/rmuslimov/workspace/plato/src/main/clj/plato/adapters/morse/core.clj, :ignore-errors [], :debug false, :op find-symbol, :column 11, :insert-newline-after-require true, :line 18, :id 110, :session fa62cd2e-3b1e-4727-9ab5-92a53221a587}
    java.lang.IllegalStateException: refactor-nrepl is unable to build an AST for plato.lib.storage.user. tools.analyzer encountered the following problem: Params must be valid binding symbols, had: [clojure.lang.Symbol]
    at refactor_nrepl.analyzer$throw_ast_in_bad_state.invokeStatic(analyzer.clj:111)
    at refactor_nrepl.analyzer$throw_ast_in_bad_state.invoke(analyzer.clj:108)
    at refactor_nrepl.analyzer$ns_ast.invokeStatic(analyzer.clj:127)
    at refactor_nrepl.analyzer$ns_ast.invoke(analyzer.clj:115)
    ...

Actual behavior

Supposed to work since clojure code is valid.

Environment & Version information

clj-refactor.el and refactor-nrepl version information

clj-refactor 3.6.0 (package: 20221023.1644), refactor-nrepl 3.6.0

CIDER version information

Include here the version string displayed when CIDER's REPL is launched. Here's an example:

;; CIDER 1.6.0-snapshot (package: 20221208.1801), nREPL 1.0.0
;; Clojure 1.11.1, Java 19.0.1

deps.edn version

{:deps {io.github.clojure/tools.build {:git/tag "v0.8.1" :git/sha "7d40500"}}

Emacs version

GNU Emacs 28.2 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 10.14.6 (Build 18G95)) of 2022-09-12

Operating system

Macos Ventura 13.01

vemv commented 1 year ago

Thanks for the report!

If you provide a reproduction git repo, I'll be able to attend it swiftly. I don't know what a com.plato.proto.Common$User is, and similarly I've never worked with protocol buffers.

Cheers - V

vemv commented 1 year ago

Hmmm, I can repro this by running refactor-nrepl on a https://github.com/AppsFlyer/pronto checkout.

vemv commented 1 year ago

I found the issue, it's rather simple: https://github.com/AppsFlyer/pronto/issues/14

rmuslimov commented 1 year ago

Hi @vemv! I'm impressed with your "speed of sound" response to the issue and diligence on find root of the issue. Thank you!