Skip to content
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

Tests for more Clojure tags #4126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 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,6 @@
documented-multimethod input.clj /^(defmulti documented-multimethod "Documentation"$/;" M multimethod.test
named-method input.clj /^(defmethod test :test2 named-method$/;" m multimethod.test
test input.clj /^(defmulti test$/;" M multimethod.test
test input.clj /^(defmethod test nil$/;" m multimethod.test
test input.clj /^(defmethod test :test$/;" m multimethod.test
test input.clj /^(defmethod test :test2 named-method$/;" m 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
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
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
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
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)
6 changes: 6 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,6 @@
const-var input.clj /^(def const-var ^:const 'var)$/;" v namespace:vars.test
doc-var input.clj /^(def doc-var "Documentation" 'var)$/;" v namespace:vars.test
dynamic-var input.clj /^(def dynamic-var ^:dynamic 'var)$/;" v namespace:vars.test
fn-var input.clj /^(def fn-var (fn [] true))$/;" f namespace:vars.test
once-var input.clj /^(defonce once-var 'evaluated-once)$/;" v namespace:vars.test
var input.clj /^(def var 'var)$/;" v 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))