Skip to content

Tests for more Clojure tags #4126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Units/parser-clojure.r/clojure-methods.b/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
About methodId kind, see #4126.
2 changes: 2 additions & 0 deletions Units/parser-clojure.r/clojure-methods.b/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+KzZ
7 changes: 7 additions & 0 deletions Units/parser-clojure.r/clojure-methods.b/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
multimethod.test input.clj /^(ns multimethod.test)$/;" kind:namespace
test input.clj /^(defmulti test$/;" kind:multi scope:namespace:multimethod.test
documented-multimethod input.clj /^(defmulti documented-multimethod "Documentation"$/;" kind:multi scope:namespace:multimethod.test
test input.clj /^(defmethod test nil$/;" kind:method scope:namespace:multimethod.test
test input.clj /^(defmethod test :test$/;" kind:method scope:namespace:multimethod.test
test input.clj /^(defmethod test :test2 named-method$/;" kind:method scope:namespace:multimethod.test
named-method input.clj /^(defmethod test :test2 named-method$/;" kind:methodId method:test scope:namespace:multimethod.test
19 changes: 19 additions & 0 deletions Units/parser-clojure.r/clojure-methods.b/input.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(ns multimethod.test)

(defmulti test
(fn [type] type))

(defmulti documented-multimethod "Documentation"
(fn [type] type))

(defmethod test nil
[& _]
nil)

(defmethod test :test
[& _]
nil)

(defmethod test :test2 named-method
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain this line?
I wonder why named-method should be extracted because my knowledge of Clojure is limited.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a method-specific name that's added to multimethod function name. See https://clojuredocs.org/clojure.core/defmethod#example-542692c7c026201cdc3269cd

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need help understanding.
Can named-method be used with a function?
I guess, with the name, a user can call the method by passing multi-method-dispatching. If my guessing is correct,I think 'named-method' should be tagged as a function, not a method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't work as a self-sufficient function. It's merely a piece of metadata identifying the method. It's only useful in debugging and (given ctags support) in location search.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thank you. We should introduce a new kind for such a language object. What do Clojure hackers call it? I think of method-identifier/i or method-id/i.

The ideal tags for named-method looks like:

named-method	input.clj	/^(defmethod test :test2 named-method$/;"	i	multimethod.test	method:test
test	input.clj	/^(defmethod test :test2 named-method$/;"	m	multimethod.test	identifier:named-method

Anyway, the current Clojure parser cannot extract caddr.
So, to satisfy these new test cases, we must rewrite the parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for disappearing 😔 Why not named method? But yes, method-id(endifier) is fine by me too!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If named-method is tagged as a method, a client tool like Vim may show it as a candidate in input completion.

No, it doesn't work as a self-sufficient function.

However, it is not callable, as you wrote. So, named-method should not be shown on the candidate list. If named-method is tagged as a method-id, Vim may not show as far as Vim shows only method kind tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all fair!

[& _]
nil)
2 changes: 2 additions & 0 deletions Units/parser-clojure.r/clojure-vars.b/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--sort=no
--fields=+KzZ
7 changes: 7 additions & 0 deletions Units/parser-clojure.r/clojure-vars.b/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vars.test input.clj /^(ns vars.test)$/;" kind:namespace
var input.clj /^(def var 'var)$/;" kind:variable namespace:vars.test
doc-var input.clj /^(def doc-var "Documentation" 'var)$/;" kind:variable scope:namespace:vars.test
dynamic-var input.clj /^(def dynamic-var ^:dynamic 'var)$/;" kind:variable scope:namespace:vars.test
const-var input.clj /^(def const-var ^:const 'var)$/;" kind:variable scope:namespace:vars.test
once-var input.clj /^(defonce once-var 'evaluated-once)$/;" kind:variable scope:namespace:vars.test
fn-var input.clj /^(def fn-var (fn [] true))$/;" kind:function scope:namespace:vars.test
13 changes: 13 additions & 0 deletions Units/parser-clojure.r/clojure-vars.b/input.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(ns vars.test)

(def var 'var)

(def doc-var "Documentation" 'var)

(def dynamic-var ^:dynamic 'var)

(def const-var ^:const 'var)

(defonce once-var 'evaluated-once)

(def fn-var (fn [] true))
Loading