Fork me on GitHub
#calva
<
2022-03-22
>
Eva O00:03:21

I've been trying to get Calva to work, but I can't connect to a REPL other than the getting started one. Even the Clojurescript Quickstart REPLs don't work. I've tried this on a number of different projects and I'm not sure what I'm doing wrong.

pez06:03:43

I wonder what could be going on with the ClojureScript Quickstart REPL...

Eva O00:03:01

For one of the projects, I have as a deps.edn

{:paths   ["src/main" "resources"]
 :deps    {org.clojure/clojure               {:mvn/version "1.10.1"}
           binaryage/oops                    {:mvn/version "0.7.0"}
           bk/ring-gzip                      {:mvn/version "0.3.0"}
           com.fulcrologic/fulcro            {:mvn/version "3.2.12"}
           com.fulcrologic/fulcro-garden-css {:mvn/version "3.0.7"}
           com.taoensso/timbre               {:mvn/version "4.10.0"}
           com.wsscode/pathom                {:mvn/version "2.2.31"}
           funcool/cuerdas                   {:mvn/version "2020.03.26-3"}
           hiccup                            {:mvn/version "1.0.5"}
           juxt/crux-core                    {:mvn/version "20.08-1.10.1-beta"}
           mount                             {:mvn/version "0.1.16"}
           org.immutant/web                  {:mvn/version "2.1.10"}
           ring/ring-core                    {:mvn/version "1.8.1"}
           ring/ring-defaults                {:mvn/version "0.3.2"}
           tick                              {:mvn/version "0.4.26-alpha"}}
 :aliases {:dev {:extra-paths ["src/dev" "src/workspaces"]
                 :extra-deps  {org.clojure/clojurescript   {:mvn/version "1.10.764"}
                               org.clojure/tools.namespace {:mvn/version "1.0.0"}
                               binaryage/devtools          {:mvn/version "1.0.2"}
                               nubank/workspaces           {:mvn/version "1.0.15"}
                               thheller/shadow-cljs        {:mvn/version "2.8.109"}}}}}

Eva O00:03:22

Then for shadow-cljs.edn

{:nrepl    {:port 9000}
 :deps     {:aliases [:dev]}
 :dev-http {8000 "classpath:public"}
 :builds   {:main  {:target     :browser
                    :output-dir "resources/public/js/main"
                    :asset-path "/js/main"
                    :modules    {:main {:init-fn prompt.client/init
                                        :entries [prompt.client]}}
                    :devtools   {:after-load prompt.client/refresh
                                 :preloads   [com.fulcrologic.fulcro.inspect.preload
                                              prompt.development-preload]}}
            :cards {:target     nubank.workspaces.shadow-cljs.target
                    :ns-regexp  "-(test|cards)$"
                    :output-dir "resources/public/js/workspaces"
                    :asset-path "/js/workspaces"
                    :preloads   [com.fulcrologic.fulcro.inspect.preload]}}}

Eva O00:03:46

I start shadow-cljs in the terminal using npx shadow-cljs. Then I run "Start or connect to a Clojure REPL" > "Connect to a running REPL in your project" > "deps.edn + shadow-cljs" > "localhost:9000" > ":main". I get the error

Failed starting cljs repl for build: :main. Is the build running and connected?
See the Output channel "Calva Connection Log" for any hints on what went wrong.

Eva O00:03:03

The output says

Socket closed
Socket closed
Execution error (FileNotFoundException) at user/eval5504 (REPL:1).
Could not locate shadow/cljs/devtools/api__init.class, shadow/cljs/devtools/api.clj or shadow/cljs/devtools/api.cljc on classpath.
Socket closed
Socket closed

bringe03:03:02

Hi! Let’s the convo in one thread here. I’m not really familiar with the deps + shadow setup, but I think there has been some confusion around this and there is come improvement that could be added to Calva / the docs regarding this. You might find some helpful info here: https://github.com/BetterThanTomorrow/calva/issues/1591 and @U0ETXRFEW may be able to help more when he’s around.

