Fork me on GitHub
#calva
<
2020-11-05
>
paulbutcher16:11:15

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!

pez17:11:49

Have you loaded the file?

paulbutcher17:11:07

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?

paulbutcher17:11:56

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.

paulbutcher17:11:16

Stupid question time - is there any reason why Calva doesn’t load files automatically when they’re opened within the editor?

pez18:11:21

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.

pez18:11:26

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...

pez18:11:48

Also when we see that someone tries to peek definitions and stuff and it fails we could hint about loading the file...

paulbutcher18:11:53

OK - that makes sense. How about putting “have you loaded the file (Ctrl-Alt-C, Enter)?” after the “No definition found” error message?

pez18:11:31

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. 😃

paulbutcher18:11:00

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?

paulbutcher18:11:25

Is there no way to get the definitions (and associated docstrings etc) out of a file without kicking off potentially disastrous side-effects?

pez18:11:17

That would leave you in the same place with the situation in the screenshot, right?

paulbutcher18:11:00

Sorry - not sure I understand?

pez18:11:47

The thing is that in Calva the definition lookup is dynamic. Things need to be evaluated to be seen.

pez18:11:18

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:

paulbutcher18:11:25

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.

paulbutcher18:11:20

That looks encouraging!

pez18:11:55

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.

🤞 3
pez19:11:38

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 ❤️

calva 6
pez19:11:11

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