Open Andre0991 opened 4 years ago
I'm not sure if we have some easy way to find the output schema on hover/documentation request given the function name, WDYT @snoe ?
@Andre0991 @ericdallo
My first thought is we'd have to allow macro-defs to add something like an :extra-info or :return-type
key to the add-reference
call, it's possible it has overlap with type-hinting. Then that key could be used in the hover/documentation commands.
I'm hesitant to do this, since we'd like to move to a new parser (kondo) and we'll likely have to do things differently with macros in that world. But if it's important, I'll take a PR.
Oh and you should reuse :signature-style :typed
for schema when figuring out how to find the return-type value.
We now rely on clj-kondo analysis to know what is that code, and the analysis related to that is:
{:fixed-arities #{1},
:end-row 18,
:name-end-col 12,
:name-end-row 17,
:name-row 17,
:ns clojure-sample.core,
:name foo,
:filename
"/home/greg/dev/clojure-sample/src/clojure_sample/core.clj",
:col 1,
:name-col 9,
:end-col 18,
:arglist-strs ["[bar]"],
:bucket :var-definitions,
:row 17}
@borkdude, do you think we could add some info about that on arglists-strs
or a new field? It's seems hard to think in a generic field not specific for that issue though
I think this and ^Type hint returns (:tag iirc in clojure.core parlance) could fit well together.
Ping @borkdude, if you agree, I can raise a clj-kondo issue to help track that
The reason the input schema shows up is just because the raw arglist source string is preserved.
I think we could add return types to the analysis, but we would have to come up with a format which offers this information on a per arity basis, since functions can have different return types per arity.
Needs hammock time and probably not high priority.
@borkdude I'm trying to implement that on clj-kondo side, AFAIK schema.core can have only one return schema for var, right?
I don't know, read the schema docs :)
From schema.core docs
- The output schema always goes on the fn name, not the arg vector. This means that all arities must share the same output schema.
@borkdude I don't see a better name, I intend to add to the :var-definitions
as :return-schema-str "s/Int"
do you have any suggestions?
Or maybe return-schema-strs
for future compatibility with other libs? (not sure it's an optimization unnecessary for now)
Consider this function:
It uses the plumatic schema library.
This is the result of
lsp-describe-thing-at-point
:Note that it displays the input schemas, but it does not do the same for the output (which is
s/Uuid
).My company heavily uses plumatic schema, so this is a bit annoying because it requires you to go to the function definition if you want to know the expected output.