bringe03:03:42

From that issue: > I think it is due to that shadow-cljs dependencies are assumed to be present. You may be missing a necessary dependency (shadow.cljs.devtools ?), but I couldn’t say at the moment what exactly you need to do.

pez05:03:00

Thanks for posting the deps.edn and shadow-cljs.edn, @UGBKV7HHP. Calva tricks you a bit here. Since you are starting the project using npx shadow-cljs you should connect to it using the shadow-cljs project type. shadow-cljs.edn has :deps {:aliases [:dev]} which will make shadow take care of starting the project using clojure.

pez05:03:21

Your command line for starting the project is not ensuring Calva's dependencies are met, though. Consider using Calva to start the project (a.k.a. Jack-in) or use Calva's command Copy Jack-in command-line to clipboard to get a command line you can use that makes Calva happy.

Eva O13:03:44

Ok I was able to get that project to work using plain "shadow-cljs" rather than "deps.edn + shadow-cljs" thank you

Eva O13:03:22

I have another project I'm trying to get working that doesn't use shadow-cljs. I tried "Start and Project REPL and Connect (aka Jack-in)" > "deps.edn" > "alias :dev". I tried Ctrl+Alt+C+Enter on my user.clj. It doesn't seem to do anything. When I try to Alt+Enter a form, the REPL says

; Syntax error compiling at (src/dev/user.clj:38:3).
; Unable to resolve symbol: start in this context

pez13:03:08

Are you typing Ctrl+Alt+C+Enter or Ctrl+Alt+C Enter?

pez13:03:56

Put another way. If you run the command Load current file and dependencies from the command palette. Does something happen then?

Eva O13:03:53

When I choose that command from the command palette, I get the error:

Command 'Calva: Load Current File and Dependencies' resulted in an error (n.filter is not a function)

pez13:03:27

Hmmm, I've seen that recently somewhere....

Eva O13:03:11

I think all the symbols in my file are defined. Here's the user.clj:

(ns user
  (:require
    [clojure.java.browse :refer [browse-url]]
    [com.walmartlabs.lacinia.pedestal2 :as lp]
    [io.pedestal.http :as http]
    [quiz.core :as quiz]))

(def schema (quiz/load-schema))

(defonce server nil)

(defn start-server
  [_]
  (let [server (-> schema
                   (lp/default-service {:graphiql true})
                   http/create-server
                   http/start)]
    server))

(defn stop-server
  [server]
  (http/stop server)
  nil)

