Calva: "No definition found" on _some_ of my local CLJS requires

Created on 25 Oct 2019  路  19Comments  路  Source: BetterThanTomorrow/calva

Hello,

I'm using vs code 1.39 on linux, using extenstions calva 2.0.53, Clojure linter (Joker) 0.0.2 and Clojure Lint 0.5.0. Running simple learning/hacking reframe project based on reframe leiningen template (so combination of clj+cljs).

Running the project directly from vs code using calva's cider-jack-in (Leiningen + shadow-cljs):

Executing task: lein update-in :dependencies conj '[nrepl"0.6.0"]' -- update-in :dependencies conj '[cider/piggieback"0.4.1"]' -- update-in :dependencies conj '[cider/cider-nrepl"0.22.4"]' -- update-in :plugins conj '[cider/cider-nrepl"0.22.4"]' -- update-in '[:repl-options :nrepl-middleware]' conj '["cider.nrepl/cider-middleware"]' -- update-in '[:repl-options :nrepl-middleware]' conj '["cider.piggieback/wrap-cljs-repl"]' -- with-profile +dev dev <

I have following :require statements in my view.cljs file:

(ns some-package-reframe.views
  (:require
   [re-frame.core :as re-frame]
   [some-package-reframe.subs :as subs]
   [some-package-reframe.events :as events]))

When I navigate to line with events namespace require, I'm able to either ctrl+click the link or press F12 and events.cljs file is opened. Correct behavior here. But I'm not able to do the same on subs namespace. It doesn't render as link when i ctrl-mouse-hover over it, and F12 keypress yields "No definition found for 'some-package-reframe.subs'" message.

It's really strange that some of my local namespaces works, some not. Mentioned subs.cljs file is happily sitting in the same directory as events.cljs. subs.cljs file can be opened manually, loaded/evaluated etc. in the same way as events.cljs. No obvious difference in namespace definition. But it just doesn't want to be ctrl+clicked from other namespaces' require statements.

Any hint regarding what to perform/check welcomed. Is there perhaps some debug-logging which might shed some more light on the issue?

upstream

All 19 comments

Hello, That sounds very strange. Have you loaded the file that requires these namespaces?

Very strange indeed. Yes, I tried manually loading all those files/namespaces - both "requiring" and "required" - (using ctrl+alt+c Enter) switching to them etc. with no effect whatsoever.

If you can cook a reproduction project that we can look at, that would great.

Understood. If I find some spare time, I'll try to prepare something during the weekend.

Hello. I guess I finally managed to reproduce the issue from scratch. It's quite simple, actually. Not sure if the behavior I'm going to describe is a feature or a bug, but for me it's confusing at least.

So here we go (feel free to skip first 4 steps, the important stuff is in steps 6-8):

1) created fresh new project using

lein new re-frame dummy-project-reframe +cider +handler +10x +routes +test
cd dummy-project-reframe
code .

2) once loaded, I performed cider-jack-in using ctrl+alt+c ctrl+alt+j.

  • used Leiningen + shadow-cljs
  • used dev alias
  • used :dev profile
  • (waited some 20s until final popup appears)
  • used :app build to connect to
    (both CLJ and CLJS repls says they're connected; CLJS repl doesn't resolve anything since no browser is connected yet - cannot evaluate any expressions)

3) waited until TERMINAL tab mentioned [:app] Build completed. (528 files, 527 compiled, 0 warnings, 37.72s)

4) opened http://localhost:8280

  • app skeleton is succesfully loaded and fully works
  • calva CLJS REPL in VS Code works, can now evaluate expressions

5) opened events.cljs file. All 3 imports (re-frame.core, dummy-project-reframe-db and day8.re-frame.tracing) can be ctrl+clicked.

6) opened routes.cljs. goog.events cannot be ctrl+clicked as well as dummy-project-reframe.events.

  • tried to Load current file and dependencies command on routes.cljs, no change.
  • tried Load current file and dependencies on events.cljs, no change

