Clojure support for Visual Studio Code

1,962 views
Skip to first unread message

Andrey Lisin

unread,
Sep 15, 2016, 7:17:38 AM9/15/16
to Clojure
Hey guys,

I've been working on Clojure support for Visual Studio Code text editor for a while. The first version is very close to the point when it can be published to Visual Studio Code marketplace, but I would like to test it a bit more before. Maybe there are Visual Studio Code uses here who can try the extension and give feedback.

Features extension supports:

- code completion
- interaction with REPL
- go to definition
- documentation hints

The extension can be obtained from its GitHub page (https://github.com/avli/clojureVSCode/releases). Download the vsix file and drag-and-drop it to the Visual Studio Code. The extension relies on cider-nrepl, so don't forget to add it to the dependencies list. To connect to nREPL use "Connect to nREPL" command from the command palette. More information is available on the extension's GitHub page.

Hope it be useful for someone.

Michael Ball

unread,
Sep 15, 2016, 1:03:40 PM9/15/16
to Clojure
This looks great, will definitely try it out this weekend!

Ikuru Kanuma

unread,
Sep 15, 2016, 7:36:26 PM9/15/16
to Clojure
Hi Andrey, thanks for sharing this great work!

- I did want to try it out on an Ubuntu machine, but simply dragging and dropping seemed to not work.
Could you perhaps point to an alternative way to install extensions (First time ever touching vs code, so it is hard for me to even google how to do it)?

- Cider injects its own nrepl middleware. Would that be hard to achieve?
It would greatly make things easy for newbies.

Ikuru

Rick Beerendonk

unread,
Sep 15, 2016, 10:07:24 PM9/15/16
to Clojure
Great, I like VSCode, so certainly very helpful, thank you.

Andrey Lisin

unread,
Sep 16, 2016, 7:32:54 AM9/16/16
to Clojure
Hi Ikuru,

I've just checked and dragging and dropping works for me on Ubuntu 16.04, could you try it again? Another option is to open the extension file with "File -> Open" menu.

Not sure I understand your question correctly, but to make the extension work you need to add cider-nrepl to a list of dependencies. The simplest way to archive it to write the code below into you ~/.lein.profiles.clj

Введите код..{:user {:plugins [[cider/cider-nrepl "0.12.0-SNAPSHOT"]]
:dependencies [[org.clojure/tools.nrepl "0.2.12"]]}}.

Andrey Lisin

unread,
Sep 16, 2016, 7:35:23 AM9/16/16
to Clojure
Sorry for the mess in the previous message. This code should be put into ~/.lein/profiles.clj

{:user {:plugins  [[cider/cider-nrepl "0.12.0-SNAPSHOT"]]
       :dependencies [[org.clojure/tools.nrepl "0.2.12"]]}}



пятница, 16 сентября 2016 г., 17:32:54 UTC+6 пользователь Andrey Lisin написал:

Michael Ball

unread,
Sep 16, 2016, 6:32:39 PM9/16/16
to Clojure
Ok was just able to try it out briefly on OSX.

- Installation went smoothly, no problems.

- Explicit docs/instructions on how to start and connect to the repl would be good. I was able to get it connected but it was unclear if the repl should be started from within VS code, or from a terminal then only connect to it from VS code.

- The commands in the command pallet could be prefixed with a "clj: " or perhaps "clojure: " or something like that. Other plugins I've used(e.g. elm) do this so it's easy  to know which commands are associated with the extension and which are part of the editor.

- code completion is working just fine.

- Docstrings don't seem to work for thread first  (-> xxx)? I also noticed that it took some time after initial repl connect for the docstrings to become available, probably some indexing delay because my laptop is old+slow, initially they showed "Docstring not found". Also the docstring not found message pops up for all characters on hover of mouse over things such as parenthesis.

- I found a command to eval the entire file which worked good. Is there a way to send selected expressions to a repl yet?

- If I had one feature request it would be for inline results a-la LightTable. Any plans for something like that?


Overall this is a great start, thank you very much for getting the ball rolling and building this extension!

Ikuru Kanuma

unread,
Sep 17, 2016, 8:52:47 PM9/17/16
to Clojure
Thanks for the reply Andrey!

I guess the installation part is then something specific to the ubuntu flavor(I am using ubuntu-mate) I am using/ what ever it could be.
(I also did try to open the file from the menu, but same story as dragging and dropping).
Also my vs-code installation is a bit suspicious, so I will look up other trouble shooting resources.
Thanks anyways!

Regarding the dependency part, I meant that in cider(on emacs)
I do not have to specify any of those dependencies by my self because it is handled when I start a repl from cider.
https://github.com/clojure-emacs/cider/pull/1552 and thought it would be a great improvement.

Michael Ball

unread,
Sep 17, 2016, 10:07:37 PM9/17/16
to Clojure
Hi Ikuru, did you install VS code from your package manager and install the code-oss package? 

I ask because when I first installed VS code on Solus Linux I used the one from the package manager which was the "code-oss package". Unfortunately I found out later that extensions are not supported in the code-oss version. 

I had to download the .tar.gz version of VS Code package directly (https://code.visualstudio.com/download), install manually, then extensions worked great.

Andrey Lisin

unread,
Sep 18, 2016, 2:07:10 AM9/18/16
to Clojure
Hi Michael,

First of all, I would like to thank you for your feedback, it helps a lot. See my comments inlined.

On Saturday, September 17, 2016 at 4:32:39 AM UTC+6, Michael Ball wrote:

- Explicit docs/instructions on how to start and connect to the repl would be good. I was able to get it connected but it was unclear if the repl should be started from within VS code, or from a terminal then only connect to it from VS code.

The instructions can be found in the "How to Use?" section of readme file. Not sure I understand your point about where the repl should be started. Do you mean you mean you expected repl will be run by VSCode on connect like it happens in Emacs?
 

- The commands in the command pallet could be prefixed with a "clj: " or perhaps "clojure: " or something like that. Other plugins I've used(e.g. elm) do this so it's easy  to know which commands are associated with the extension and which are part of the editor.

This is a valid point. I will do the necessary modifications soon.
 

- Docstrings don't seem to work for thread first  (-> xxx)? I also noticed that it took some time after initial repl connect for the docstrings to become available, probably some indexing delay because my laptop is old+slow, initially they showed "Docstring not found". Also the docstring not found message pops up for all characters on hover of mouse over things such as parenthesis.

You're right about the thread first docstring. It looks like I need to adjust the regex for finding Clojure words. Will fix it soon.

About docstrings. There shouldn't be snoticable time between pointing a thing and getting its documentation. However, the is a subtly aspect you should be aware of. If you have a namespace definition in the beginning of a file you should eval the file first. Say, you have a file with the following content:

(ns foo)

(println "Hello World")

 When you point println you won't see the docstring. The reason is the extension sends the following message to the repl: "Give me a docstring for the function println from foo namespace." But at the moment repl know nothing about foo namespace! So you neen to eval the file. This will result adding foo namespace to the repl and importing everything from clojure.core namespace to it (this is a sideeffect of ns macro). I believe, this is the common behaviour for all solutions based on cider-nrepl (I've checked it is true for Emacs Cider and Vim Fireplace). Though I admit it's not the most intuitive one. So I'm open to suggestions.

- I found a command to eval the entire file which worked good. Is there a way to send selected expressions to a repl yet?

Yes, it is! Just select code you want to send to a repl and eval it with "Eval" command.
 

- If I had one feature request it would be for inline results a-la LightTable. Any plans for something like that?

It's definetly a useful feature and I can add it easily. The only thing I'm not sure about is where to show an evaluation result :) Do you have any ideas. Maybe you've seen the similar feature in other VSCode plugins and know how to do it right?
 

