Skip to content

Support for multi src path analysis #28

@mfikes

Description

@mfikes

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:

  1. The :root in 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 be src/cljs/.
  2. For projects that have multiple roots (:source-paths per lein-cljsbuild) a separate analysis needs to be done for each distinct root. Thus, Weasel would need to accomodate a :src-paths option in lieu of its current :src option.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions