-
Notifications
You must be signed in to change notification settings - Fork 32
Description
When I piggyback into the Weasel REPL, many "false-positive" code analysis warnings are emitted. These are mostly of the form "Referred var some.namespace/var-name does not exist," but other similar warnings are emitted. Nothing breaks for me, and the REPL functions.
This occurs when (cljs.repl/analyze-source (:src this)) is called from within weasel.repl.websocket/websocket-setup-env.
I've traced the root cause down to an inability of the ClojureScript compiler to locate the source of dependent namespaces to analyze. To fix this appears to require two changes:
- The
:rootin the ClojureScript compiler environment needs to be set to the source root. This root needs to follow the JVM classpath convention. In other words it needs to be precisely at the level containing the namespace directories. Using the weasel project structure itself as an example, this would besrc/cljs/. - For projects that have multiple roots (
:source-pathsperlein-cljsbuild) a separate analysis needs to be done for each distinct root. Thus, Weasel would need to accomodate a:src-pathsoption in lieu of its current:srcoption.
With a :src-paths option, if I replace (cljs.repl/analyze-source (:src this)) with the following form
(let [compiler-env (::env/compiler this)
previous-root (:root @compiler-env)]
(doseq [src-path (:src-paths this)]
(swap! compiler-env assoc :root (File. src-path))
(env/with-compiler-env compiler-env
(cljs.repl/analyze-source src-path)))
(swap! compiler-env assoc :root previous-root))then piggybacking into Weasel works without any "false-positive" warnings, and if you inspect the ClojureScript compiler's behavior, you can see that it succeeds in loading dependent namespaces and analyzing them.