Can someone help me diagnose why Calva isn’t able to find definitions in my own code? I have (as far as I know) successfully jacked-in, but Calva claims to be unable to find definitions of any of the functions in the project itself (although it does successfully find definitions in libraries that I’m using. I can’t see any error messages anywhere (but perhaps I’m not looking in the right place?). Thanks in advance!
Have you loaded the file?
The fact that I’m not sure what you mean by “have you loaded the file” suggests that I’m missing something pretty crucial :rolling_on_the_floor_laughing:. I’ve jacked-in and the file is open in the editor. What else do I need to do?
Oh! Sorry - I’ve just found it (and yes, it’s almost the first bit of the documentation so I don’t know how I missed it).
I think that what was foxing me was that things seemed to work without loading a file. If I create a brand-new project with lein new
, open it and jack-in (without loading the file) then I can see definitions. So I was expecting that that would always work.
Stupid question time - is there any reason why Calva doesn’t load files automatically when they’re opened within the editor?
I've noticed that things sometime work a bit w/o loading the file. I'm not quite sure why, but maybe nrepl needs to load some stuff while it is starting.
As to your totally valid question about why the files are not auto-loaded. It is because the files can contain about anything and evaluating them might start whatever resource hungry processes. We have decided that it must be the user who is in control about when and what to evaluate, and opening a file should not have such effects. I have considered making it an option, but that still wouldn't help new users, because they need to figure it out and find the option. It's quite an Ux dilemma. We should probably inform about the file load in the repl window when jacking in as well. Cover more bases...
Also when we see that someone tries to peek definitions and stuff and it fails we could hint about loading the file...
OK - that makes sense. How about putting “have you loaded the file (Ctrl-Alt-C, Enter)?” after the “No definition found” error message?
Snap!
Haha, in my family we say Gammelsmurf (Papa Smurf) in these situations. I don't know why, but when two people think the same thing, it is said. 😃
Sorry - I’ve just realised something. Does that mean that loading the file is executing the file? So any top-level code is actually run?
Is there no way to get the definitions (and associated docstrings etc) out of a file without kicking off potentially disastrous side-effects?
That would leave you in the same place with the situation in the screenshot, right?
Sorry - not sure I understand?
The thing is that in Calva the definition lookup is dynamic. Things need to be evaluated to be seen.
We do want to support static analysis, but it has so far not been something we have found the time to do. If you check this thread you'll fins a dev build of Calva that doesn't need to load files to peek at definitions:
OK, got it. That’s a wrinkle which really didn’t occur to me. I know that code is executing when I do Ctrl-Enter, and obviously I need to worry about side-effects then. But it never occurred to me that loading a file so that I could automatically cross-reference definitions would do the same.
This link: https://clojurians.slack.com/archives/CBE668G4R/p1603978340028200
That looks encouraging!
It needs some serious code design skills to pull it together neatly, I think. I'm hoping we can pick thee brains of @brandon.ringe and @stefan.van.den.oord to form a good plan.
Dear Calva-friends, v2.0.131 is out, containing the QA fixes to parsing and syntax highlighting that I've previously mentioned. Please upgrade. And big thanks to @sogaiu for the help with spotting the glitches, and reporting in such an actionable manner. :calva: ❤️ :calva: ❤️
And always keep in mind that a review of Calva is a way to help the project: https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva#review-details