Skip to content

Commit 5d663da

Browse files
committed
Fix bug with protocol vector return schemas
1 parent ba01076 commit 5d663da

4 files changed

Lines changed: 31 additions & 12 deletions

File tree

.cljfmt.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{:remove-multiple-non-indenting-spaces? true
22
:sort-ns-references? true
3-
:indents {io.julienvincent.malt/extend [[:inner 0] [:inner 1]]}}
3+
:indents {io.julienvincent.malt/extend [[:inner 0] [:inner 1]]
4+
io.julienvincent.malt/implement [[:inner 0] [:inner 1]]
5+
io.julienvincent.malt/defrecord [[:inner 0] [:inner 1]]}}

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ config to display properly:
132132

133133
```clojure
134134
;; .cljfmt.edn
135-
{:indents {io.julienvincent.malt/extend [[:inner 0] [:inner 1]]}}
135+
{:indents {io.julienvincent.malt/extend [[:inner 0] [:inner 1]]
136+
io.julienvincent.malt/implement [[:inner 0] [:inner 1]]
137+
io.julienvincent.malt/defrecord [[:inner 0] [:inner 1]]}}
136138
```
137139

138140
This might not be needed in the future - see https://github.com/weavejester/cljfmt/issues/336
141+
142+
## Gotchas
143+
144+
If you are using the autogenerated `?Type` schemas that are produced by `malt/defprotocol` and `malt/defrecord` then
145+
note that lsp references don't work perfectly due to limitations in clojure-lsp. This means that go-to-references will
146+
not find references to these schema vars and operations like rename will not apply to those references.

clj-kondo-test/io/julienvincent/kondo_test.clj

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@
2929

3030
(c [a :int b :int] ?SchemaReference))
3131

32-
(malt/defprotocol ExampleWithDocs
33-
"This is what the protocol does"
34-
(get-docs [a :int] :string))
35-
36-
(get-docs
37-
(reify ExampleWithDocs
38-
(get-docs [_ _] ""))
39-
1)
40-
4132
(def example
4233
(reify Example
4334
(a [_ _ _] 1)
@@ -82,3 +73,21 @@
8273
(m/validate ?Point (->Point 1 1))
8374
(m/validate ?PointSchema {:x 1
8475
:y 1})
76+
77+
(malt/defprotocol ExampleWithDocs
78+
"This is what the protocol does"
79+
(get-docs [a :int] :string))
80+
81+
(get-docs
82+
(reify ExampleWithDocs
83+
(get-docs [_ _] ""))
84+
1)
85+
86+
(malt/defprotocol NoArgs
87+
(no-args [] [:vector :string]))
88+
89+
(def with-no-args
90+
(reify NoArgs
91+
(no-args [_] "")))
92+
93+
(no-args with-no-args)

resources/clj-kondo.exports/io.julienvincent/malt/hooks/io/julienvincent/malt.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
[(first rest-children) (rest rest-children)]
2929
[nil rest-children])
3030
schema-form? (and (= 2 (count rest-children))
31-
(= 1 (count (filter vector-node? rest-children))))
31+
(vector-node? (first rest-children)))
3232
method-children (if schema-form?
3333
(let [[input-schemas-node output-schema-node] rest-children
3434
{:keys [pair-form? param-nodes schema-nodes]} (parse-input-schemas-node

0 commit comments

Comments
 (0)