This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-02
Channels
- # announcements (2)
- # aws (7)
- # babashka (47)
- # beginners (54)
- # biff (6)
- # calva (14)
- # clojure-europe (7)
- # clojure-germany (2)
- # clojure-japan (4)
- # clojure-norway (5)
- # datalevin (1)
- # deps-new (13)
- # helix (5)
- # hoplon (1)
- # hyperfiddle (12)
- # introduce-yourself (6)
- # joyride (1)
- # malli (2)
- # off-topic (21)
- # polylith (11)
- # re-frame (3)
- # reitit (8)
- # remote-jobs (1)
- # scittle (25)
- # shadow-cljs (20)
- # vim (19)
- # xtdb (4)
I have a record in a file that I'm trying to refer to in another file:
;; src/pkg/foo.clj
(ns pkg.foo)
(defrecord Foo [bar])
;; src/pkg/bar.clj
(ns pkg.bar
;; I want to refer to pkg.foo/Foo here
)
I've tried (:require pkg.foo :refer [Foo])
, but that errors? (:require pkg.foo :as foo)
and referring to Foo
as foo/Foo
works, but I'd rather avoid that if possible...I think that, since defrecord creates a class, it's necessary to import it rather than requiring it
It depends how you want to refer to it - if you need the type, then yes you should import pkg.foo.Foo as a class
If you want to use the constructors or functions, then you just require and use as with any other function
I wanted to use them in type hints
Then yes, import the class
Thanks!
Is there a way to make “go to definition” work with symbols to external libraries in calva / VSCode? Similiar to what is possible with Cursive? Eg I added ring to my deps.edn. Now I use ring/wrap-defaults in my code. I want to jump to the source of ring/wrap-defaults with “go to definition”. However, I get an error “definition not found”.
I’m using the polylith setup. Maybe this as an influence? If not: Any idea, where I can start looking for some misconfiguration?
Polylith setup should work. Maybe I don’t fully understand what is working and what is not working for you. Can you navigate to any library symbol?
short update. Now it works. Some plugin ran with 100 % cpu usage and created an enormous amount of lack. Disabling some plugins and restarting solved the problem. Thanks for your help. I really appreciate it 🙂
Noticed some more detail:
;in a source file of my project
(ns :require [some.3rd.partylib] ;go to definition works
[someother.3rd.partylib]) ;go to definition works
;in some.3rd.partylib
(ns :require [someother.3rd.partylib]) ;go to definition does not work. symbol not found
So basically symbol resolution does work from within my own source files, but not within external source files. Is this expected behaviour?Thanks for the update! Could you share what extension was causing the cpu congestion and what extensions you found problematic otherwise. @U09K620SG ran into similar problems and maybe we ca find a pattern, or at least start to collect information to help with getting a workable VS Code setup.
As for your 3rd party lookup observation. In some situations it is to be expected, in some not. Without knowing your situation I don’t know if you have identified a bug or an expected limitation. I can speculate, though, so let’s! We know this about Calva and the tooling it relies on:
• It uses both clojure-lsp and nrepl for lookup.
• By default it consults nrepl first, then clojure-lsp (this is configurable)
• clojure-lsp will exhibit the behaviour you describe (afaik)
• nrepl needs to have evaluated a namespace in order to lookup its dependencies (or some other namespace with the same dependency)
• Once nrepl has evaluated a namespace bringing in some.3rd.partylib
it will be able to lookup some.3rd.partylib
’s dependencies too.
So, I’d say that:
• if you are not connected to the REPL, then the behaviour is expected.
• if you are connected to the REPL, but haven’t evaluated a namespace which “brings in” some.3rd.partylib
, then it is also expected (and navigating to some.3rd.partylib
will work because clojure-lsp.
• if you are connected to the REPL and have evaluated a namespace bringing in some.3rd.partylib
, then the behaviour is not expected.
I hope this makes sense. I think it is independent on your configuration of which lookup service to consult first. At least if things are working as they should.
Thanks for your response. Regarding the plugin. Unfortunately, I can’t tell, I had a ton of plugins (most of them for python and .net). And I removed them in one go without much in between testing.
As for the 3rd party lookup:
I am connected to the repl.
I can reach some.3rd.partylib if I am requiring from my own source. I cannot go to any definition from within some.3rd.partylib file*.*
One example:
some.3rd.partylib requires clojure.pprint
.
I can jump to pprint, if I require it in my own ns and I am in that file.
If I am in file some.3rd.partylib, then I cannot jump to the definition of pprint.
I evaled some.3rd.partylib. It does not work. No jump possible.
I evaled clojure.pprint (by requiring it from my own ns and jumping to the definition). It does not work, neither.
Interesting. What’s your setting for definition lookup priority? (Searching for priority in settings should find it for you)
Thanks, As I said, it shouldn’t matter, but just to know where we are. Can you enable the nREPL message log? It’s a command in Calva, i don’t quite remember the name, but you should find it in the command palette under Calva Diagnostics. It’s a log of messages between Calva and the nREPL server. We should be able to compare the messages for the lookups that succeed with those who fail and maybe that can tell us something.
I enabled and checked the message log. I see no messages. Neither for succeding nor for failing lookups. Does this mean, that clojure-lsp is used and not the repl?
That would be consistent with the observed lookup behaviour… Do you see any messages if you evaluate something?
I am using the deps.edn from Sean Corefield. I start the repl with:
clj -A:add-libs:portal:nrepl:dev/repl:dev
Can you test if lookups work if you let Calva start the REPL? There’s a command for that in Calva, searching for Jack-in in the command palette should find it for you.
Like you described. Without eval -> symbol not found. after eval of the http://3rd.party file -> jump to the definition works
Can you post the nrepl alias from the project deps.edn here? I get curious why it fails to satisfy Calva’s requirements.
{:extra-deps {nrepl/nrepl {:mvn/version "RELEASE"}}
:main-opts ["-m" "nrepl.cmdline"]}
Thanks. So it lacks cider-nrepl. @U04V70XH6 I guess it tells us one of the things that requires cider-nrepl to work. Strange as it sounds to me. @U023LKF2PQV When you connect Calva the way you do without jack-in, do you get a warning about that Calva’s requirements are not met? It would look like so:
I get this warning. I did not notice this before or did not pay attention to it because the rest of Calva worked fine.
You are not the first who do not connect the problems with the warning. We need to figure out how to make this clearer.
Anyway, if you prefer to start the repl yourself, @U023LKF2PQV, Calva has a command for copying out the command line it uses to start the REPL. something Copy Jack-in something in the command palette. But if you are fine with letting Calva start the REPL, I recommend that.
@U023LKF2PQV This is why my dot-clojure deps.edn
has a :cider-nrepl
alias too: https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn#L65-L67
(given how you're starting your REPL, I assume you're using some variant of my deps.edn
file? 🙂 )
how do I easily build a vector without repeating myself? I don't want to have to write ["a" "a" "a" "b" "b" "c"]
but do something like [(repeat 3 "a") (repeat 2 "b") "c"]
but how do I flatten the seqs?
`[~@(repeat 3 "a") ~@(repeat 2 "b") "c"]
could be one way?or simply (flatten [(repeat 3 "a") (repeat 2 "b") "c"])
if its a specific structure
flatten gives back a seq, if that matters
oh yeah I tried the last one but "a"
can actually be a seq itself in the vec I'm building, which gets rid of that
the first one should work then, its a bit low level but gives a lot of control
@ULS5BHEUR thanks, that's what I'll actually go for 🙂
or (into [] cat [(repeat 3 "a") (repeat 2 "b") ["c"]])
which will make sure you have a vector at the end