Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Calva by

Is there a way to make Calva: Load/Evaluate Current File and its Requires/Dependencies use a relative path for ClojureScript instead of an absolute path?

I'm connecting to a docker container repl for development and the app is running at /app inside the container. Loading the current file in Clojure works as expected and evaluating things that have already been loaded in ClojureScript works as expected. Loading the current file in ClojureScript fails because it uses the host machine's full path. I get the following error:

; ------ REPL Error while processing ---------------------------------------------
; (cljs.core/load-file "/home/bmaddy/.../model/user.cljc")
; FileNotFoundException: /home/bmaddy/.../model/user.cljc (No such file or directory)

The following all work in the cljs repl as expected:

;; absolute path inside the container
(cljs.core/load-file "/app/src/.../model/user.cljc")
[]
;; relative path from project folder
(cljs.core/load-file "./src/.../model/user.cljc")
[]
(cljs.core/load-file "src/.../model/user.cljc")
[]

I see there are JACK_IN_PROJECT_ROOT_PATH and calva.replConnectSequences.projectRootPath settings, but they don't seem to affect this.

Some version info:
Calva version used: v2.0.474
clojure-lsp version used: 2024.08.05-18.16.00
VSCode Version: 1.93.1
OS: Linux

1 Answer

0 votes
by
edited by

Hello. I don't think there is a way to configure that currently. You are welcome to file an issue about it. We can probably make this work.

Meanwhile.

Is shadow-cljs or Figwheel managing the loading of the project? If so, saving the file should load it .

Also, I think you most often get away with selecting the whole file and evaluate selection. You can configure a keyboard shortcut like this to give yourself something quite similar to the command that doesn't work:

  {
    "command": "runCommands",
    "key": "ctrl+alt+c ctrl+alt+enter",
    "args": {
      "commands": [
        "editor.action.selectAll",
        "calva.evaluateSelection",
        "cursorUndo"
      ]
    }
  },

You can add a when clause to it to only operate on cljs files. I think it would be resourceExtName == .cljs. See https://code.visualstudio.com/api/references/when-clause-contexts

That said, it's probably fine to let it load Clojure files this way as well. You can copy the existing when clause from the command in the in Keyboard Shortcuts UI.

...