sam-pitch / macro_example

0 stars 1 forks source link

Could be a Calva issue #1

Open PEZ opened 2 years ago

PEZ commented 2 years ago

I'm not completely sure about why this happens like it does, but jotting down my thoughts so maybe we can figure it out together.

Some background:

  1. When Calva connects to a ClojureScript REPL it will first connect to the Clojure REPL and establish an nREPL session. Then it clones this session and ”promotes” the clone to a ClojureScript nREPL session. Note that we now have two CLJ sessions: CLJ1 while be used for Clojure files, and CLJ2 (promoted to CLJS) will be used or ClojureScript files.
  2. Calva also has a CLJC session ”pointer” which will point to CLJ1 by. default. (This pointer can be toggled by the user by clicking the cljc/clj button in the statusbar.)

When you load example.cljc it will compile the macro in CLJ1. Then when you load core.cljs it will compile the macro using CLJ2. Then you update the file and recompile the macro in CLJ1 by loading example.cljc. Then you load core.cljs which doesn't seem to recompile the macro. I don't know why.

I tried this: I toggled the CLJC pointer to be cljc/cljs and then I get the expected results loading files in the order

  1. example.cljc (recompiles the macro using CLJ2)
  2. core.cljs

But if I load core.cljs first the recompile doesn't happen.

So, maybe it is generally the case that loading a .cljs file does not trigger a recompile of macros... This could be a Calva bug, but I don't recall any code in Calva that cares about wether a file is .cljc or .cljs. It just has this mapping of file-extension -> nrepl-session and sends the nREPL op to the session it picks up.

I'll investigate it a bit further and see what I can figure out.

PEZ commented 2 years ago

OK. So it seems to be shadow-cljs that doesn't recompile the macro when loading a .cljs file. I tried this:

$ npx shadow-cljs watch :app
------------------------------------------------------------------------------

   WARNING: shadow-cljs not installed in project.
   See https://shadow-cljs.github.io/docs/UsersGuide.html#project-install

------------------------------------------------------------------------------
shadow-cljs - config: /Users/pez/Projects/tests/sam-macro-weirdness/shadow-cljs.edn
shadow-cljs - starting via "clojure"
[2022-03-31 14:25:09.939 - WARNING] TCP Port 9630 in use.
[2022-03-31 14:25:09.962 - WARNING] TCP Port 9631 in use.
[2022-03-31 14:25:09.983 - WARNING] TCP Port 9632 in use.
[2022-03-31 14:25:12.742 - WARNING] TCP Port 8000 in use.
shadow-cljs - HTTP server available at http://localhost:8001
shadow-cljs - server version: 2.17.8 running at http://localhost:9633
shadow-cljs - nREPL server started on port 7999
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build completed. (128 files, 0 compiled, 0 warnings, 4.11s)

Loaded http://localhost:8001 in the browser, then:

% npx shadow-cljs clj-repl
------------------------------------------------------------------------------

   WARNING: shadow-cljs not installed in project.
   See https://shadow-cljs.github.io/docs/UsersGuide.html#project-install

------------------------------------------------------------------------------
shadow-cljs - config: /Users/pez/Projects/tests/sam-macro-weirdness/shadow-cljs.edn
shadow-cljs - connected to server
shadow-cljs - REPL - see (help)
To quit, type: :repl/quit
shadow.user=> (shadow/repl :app)
cljs.user=>  (load-file "src/core.cljs")
[]
cljs.user=> (in-ns 'core)
nil
core=> e/bar
4
> 

Then:

  1. Killed both shadow-cljs processes
  2. updated short.txt to be 8 character in length
  3. Repeated the above npx shadow-cljs sessions.

I expect: e/bar => 8 I get: e/bar => 4

Wiping .shadow-cljs and repeating the processes, I get e/bar => 8.

Why it works with example.cljc in Calva connected to that CLJ2/CLJS session, I don't quite understand, but at least you have a workaround there, @sam-pitch.

PEZ commented 2 years ago

Hmmm, could the difference between loading example.cljc and core.cljs here be not the file extensions, but rather the inderection? example.cljc is defining the macro...