Overall this is a great start, thank you very much for getting the ball rolling and building this extension!

Pleasure! 

Andrey Lisin

unread,
Sep 18, 2016, 2:11:44 AM9/18/16
to Clojure
Hi Ikuru,

please, see my comments below.

On Sunday, September 18, 2016 at 6:52:47 AM UTC+6, Ikuru Kanuma wrote:

I guess the installation part is then something specific to the ubuntu flavor(I am using ubuntu-mate) I am using/ what ever it could be.
(I also did try to open the file from the menu, but same story as dragging and dropping).
Also my vs-code installation is a bit suspicious, so I will look up other trouble shooting resources.
Thanks anyways!

I'm with Michael here. Try to use the package from the VSCode download web-site.
 

Regarding the dependency part, I meant that in cider(on emacs)
I do not have to specify any of those dependencies by my self because it is handled when I start a repl from cider.
https://github.com/clojure-emacs/cider/pull/1552 and thought it would be a great improvement.


Wow, I didn't know about it (haven't used Emacs Cider for a while.) Not sure how to implement this, but will definitely take a look. Thank you for pointing this out!
 

Andrey Lisin

unread,
Sep 18, 2016, 10:40:34 AM9/18/16
to Clojure
I've just published the new release that addresses the issues Michael pointed out. I've also added the new 'Eval and show the result' command which evaluates a file and prints the result into a VSCode output channel. Feel free to try it out.