7) added (def foo 42) to events.cljs, saved the file.. and.. voila! I can now ctrl+click events import in routes.cljs and other locations!

8) when I remove (def foo 42) and save the file, dummy-project-reframe.events imports are not clickable again.

So it seems to me that there needs to be at least some def or defn present in the file. If there's none, calva will simply not render the import as clickable, nor will it allow F12. I don't like this behavior, it's a bit confusing and feels like a bug.

What's funny is that when I register for example following subscription in subs.cljs...

(re-frame/reg-sub
 ::blahblahblah
 (fn [db _]
   (:blahblahblah db)))

... then later when editing views.cljs, calva will actually offer me a valid code-completion to ::subs/blahblahblah when I enter just partial namespaced key ::subs/. So calva/cider must actually know that the subs namespace is there. Still, the import definition is not clickable unless I put some def or defn into subs.cljs.

Can this be improved somehow?

Thanks for the detailed reproduction steps! This sounds like a bug in Calva, but I say so before having investigated it. Which I will do now. Cheers!

Now I've had a look. Seems that the problem is in cider-nrepl. I'll dig some more and see if we can hope to get this fixed.

@brdloush @PEZ

Can you test the issue with version 2.0.57 please?

  1. opened routes.cljs. goog.events cannot be ctrl+clicked as well as dummy-project-reframe.events.

The namespace dummy-project-reframe.events is resolved immediately after opening the file but the namespace goog.events returns no-info and therefore is not clickable.

And when I try to load either of the files I get the following error:

no source by id: [:shadow.build.classpath/resource "dummy_project_reframe/routes.cljs"]
{:id [:shadow.build.classpath/resource "dummy_project_reframe/routes.cljs"]}
ExceptionInfo: no source by id: [:shadow.build.classpath/resource "dummy_project_reframe/routes.cljs"]

But this could be me not knowing what I do with shadow-cljs.

@brdloush @PEZ

Kind of fanny the loading errors may be a Windows problem. If I use WSL the loading works and the behavior is as described above. All namespaces are immediately "visible" except of goog.events which is not even not after loading the file.

This won't work until this PR is pulled in the orchard library, and a new cider-nrepl is released with the fix, and a new Calva is released with the new cider-nrepl.

Poke @bbatsov to do that first merging. 馃槃

All namespaces are immediately "visible" except of goog.events which is not even not after loading the file.

Yeah, goog.events is out of reach until someone super duper smart solves that problem.

@PEZ

Top!

Hi, I'd just like to ask what's the status of this issue right now.

If I understood correctly, mentioned PR to orchard has already been merged and cider-nrepl also seems to use latest orchardversion. So the last link of the chain is calva itself, or are we still missing some merges/version bumps in dependencies?

Is there anything to be tested right now?

Hmmm, not sure. Calva is using cider-nrepl 0.22.4 which doesn't seem to pull in latest orchard, right? Maybe @bbatsov can cut a new release?

But, maybe first you can try this, @brdloush .

  1. Jack in to your project.
  2. Press ctrl+c when the terminal pops up with the jack-in command line.
  3. Copy the command line and edit it to use cider-nrepl 0.23.0-SNAPSHOT.
  4. Execute that command line in a terminal, from your project root.
  5. Calva will continue the jack-in procedure once the nREPL server is started (because of a bug, but anyway).
  6. Verify that the problem is fixed.

Very good idea @PEZ. I've tried what you described and it seems to work correctly. I can now navigate even to namespaces which have no fns/defs inside them. 馃憤 Great job everyone 馃憦, looking forward to see this in next version.

Closing this since Calva now uses cider-nrepl 0.23.0

@bpringe I hoped you'd be on 0.25 by now. :-)

I put it on our todo list :smile: - #852

Was this page helpful?
0 / 5 - 0 ratings