-
Notifications
You must be signed in to change notification settings - Fork 16
Update clojure-ts-find-ns to support in-ns
and Add tests
#38
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
Conversation
- The tests cases are copied from clojure-mode and updated
(with-clojure-ts-buffer "(in-ns 'bar.baz)" | ||
(expect (clojure-ts-find-ns) :to-equal "bar.baz"))) | ||
|
||
(it "should take the first ns instead of closest unlike clojure-mode" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only scenario where it differs from clojure-find-ns after this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular reason for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIU It's debatable what is the correct behaviour here.
clojure-mode finds the closest ns above point and falls back to finding the closest ns below point.
-
My understanding is that clojure-mode finding the closest ns is more of a result of an implementation detail rather than desired behaviour.
-
Also I haven't figured out yet how to find all occurrences or do a reverse search with tree-sitter queries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall in the beginning clojure-mode
was just looking for a ns
form in the beginning of the file, but then we changed it, as per the Clojure specification the current ns
was supposed to be whatever ns is closest above the form in question. I don't recall doing a search below as well, but perhaps there was some reason for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyways, if by first you mean "closest above" (and so it seems looking at the tests), I think that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now it's first from the beginning of file. (point is not used at all).
This is the behaviour before the PR as well. I haven't updated it as it would require more complicated tree-sitter queries.
The below test is matching the 3rd ns only because the first 2 are invalid not because of the point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If clojure-mode behaviour is ideal I would prefer to create a new issue and handle it in a separate PR.(Need more tree-sitter knowledge to handle the queries there.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd be fine by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general that has never been super important for me (to do this by the letter), as usually source files have only the leading ns
form. But clearly it was a problem for some users of clojure-mode
. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/utils/test-helper.el
Outdated
@@ -0,0 +1,50 @@ | |||
;;; test-helper.el --- Clojure TS Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*- | |||
|
|||
;; Copyright © 2022-2024 Danny Freeman |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to preserve the copyright attribution of the original code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add them back.
in-ns
when finding namespace.clojure-mode
.