Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No definition found" on _some_ of my local CLJS requires #427

Closed
brdloush opened this issue Oct 25, 2019 · 19 comments
Closed

"No definition found" on _some_ of my local CLJS requires #427

brdloush opened this issue Oct 25, 2019 · 19 comments
Labels

Comments

@brdloush
Copy link
Contributor

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?

@PEZ
Copy link
Collaborator

PEZ commented Oct 25, 2019

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

@brdloush
Copy link
Contributor Author

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.

@PEZ
Copy link
Collaborator

PEZ commented Oct 25, 2019

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

@brdloush
Copy link
Contributor Author

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

@brdloush
Copy link
Contributor Author

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 .
  1. 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)
  1. waited until TERMINAL tab mentioned [:app] Build completed. (528 files, 527 compiled, 0 warnings, 37.72s)

  2. opened http://localhost:8280

  • app skeleton is succesfully loaded and fully works
  • calva CLJS REPL in VS Code works, can now evaluate expressions
  1. opened events.cljs file. All 3 imports (re-frame.core, dummy-project-reframe-db and day8.re-frame.tracing) can be ctrl+clicked.

  2. 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
  1. 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!

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

@PEZ
Copy link
Collaborator

PEZ commented Oct 30, 2019

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!

@PEZ
Copy link
Collaborator

PEZ commented Oct 30, 2019

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.

@PEZ
Copy link
Collaborator

PEZ commented Oct 31, 2019

Added this issue on orchard: clojure-emacs/orchard#75

@cfehse
Copy link
Contributor

cfehse commented Nov 5, 2019

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

@cfehse
Copy link
Contributor

cfehse commented Nov 5, 2019

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

@PEZ
Copy link
Collaborator

PEZ commented Nov 5, 2019

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

@PEZ
Copy link
Collaborator

PEZ commented Nov 5, 2019

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.

@cfehse
Copy link
Contributor

cfehse commented Nov 5, 2019

@PEZ

Top!

@cfehse cfehse added the upstream label Nov 5, 2019
@brdloush
Copy link
Contributor Author

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 orchard version. 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?

@PEZ
Copy link
Collaborator

PEZ commented Nov 13, 2019

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.

@brdloush
Copy link
Contributor Author

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.

@bpringe
Copy link
Member

bpringe commented Nov 25, 2020

Closing this since Calva now uses cider-nrepl 0.23.0

@bpringe bpringe closed this as completed Nov 25, 2020
@bbatsov
Copy link
Contributor

bbatsov commented Nov 26, 2020

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

@bpringe
Copy link
Member

bpringe commented Nov 26, 2020

I put it on our todo list 😄 - #852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants