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

"Require REPL Utilities" command is broken #451

Closed
bpringe opened this issue Nov 5, 2019 · 12 comments
Closed

"Require REPL Utilities" command is broken #451

bpringe opened this issue Nov 5, 2019 · 12 comments

Comments

@bpringe
Copy link
Member

bpringe commented Nov 5, 2019

I was looking into #433 and I realized this command doesn't work, at least for me. I run the jack-in command, the repl window opens, and then I run the Require REPL Utilities command. I see REPL utilities (like apropos, dir, doc, find-doc, pst, and source) are now available. in the Calva says window, but I get an error when I try to use doc:

image

@bpringe
Copy link
Member Author

bpringe commented Nov 5, 2019

Update: It works if I have the cursor in the repl window when I run this command, but shouldn't it work also if I have the cursor in the editor?

I'm wondering if there is something wrong with the session returned here:

session: NReplSession = replWindow ? replWindow.session : util.getSession(util.getFileType(util.getDocument({}))),

If I put the CLJ_FORM below the above line into my editor and evaluate it, then I can use doc. So it seems something is wrong with the session.eval call when the session does not come from the active repl window. Looking through the code though, it looks like it should work.

@PEZ
Copy link
Collaborator

PEZ commented Nov 5, 2019

From the screenshot it looks like you are trying to evaluate (doc map) in the user namespace. Maybe you required in the REPL utils in another namespace in the editor?

@cfehse
Copy link
Contributor

cfehse commented Nov 5, 2019

@bpringe @PEZ

The problem is that the REPL window and the editor do not share the same session. If you execute the command the tools will immediately work in the editor that was active while executing the command (only in this namespace the tools are aquired). In the current implementation the REPL window is only used to determine the session type (strange enough) but the session of the REPL window is not used to aquire the tools there as well.

@cfehse
Copy link
Contributor

cfehse commented Nov 5, 2019

@bpringe

Update: It works if I have the cursor in the repl window when I run this command, but shouldn't it work also if I have the cursor in the editor?

Yes you are absolutely wright. One way to make it work as well is to close the REPL window. Execute the command and then open the REPL window (which will clone the editor session with the aquired tools for the new REPL window) then change the namespace of the REPL window to that of the editor and then the tools will work. gg

@PEZ
Copy link
Collaborator

PEZ commented Nov 5, 2019

Actually I think this works as intended. No need to close and reclone any sessions. Sessions share definitions. If the utilities are required to namespace foo from the editor then they will be available in namespace foo in the REPL window. And also vice versa.

@cfehse
Copy link
Contributor

cfehse commented Nov 5, 2019

@PEZ

If a REPL Window exists shouldn't the command not be executed in both sessions? REPL Window and editor?

@bpringe
Copy link
Member Author

bpringe commented Nov 5, 2019

Ok... so this was not working as you say it should above when I tried it in an existing leiningen clj project. However, I just created a lein new test-project and it worked fine. 🤔

Also I realized my namespace error in the image, but I corrected this in the existing project and it still would not work correctly. Not sure what the difference in projects could be, but I can't look into it more at the moment.

@bpringe
Copy link
Member Author

bpringe commented Nov 5, 2019

Here is an example of it not working. Notice the (doc map) does not resolve on save (evaluate, shown in the Calva says window) or in the REPL window after requiring the utilities into that namespace.

calva-require-repl-utilities

@PEZ
Copy link
Collaborator

PEZ commented Nov 5, 2019

That's odd. But at least it is consistent. Make a copy of that non-working project, so that you can use it for debugging the issue. 😄

@bpringe
Copy link
Member Author

bpringe commented Nov 6, 2019

Okay ~ ... At the risk of seeming crazy... I have some repro steps and a test repo. I don't really know how to make sense of the effects as of yet.

The repo:
https://github.com/bpringe/test-project

The steps (with eval on save turned on, but can probably do the same with eval commands)

  1. Open the project and open core.clj
  2. Jack-in
  3. Evaluate the file
  4. Add (doc map) to the bottom of the file, save, notice doc is not found
  5. Run "Require REPL utilities" command, save, notice (doc map) evaluated successfully

Now... the above always works with the core.clj file, however, in each of the new(x).clj files, if you repeat steps 3 through 5 you will notice that the doc expression does not evaluate successfully.

Furthermore, if you avoid step 3 and add (doc map) before the first time you evaluate the file, you'll notice that steps 4 and 5 result in the successful evaluation of the doc expression.

It's a very subtle difference in order of operations, but it is consistent when I try both ways. Besides the core.clj file, one way always works, the other way always does not work.

cfehse pushed a commit to cfehse/calva that referenced this issue Nov 6, 2019
@cfehse
Copy link
Contributor

cfehse commented Nov 6, 2019

@bpringe

I created a PR which fixes the issue in my tests. One critical point was to ensure that the namespace of the file exists in the REPL. If the namespace exists (even in case of the "empty" files new(x).clj) than the command successfully requires the tools and they are available. Perhaps you can take a look at my code.

Thanks!

@bpringe
Copy link
Member Author

bpringe commented Nov 6, 2019

Ah that makes sense! Thanks!

@bpringe bpringe closed this as completed Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants