-
Notifications
You must be signed in to change notification settings - Fork 108
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
Multiple NRepls.cs improvements #380
Conversation
Support for sending :info via NRepl was incomplete because the :forms and :arglists keys are blacklisted, as they usually contain edn which is not safe to parse with read-str. The alternate version :forms-str and :arglists-str is now sent instead, and editor plugins now show arglist information on the function documentations.
With this changes, when an eval region command is sent, the current ns var (*ns*) is bound to the actual ns in the file being evaled. Detecting the ns is done by inspecting the path of the file, assuming the folder structure maps the ns structur and the clojure's source tree is always inside a parent folder called "Assets". If the ns cannot be safely determined, it falls back to the previous behaviour, and evaluates code in the last bound *ns*.
I've also implemented automatically setting the ns to the current file's ns when that can be safely determined by folder structure. This gets rid of an annoying issue where you would eval a region of code before evaluating that file's ns form and evaluate that code in another namespace instead. I believe the old behaviour was error-prone, as it lead to situations where, for instance, you would define a function in multiple namespaces by mistake. However, let me know if the original behaviour was the intended, and I'll rever this last commit, or we can put it behind a config flag instead. |
This works by implementing the :complete message mimicking what cider-nrepl does.
I couldn't help myself and also implemented a simple version of Intellisense-like autocomplete :) Again, I've tested it to work with both CIDER and Calva. Some highlights:
As for the implementation details, I am not really satisfied with having clojure lambdas stored in strings inside the C# source. Suggestions are welcome! Note this addition may be a bit resource hungry (especially since I do no caching at all). This works fine on my machine and there's no noticeable slowdown. However, I think it would be best if we allow disabling it behind a config flag in configuration.edn. With some instructions, I can take a look at it myself. |
Now a "type" field is included with the responses to the :complete message handler. This allows IDEs to distinguish between functions, namespaces and keywords when displaying completions. Also added an "eldoc" message handler, which is synonym to "info", which had already been implemented.
This looks great, thanks for the hard work! We're testing now |
Thanks! I'm glad to be able to help :D Please let me know if there's anything that should be addressed. |
@setzer22 this is awesome! just confirmed working for me in VSCode/Calva on Linux. the autocomplete is a real game changer. its the feature ive missed the most when working in clojure compared to F#, C# or JavaScript -- this is going to make the Arcadia experience really great! Feedback on the implementation:
What we've done is implement functionality that is more naturally expressed in Clojure in a There are examples of this approach in the
You could move the Clojure functions that are currently inline into
Adding a flag to the configuration file makes sense. To do that:
Let me know if that makes sense. Thanks again for a great contribution! |
Many thanks @nasser ! Again, I'm very glad to be able to contribute :D I've pushed a new commits implementing your two suggested refactors. Let me know if you think something else can be improved! I also added a CIDER-specific workaround that I think requires a bit more discussion. Let me ellaborate: There seems to be an effort in cider to gradually replace middlewares with their own sideloaded implementations (clojure-emacs/cider#2611) if those aren't present. That's actually good, but has an unfortunate side-effect: Since CIDER has no knowledge of CLR, it will assume ours is a Java nREPL and send some very JVM-specific code snippets to eval. If we do the right ting and throw an exception, CIDER acts strangely, and may even freeze. One particular issue occurs when the "classpath" is not supported by the nrepl server (we have no classpath in CLR!). Cider will try to eval Note that all these changes are pretty recent in cider (less than a year old). So it may very well be that some users are not experiencing this issue yet because their CIDER is not at the latest version. Could you please check if you can reproduce this behaviour? I suspect this issue affects Arcadia even prior to the changes introduced in this branch. Some minimal steps to reproduce on my machine are:
I've asked around in #cider at clojurians slack, and I may open an issue there to discuss this as well if they agree this is worth fixing. Hopefully we can get rid of this workaround. Another possibility would be to implement support for the "classpath" op, returning something that makes sense in CLR (a classpath equivalent, perhaps?). This may improve even more the nREPL experience in Arcadia so it's my preferred option. Sorry for the wall of text! 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great @setzer22, thanks for turning it around so fast! Two fine grained things in this review and we should be ready to merge and cut a new release with this functionality.
@nasser Done! I've talked to @bbatsov from #cider and with his help I managed to get rid of the classpath workaround. Now we do a cleaner thing by implementing the classpath nrepl op. CLR has no "classpath" per se, but what I'm doing is sending the full path to the That might become an issue if you're using this NRepl.cs outside of unity. Let me know if that happens so we can look for a better fix. With this fix, more functionalities are now working: For instance, when you create a new file, cider will automatically detect the right namespace for that file, and add an |
Feel free to ping me any time you need help with something nREPL related. :-) Btw, is there any particular reason that you opted not to have the server as a separate project? I'm not sure if there's anything Arcadia specific in it, or it can be used by anyone interested in ClojureCLR. I was also reminded of https://github.com/nrepl/bencode/pull/2/files today, as I wasn't sure if you plan to finish it or not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing -- using we can support Leiningen projects if you use the CLOJURE_LOAD_PATH
environment variable that Arcadia computes on startup.
@setzer22 This is looking really good! Added a note about ClojureCLR's "load path" which is the closest thing to the class path we have. If you can land that change we can support Leiningen projects and the whole thing would be less Arcadia dependent -- should be OK to merge after that! @bbatsov No reason not to make the server its own project. It is in the Arcadia repository out of convenience more than anything else. I think with @setzer22 latest changes it would make sense to factor it out into its own project given how powerful its become. wrt nrepl/bencode#2, we ended up continuing to build on our C# implementation that uses the Bencode.NET library, so the Clojure implementation hasn't been a priority. Realistically speaking I won't have time to come back to it any time soon, so it might make sense just to close that PR for now. |
Makes sense to me.
I think that'd be pretty cool indeed. The lack of a working nREPL implementation has long been a problem for wider ClojureCLR adoption (at least IMO). |
@nasser I'll start working on the changes soon! About making a standalone CLR nREPL, I'm all in for that! I haven't used Clojure CLR outside of Arcadia, but that's partly due to the difficulty in setting up a good development environment. As for the autocompletion support, I've found out @sogaiu, another member of the community, has a fork of the Since that is more tested, and has a few interesting features, I'd suggest merging that with my implementation in In fact, the only thing that's missing is support for keyword completions, but I could patch in my implementation easily and we'd have a very good autocompletion support! What do you think? |
I went ahead and added the new autocompletion library I mentioned yesterday. I had to modify the original code slightly, and put it into a new namespace Let me know if you'd rather manage this as an external dependency. I am not aware we can do this yet in Arcadia, so I've just went the good ol' copy-paste approach 😄 The The new autocompletion engine can now handle:
|
Regarding the completion - you can also check this nrepl/nrepl#174 I'm planning to adapt the original |
Hi @setzer22 thank you for this amazing contribution! How can I as a CIDER user make use of auto-completion? I have checked my I simply executed
Thank you in advance! |
Hi @lccambiaghi, I'm glad you like this :) I don't have a lot of time to work on this right now. But I can tell you it used to work just fine in CIDER. Emacs is my main editor and I made sure every feature worked there. That being said, there might have been a breaking change in either cider, ClojureCLR/Arcadia or the NRepl implementation. If I had to look somewhere, I'd start at the Unity console, see if you can find any errors there. Also, try having a look at the I hope some of this helps you debug the issue :) |
Thank you for your quick reply! It may very well be that I am doing something wrong. For example, should I have a In the Unity console I read this error:
I understand you may not have the time! I wish I knew how to debug this ahah.. Thanks anyway! |
Hi @setzer22 sorry to bother you again.. Would you be able to help me debug this issue? I tried to inspect the namespace indicated by you but I keep getting this What I could understand is that in the |
Hello @lccambiaghi ! I also experience some issues with autocompletion using CIDER. I just found that by using CIDER v0.24.0, the autocompletion seems to work without issues. Unfortunately I'm not an expert so I can't pinpoint the cause of error, but I hope it helps. |
Hi @FilipCon thank you so much!!! That fixed the However, I still cannot see documentation and jump to definition for functions... EDIT: ok, documentation is working with |
Support for sending symbol metadata information via NRepl was incomplete because the
:forms
and:arglists
typically present in symbol's metadata are expected to have different names::forms-str
and:arglists-str
. This is related to the fact that these two keys usually contain edn that should not be parsed directly.With this PR, the nrepl client in NRepl.cs now does the right thing and sends the
-str
version of the keys. This means that the argument list for user-defined fns and documentation for special forms (likelet
) should be now shown by most editor plugins. I've tested this behaviour to be correct both with Emacs (CIDER) and VSCode (Calva).This PR also gets rid of a minor annoyance with Calva (and probably other editors that show documentation on mouse hover) where sometimes it would ask our nrepl server for an empty string, making it throw an exception that was logged to the Unity console. Now those empty string queries are properly ignored, making the Arcadia experience in Calva better.