nrepl / nrepl/weasel

Support for multi src path analysis

Open
#28 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
323
Forks
31
PR merge metrics
No merged PRs in 30d

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:

  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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at weasel.repl.websocket/websocket-setup-env and trace its call to cljs.repl/analyze-source, then review the compiler environment handling described in the issue. Support a :src-paths option and analyze each source root while preserving the previous compiler root; done means dependent namespaces load without the reported false-positive warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.