You can download the new release here: https://github.com/avli/clojureVSCode/releases/tag/v0.4.0

Andrey Lisin

unread,
Sep 19, 2016, 7:15:37 AM9/19/16
to Clojure
Uploaded the extension to the Visual Studio Code marketplace. Now you can install using VSCode 'Extensions' menu.

Michael Ball

unread,
Sep 19, 2016, 1:50:08 PM9/19/16
to Clojure
On Saturday, September 17, 2016 at 4:32:39 AM UTC+6, Michael Ball wrote:

- Explicit docs/instructions on how to start and connect to the repl would be good. I was able to get it connected but it was unclear if the repl should be started from within VS code, or from a terminal then only connect to it from VS code.

The instructions can be found in the "How to Use?" section of readme file. Not sure I understand your point about where the repl should be started. Do you mean you mean you expected repl will be run by VSCode on connect like it happens in Emacs?

Yes, in LightTable and Cider generally the repl is started up from within the editor, and it was unclear if there was an editor action that would do this, or if the repl needed to be started in a terminal, then connected to.



- Docstrings don't seem to work for thread first  (-> xxx)? I also noticed that it took some time after initial repl connect for the docstrings to become available, probably some indexing delay because my laptop is old+slow, initially they showed "Docstring not found". Also the docstring not found message pops up for all characters on hover of mouse over things such as parenthesis.

You're right about the thread first docstring. It looks like I need to adjust the regex for finding Clojure words. Will fix it soon.

About docstrings. There shouldn't be snoticable time between pointing a thing and getting its documentation. However, the is a subtly aspect you should be aware of. If you have a namespace definition in the beginning of a file you should eval the file first. Say, you have a file with the following content:

(ns foo)

(println "Hello World")

 When you point println you won't see the docstring. The reason is the extension sends the following message to the repl: "Give me a docstring for the function println from foo namespace." But at the moment repl know nothing about foo namespace! So you neen to eval the file. This will result adding foo namespace to the repl and importing everything from clojure.core namespace to it (this is a sideeffect of ns macro). I believe, this is the common behaviour for all solutions based on cider-nrepl (I've checked it is true for Emacs Cider and Vim Fireplace). Though I admit it's not the most intuitive one. So I'm open to suggestions.

Ah, you're probably right on the eval. Also was thinking that perhaps doc-string could/should be shown on a keystroke instead of mouse-over?


 
- If I had one feature request it would be for inline results a-la LightTable. Any plans for something like that?

It's definetly a useful feature and I can add it easily. The only thing I'm not sure about is where to show an evaluation result :) Do you have any ideas. Maybe you've seen the similar feature in other VSCode plugins and know how to do it right?

I don't know if there's a really good way to do it right now, but in some very timely news just this morning a feature got some attention and we hopefully should see it in October. Probably should watch this issue and then use whatever they come up with. You could comment on that issue with your use case as jrieken requested.



You might also have look at LightTable(my personal favorite for inline results), and atom proto-repl for ideas on how to add inline results. In proto-repl, I have to admit for larger data-structures, the expandable data-structure inspector looks pretty nice. 

Ikuru Kanuma

unread,
Sep 19, 2016, 8:06:02 PM9/19/16
to Clojure
Thanks for the tips, Andry & Michael!

Will investigate the rabbit hole deeper when I have time (Tried you suggestion but no success...),
but thanks Andrey for releasing it into the market place because now
I can try it out in the mean while.

