Fork me on GitHub
#calva
<
2022-11-16
>
Dallas Surewood01:11:29

Sometimes a function takes certain keys, kinda like enums, and calva seems to know which one of these the function can take. Like my HugSQL queries know what the names of the queries are. What tells Calva about this?

skylize02:11:17

Haven't used HugSQL myself. But I expect from your example that it uses a destructured map in the parameters. https://clojure.org/guides/destructuring

(defn foo [& {bar :bar}]
  bar)
or
(defn foo [& {:keys [bar]}]
  bar)
You should be able to verify this by hovering over the function name, where the function signature will show above the docstring. Or you can go deeper with Go to Definition command (defaults to F12 or Ctrl-LClick on Win/Linux) to read the source code.

bringe03:11:01

Clojure-lsp informs Calva/VS Code about this. You can see this by enabling the logs between the client and server: https://calva.io/clojure-lsp/#viewing-the-logs-between-the-client-and-server. After you see the completion pop up, search the the Clojure Language Client output channel for one of the completion items (like :create-user! in your case), and you’ll see it was provided in a textDocument/completion response.

bringe03:11:35

If you want to go a step further, clj-kondo is what provides this information to clojure-lsp, I believe.