Fork me on GitHub
#calva
<
2021-08-06
>
p-himik13:08:07

Trying to use shadow-cljs with deps.edn and make the CLJS REPL work while also being able to navigate to symbol definitions. Struggled a bit since the default deps.edn + shadow-cljs project type didn't work - had to search through GitHub issues for Error while connecting cljs REPL: TypeError: Cannot read property 'search' of undefined to find that there's a way to use shadow-cljs via deps.edn. But that didn't work because I can't evaluate CLJS files there, even after running (shadow/repl :main). Seems like just shadow-cljs project type works, although it doesn't like that -d option, so I added the dependency from it to my deps.edn. Now I can evaluate the CLJS file. Although using Go To Definition sometimes works as intended and sometimes just jumps to a seemingly random line in the ns declaration. With that many problems at every stage of the process - is there a bare bones project that: • Uses shadow-cljs.edn with :deps set to something • Uses CLJS REPL (ideally alongside with a CLJ one) • Allows for robust symbol navigation • Makes it possible to evaluate whole files (not needed if the symbol navigation works just fine without it) ?

ericdallo14:08:24

> Allows for robust symbol navigation Question, does that works without the REPL? as I suppose Calva will use only clojure-lsp

p-himik14:08:13

In one of the issues on GitHub, I have read that if it doesn't work then evaluating the whole file should make it work.

p-himik14:08:46

> You don't need to do anything to start clojure-lsp. No install, no commands, no nothing And that's exactly what I did. :) Seems like it didn't help.

ericdallo14:08:57

What happens when you try to go to definition only using clojure-lsp? Did clojure-lsp start correctly for you (you can check the troubleshooting section)

p-himik14:08:11

Just restarted VSCode and noticed that initializing LSP server status in the bar below. Perhaps it didn't work before only because I was trying to navigate to a symbol while it was still running - it takes quite some time with an almost empty project. It doesn't help that the pop-up then says "No definition found for 'x'" instead of something like "Wait for the LSP initialization to complete".

p-himik14:08:03

Alright, it seems to be reliable right now. Thanks!

ericdallo14:08:36

@U2FRKM4TW the very first time show analyze the whole project + external deps (for cljs usually this take a little more because cljs libs has a lot of more libs)

ericdallo14:08:59

the next time, clojure-lsp uses external analysis cache, only analyzing your project code, which usually is fast for medium/small projects

ericdallo14:08:44

> "Wait for the LSP initialization to complete" Yeah, probably something to be improved on vscode side, as this request was not sent yet to clojure-lsp as it didn't start yet.

p-himik14:08:51

Makes sense! Took around 6 seconds this time. Not sure why the previous took 20+, given that it wasn't the first time either.

ericdallo14:08:59

probably you changed your deps/shadow file, then clojure-lsp needs to recheck for extra deps

p-himik14:08:17

Oh, I see.

p-himik15:08:21

That's still imperfect - jumping to definitions used in CLJC files always defaults to the :clj path, it seems. Maybe you know a way to go to a file/namespace that's defined within a jar? At least I would be able to navigate to some of the symbols myself.

ericdallo15:08:56

hum, I didn't understand the issue, could you elaborate with a repro/sample?

ericdallo15:08:12

also, feel free to open an issue on clojure-lsp https://github.com/clojure-lsp/clojure-lsp/

p-himik15:08:51

I'm hesitant to start opening issues just yet since it still might be me missing something that's actually there. :) I'm trying to get started with quil. Here's a namespace declaration from one of its files:

(ns ^{:doc "Wrappers and extensions around the core  API."}
 quil.core
  #?(:clj
     (:import [processing.core PApplet PImage PGraphics PFont PConstants PShape]
              [processing.opengl PShader]
              [java.awt.event KeyEvent]))
  #?(:clj
     (:require quil.sketch
               [clojure.set]
               [quil.helpers.docs :as docs]
               [quil.util :as u]
               [quil.applet :as ap])

     :cljs
     (:require clojure.string
               cljsjs.p5
               [quil.sketch :as ap :include-macros true]
               [quil.util :as u :include-macros true])))
If I go to the definition of quil.sketch mentioned above in both :clj and :cljs branches, I will always be directed to the definition in sketch.clj, so I cannot see what's going on in sketch.cljs. And Go to File... doesn't list files in jars, so I can't navigate to sketch.cljs manually.

p-himik15:08:07

And, of course, there's no Reveal in Side Bar context menu option for an editor tab for a file from a jar, so I can't just browse a jar as well. Although this has more to do with Java rather than Clojure.

ericdallo15:08:58

Yeah, I can confirm this is a issue, I think it's related with you only having opened previously the sketch.clj so clojure-lsp has only that file available

ericdallo15:08:08

it's a bug related with jar definitions indeed

ericdallo15:08:39

feel free to open an issue, with a repro as minimal/simple as possible

ericdallo15:08:53

clojure-lsp has indeed somethings to improve related with .cljc files

ericdallo15:08:17

I confirmed it works if you already opened sketch.cljs before, so the bug it's related with clojure-lsp doesn't know there is another file with that definition for other lang

p-himik15:08:45

But how did you open sketch.cljs in the first place?

ericdallo15:08:24

I added quil.sketch in a .cljs file and tried to go to definition, it was just to confirm my guess

p-himik15:08:25

Ah, right.

ericdallo15:08:05

TLDR, it's an issue with definition navigation inside jar files

ericdallo15:08:23

navigating from/between your source code should cause no issues

ericdallo16:08:40

Found the bug and how to fix 🙂

p-himik16:08:32

And just plain navigation to files within jars has nothing to do with clojure-lsp, right? I'd think it's a purely Calva feature.

ericdallo16:08:41

yeah, I don't know anything about that feature, probably a vscode thing, not a Calva feature 😕 Maybe @U9A1RLFNV knows about it

pez16:08:10

I thought both clojure-lsp and nrepl helped with that.

bringe16:08:19

I think they both do

pez16:08:42

Or maybe I don’t understand what “plain navigation to files within jars” mean. If you have a jar path and navigate to that, then it is VS Code built in behaviour.

bringe16:08:50

Ah, yeah if we aren't talking about go-to-definition, then what I said is not relevant.

pez16:08:46

I’m sorry for the inconvenience with the shadow-cljs + deps.edn configuration, @U2FRKM4TW. It has been broken a while. I should fix it or remove it.

bringe16:08:09

Awesome response+fix time @UKFSJSM38 👏

thanks 3
🚀 3
☝️ 3
pez16:08:26

Honestly, I have forgotten what that configuration is supposed to do.

p-himik16:08:24

Thanks! Yeah, I was talking about Go to File... when it comes to jars, sorry for the confusion.

pez10:08:45

I created an issue for the project config confusion: https://github.com/BetterThanTomorrow/calva/issues/1253

pez17:08:30

New Calva out, @U2FRKM4TW. It just removes the confusing shadow-cljs + deps.edn config. And Thomas Heller fixed that confusing warning. And I think the issue you found with CLJC files also is fixed now. Would you say that all issues you raised are fixed now?

p-himik18:08:50

Awesome, thanks! Seems like they are, yes!

pez10:08:39

Great! Thanks for reporting. For many things it takes fresh eyes to see the flaws.