Cheers,

Andrey Lisin

unread,
Sep 20, 2016, 4:53:31 AM9/20/16
to Clojure
Hi Michael,

1. Showing a docstring on hover is a standard VSCode behavior. I don't think any extension should change it without a good reason.

2. I will investigate if it is possible to run repl from within VSCode. On the other hand, this behavior can be unexpected for some users. I believe, many users are willing to connect to a remote repl and need an explicit way to say which repl they want to use. Also note that if you open a Leiningen project and repl is running in console the extension will automatically connect to it.

3. I added an output channel for evaluation results in the latest extension version. You can try it out. I will investigate other options though.

Boris V. Schmid

unread,
Sep 24, 2016, 5:37:38 AM9/24/16
to Clojure
Just started using your plugin. Thanks. So far so good.

Two questions. 

1. Every time I eval something, or have an error, a bar appears on top, like this: "[Info] Successfully Compiled    [Close]". They don't fade away automatically, and stack, meaning that they block the top part of the editor. I couldn't find a setting how to make that bar fade away after 2-3 seconds or something like that.

2. If I have the Problems (cmd-M) window open at the bottom of the screen, and I eval something with output, that error window is replaced for an output window (which is fine behavior to me). The other way around doesn't work - if I eval something and it gives an error, the bottom window remains to be the output window, rather than switch to the problem window. Is there any way I make that behavior consistent.

Thanks for the plugin!

Michael Ball

unread,
Sep 24, 2016, 5:32:51 PM9/24/16
to Clojure
On Tuesday, September 20, 2016 at 1:53:31 AM UTC-7, Andrey Lisin wrote:
2. I will investigate if it is possible to run repl from within VSCode. On the other hand, this behavior can be unexpected for some users. I believe, many users are willing to connect to a remote repl and need an explicit way to say which repl they want to use. Also note that if you open a Leiningen project and repl is running in console the extension will automatically connect to it.

I would say don't waste time on starting the repl from within vscode, and it's probably best to not support it at all. I only mentioned because it was a bit unclear coming from LightTable on the procedure of how to start and connect to a repl.

My preference is to run repl's outside because it's easier to then use something like boot-clj to run a repl, to connect to a repl in a local docker dev container, and as you mention connect to remote repl's as well.


 
3. I added an output channel for evaluation results in the latest extension version. You can try it out. I will investigate other options though.
 
Tried it out and it's working well.



Andrey Lisin

unread,
Sep 25, 2016, 10:34:15 AM9/25/16
to Clojure
Hi Boris,

please, see my answers below.


On Saturday, September 24, 2016 at 3:37:38 PM UTC+6, Boris V. Schmid wrote:
Just started using your plugin. Thanks. So far so good.

Two questions. 

1. Every time I eval something, or have an error, a bar appears on top, like this: "[Info] Successfully Compiled    [Close]". They don't fade away automatically, and stack, meaning that they block the top part of the editor. I couldn't find a setting how to make that bar fade away after 2-3 seconds or something like that.

Visual Studio Code doesn't have an API for dismissing pop-ups (at least, I haven't found one). I'm going to disable pop-ups for "Eval and show the result" action in the next release. The issue is currently discussed in this issue on GitHub. Feel free to join, if you have any ideas.
 

2. If I have the Problems (cmd-M) window open at the bottom of the screen, and I eval something with output, that error window is replaced for an output window (which is fine behavior to me). The other way around doesn't work - if I eval something and it gives an error, the bottom window remains to be the output window, rather than switch to the problem window. Is there any way I make that behavior consistent.

Yes you're right. Something is wrong with the logic. I will investigate and fix it soon.
 

Thanks for the plugin!

Always pleasure :) 

Andrey Lisin

unread,
Sep 25, 2016, 10:40:51 AM9/25/16
to Clojure
Hi Michael,

I agree with you. What makes me optimistic is that VSCode has a built-in terminal, but I don't know if it is possible to interact with it through the API. 

However, as you said, it all depends on a user's background. I know that Vim Fireplace plugin users are used to running a repl outside the editor, when Emacs or LightTable users are not. For now, let's keep things simple and transparent by running the repl outside the editor :)
Reply all
Reply to author
Forward
0 new messages