BetterThanTomorrow / calva

Clojure & ClojureScript Interactive Programming for VS Code
https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva
Other
1.62k stars 213 forks source link

Displaying the specs of a function #687

Open matdurand opened 4 years ago

matdurand commented 4 years ago

It would be nice if Calva was able to display the specs of a function in the VSCode popup overlay giving the info about a function. We could leverage the clojure.repl/doc function that already gives the specs of a function if available.

Here is the REPL output of the doc function for a demo function taken from the spec documentation:

user/ranged-rand
([start end])
  Returns random int in range start <= rand < end
Spec
  args: (and (cat :start int? :end int?) (< (:start %) (:end %)))
  ret: int?
  fn: (and (>= (:ret %) (-> % :args :start)) (< (:ret %) (-> % :args :end)))

Displaying this in the popup would be a good start.

Not sure if it would be possible for clojurescript though because I'm having issue running the doc function in my node repl...

bpringe commented 3 years ago

Just making a note here for later to check if clojure-lsp shows the spec in its hovers. (We'll be adding clojure-lsp soon.)

bpringe commented 3 years ago

Update: It doesn't seem like clojure-lsp provides this, and now that I think about it, it does seem like more of a repl driven thing, since specs would exist on a function after the spec has been eval'd. Not to say it's impossible to do with static analysis, but it would have to take into account clojure.spec when crawling the files, I think.

In the future if we do decide to use clojure-lsp's hovers in place of Calva's for function docs (even when connected to a repl), maybe we could use Calva's provider just for things like spec docs when a repl connection exists. So lsp provides the function name, args list, and doc string, and Calva provides the spec if it exists.