(defn start
  []
  (alter-var-root #'server start-server)
  :started)

(defn stop
  []
  (alter-var-root #'server stop-server)
  :stopped)

(comment
  "Execution error (ExceptionInfo) at com.walmartlabs.lacinia.schema/verify-fields-and-args (schema.clj:1524)."
  "Field `Query/quiz' references unknown type `Quiz'."
  (start)
  (stop))

pez14:03:18

If something breaks before start is defined, then it won't get defined. Maybe (quiz/load-schema) results in an error?. Can you try it with clj on the command line and see what happens? Calva can sometimes hide some error messages (we should fix that):

Eva O14:03:01

I double checked and one of my dependenices was broken. Once I fixed it, that error message went away thanks

Eva O14:03:43

How do you send a form within a comment? I'm using Alt+Enter but I think that's sending the entire comment

pez14:03:04

It should work with Alt+Enter. Also the error you got when start wasn't defined, seems to indicate it worked then....

pez14:03:46

If you paste the comment form... maybe it is something special with it.

Eva O14:03:15

Ok when I Alt+Enter on (start) the REPL says:

; Syntax error compiling at (src/dev/user.clj:38:3).
; Unable to resolve symbol: start in this context

pez14:03:21

Do you still get errors loading the file?

Eva O14:03:14

When I load the file, the REPL says:

; Evaluating file: user.clj
; Execution error (ExceptionInfo) at com.walmartlabs.lacinia.schema/verify-fields-and-args (schema.clj:1524).
; Field `Query/quiz' references unknown type `Quiz'.
; Evaluation of file user.clj failed: class clojure.lang.Compiler$CompilerException

Eva O14:03:52

For some reason, it has part of the text of my comment in it

Eva O14:03:25

Actually when I try to change the text of that comment and load the file again, it still shows the same error. Not sure if it's not loading the changes to my file or if that's a genuine error message

pez14:03:33

Did you write that comment? Seems like documentation..

Eva O14:03:40

I wrote the comment

Eva O14:03:56

I wrote it in the user.clj file

Eva O14:03:08

But it's showing up in the REPL output

Eva O14:03:41

It's a little confusing sorry because it might be a real error and it might be reading out my comment

pez14:03:42

I think it is just the same error.

Eva O14:03:07

Ok if it's just a real error then I know what to do from there. Thanks

pez14:03:13

The messages in your comment there are just strings. You can alt enter on them and see them evaluate to themselves.

pez14:03:52

But when you load the file, the Clojure reader will not evaluate things in the comment form. It is a macro defined like so:

(defmacro comment
  "Ignores body, yields nil"
  {:added "1.0"}
  [& body])
Which means the Clojure Reader will read the forms there, but not evaluate them.

Eva O14:03:17

Ok thanks for all your help

pez14:03:27

You're welcome!

Eva O14:03:57

Yeah I'll def add a review once I've gotten a feel for it

🙏 1
Eva O00:03:18

How do I fix this?

Štěpán Kočí12:03:37

Hi, I am using Calva on the deps.edn + shadow-cljs project. For several days / weeks I have a problem with code navigation, linting, etc. when REPL is running. I have created a minimal project / repo with this problem. I’m not sure if I’m doing something wrong or it’s a bug. Thank you for any help. https://github.com/stepankoci/vscode-calva (project contains readme with my setup and steps to problem reproduction)

pez12:03:43

Thanks for the report and the repro. I’ll have a look.

pez13:03:41

I sent a PR. 😃 Let me know if it works. It's a bit tricky for me to test it right now.

👍 1
Štěpán Kočí13:03:29

Awesome, It’s working! I’m expecting cider/cider-nrepl version should be in sync with version provided by copy jack-in command? Thank you very much!

calva 1
pez13:03:27

> I’m expecting cider/cider-nrepl version should be in sync with version provided by copy jack-in command? Yes.

👍 1
Jakub Holý (HolyJak)14:03:25

In Calva Calva 2.0.256 when I jack-in with deps.edn and do not select any alias, it tries to run clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"0.9.0"},cider/cider-nrepl {:mvn/version,"0.27.4"}}} '-M -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]" which fails with > Missing required argument for "-M ALIASES" Any tips? Should I make a dummy, empty alias and use that one?

Jakub Holý (HolyJak)14:03:42

I do get the list where I can select an alias, it is just that I do not want any of them :)

pez14:03:09

I can't reproduce your error either. I often don't want my aliases. 😃

pez14:03:22

The command you pasted looks a bit funny just before -M. There is a space before the ' instead of after it...

pez14:03:38

When I jack in it looks like

clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version,"0.9.0"},cider/cider-nrepl {:mvn/version,"0.27.4"}}}' -M -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]"
And no complaints.

pez14:03:36

If I run your command line though, it complaints

WARNING: Implicit use of clojure.main with options is deprecated, use -M
And then it starts the REPL anyway.

pez14:03:25

Sorry, tips... Run my command line and see if that works, then connect.

pez14:03:43

And please file an issue about the jack-in. Freaking strange!

Cora (she/her)14:03:35

version info of things would be great, including clojure and jdk

bringe17:03:23

Yes, it could be possible that that’s behavior from an older version of clojure, but I’m not sure. -M does not require the use of aliases.

Jakub Holý (HolyJak)07:03:52

Could be old Clojure indeed. Will explore and get back! Thx!

👍 1
Jakub Holý (HolyJak)19:03:59

You were right! I updated from clojure 1.10.1.619 to 1.10.3.1087 and now it works just fine

metal 2
pez17:03:31

