avli / clojureVSCode

Clojure support for Visual Studio Code
https://avli.github.io/clojureVSCode/
MIT License
204 stars 34 forks source link

Add eval region commands #129

Closed ulyssesdotcodes closed 5 years ago

ulyssesdotcodes commented 5 years ago

Useful for evaluating single expressions in nREPL.

avli commented 5 years ago

Hi @ulyssesp,

Thank you for your contribution!

I can see what improvement you're trying to make but I have two concerns:

  1. The way you have implemented the region start and end lines search is not correct in all cases. Imagine the following code:
(let [s "hello"]

  (println s) ;; cursor is here

  )

Region evaluation causes an error in this situation, because you define a region as a text between two empty lines, which is not enough in this case.

  1. We already have a region calculation command and another one can be confusing for users. It may be even more confusing due to the loosely defined region entity.

This leads me to the idea that it would be better to add "Evaluate Form" command rather than "Evaluate Region". I believe it's not hard to make necessary changes to the code you've already provided and find forms by counting opening and closing brackets. This approach is much less fragile than looking for empty lines.

I'm going to close this PR for now, but I will be more than happy to accept the changes with the forms evaluation.