Dear Calva-friends: Here's next version of Calva https://19922-125431277-gh.circle-artifacts.com/0/tmp/artifacts/calva-2.0.257-dev-00abd8b2.vsix The Ux change here is more monorepo convenience when jacking in or connecting to a project. If there are more than one Clojure projects, Calva presents a menu. You can fuzzy search it to quickly find your project if the menu is long. I've been smiling using it at Pitch where we have a lot of projects in the repo and I often need to start three of them in parallell. I can now easily switch which project I am connected to. However, as simple as the change is on the Ux side, it is a major refactor in the code. It was all too stateful and I couldn't build more on top of it. The result is a rebuild of important Calva things and there is now much less statefulness + this feature. Sweet, huh? The catch? Haha, it is that now I hope you help me test it some. I've gone through all use cases I can think of, but there are sure more of them. Be creative please! Thanks to @corasaurus-hex, @domagala.lukas and @brandon.ringe for help with reviewing, suggestions, ideas, and cheering-ons! gratitude ❤️

calva 6
🎉 6
💜 4
bringe17:03:12

Wow that search seems very fast. I tried this out on a polylith work project with several deps.edn files.

❤️ 1
sashton19:03:38

Is there a command I need to run to switch between running repls? I opened two repls, and all evaluations get sent to the second one. I’m guessing I need to switch connections somehow?

pez20:03:34

@U08TWB99B Calva can only be connected to one project at a time, So ”switching repls” means disconnecting from one and connecting to another. But Calva does the disconnect automatically when you connect to another repl, so .... well, try this: Start two repls from projects in the same repo/workspace (outside of Calva, so not jack-in). Then use Calva to connect to one of them. Then connect to the other.

sashton20:03:21

Ok, thanks for clarifying. I’ll give it a try to connect to external repls. But, in the meantime, it’s awesome that I can use Calva in a monorepo now! I’ve been opening individual sub-directories in VSCode until now.

pez20:03:02

To your observation about the speed of the search, @brandon.ringe. It is a glob over all the files in the workspace. On my machine (a Mac M1 Max) it takes about 50-100 ms in the rather huge Pitch monorepo. I'm curious about the performance on less stellar machines. Calva logs the time the glob takes, so anyone reading this is encouraged to report the times printed in the console.

👍 1
pez20:03:50

To avoid searching through large sub directories for naught, the search excludes some known non-project directories, like .git, node_modules, etcetera. This exclusion is configurable via the setting, calva.projectRootsSearchExclude . Docs here: https://github.com/BetterThanTomorrow/calva/blob/dev/docs/site/connect.md#monorepos--multiple-clojure-projects-in-one-workspace

pez20:03:50

To see the impact the exclusion has, remove all entries in that setting and bring up the project root menu.

Eugen08:03:51

I love the new feature 🙂 !!!

calva 1
❤️ 1
bringe19:03:48

See this thread: https://clojurians.slack.com/archives/CBE668G4R/p1647974038051949. Just trying to keep the convo in one place. 😄

😂 1
Cora (she/her)18:03:58

I don't think so, but I'm wondering if you can see anything in the vscode inspector console now? I recently added an assert to that function

👍 1
Charlie Briggs19:03:49

ooo, I raised the original issue - I'll have a check next time it happens! My colleague had the same thing happen today so it could be something at a project level

Cora (she/her)19:03:36

well, the assert should result in a different error, that's all. I'd just like to confirm and see if the message is different

Charlie Briggs19:03:53

sure, I'm just interested (and grateful) to see any progress on this

1
Cora (she/her)19:03:12

it's a side-effect of working towards changing some typescript options (turning on strictNullChecks)

Isac18:03:55

; This is the Calva evaluation results output window.
; TIPS: The keyboard shortcut `ctrl+alt+o o` shows and focuses this window
;   when connected to a REPL session.
; Please see  for more info.
; Happy coding! ♥️
The same message on calva output and nothing different on terminal.

Isac11:03:05

I don't know if it helps, but the same occurred when I tried to connect to a remote repl.