-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
implementation of cider-expected-ns #1622
Conversation
(ert-deftest cider-expected-ns () | ||
(noflet ((cider-ensure-connected () t) | ||
(cider-sync-request:classpath () '("/a" "/b" "/c" "/c/inner"))) | ||
(dolist (x '(("/a/foo/bar/baz_utils.clj" "foo.bar.baz-utils") |
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 think that just adding explicit should
s will make this more readable. Our gain from dolist
is pretty minimal right now.
Apart from my small remarks the changes look good. When you address them you should also squash the commits together and have the final commit follow our commit message guidelines. |
I addressed the 2 comments, squashed the commits, and changed the commit message to match the guidelines. |
Great! :-) Guess now you can continue with moving the cljr functionality here (or you can wait for @benedekfazekas to do it). Depends on how fast you want to use this. :-) |
haha I am happy either way. don't stop @aiba while you are at it tho :) I guess removal from cljr should happen after 2.2.0 release as that will be compatible with 0.11 cider which won't have this functionality. |
We can add the new version to cider and you can remove the old one afterwards. That'd be the most painless solution imo. |
sorry if was not clear, that is what i meant. I only added that I would merge the removal from cljr after cljr 2.2.0 released as 2.2.0 will be meant to compatible with cider 0.11 |
Thanks for the help getting this into shape! Currently clj-refactor has a feature, As a next step, I'd propose changing Or, @benedekfazekas are you suggesting that the insertion of namespace doesn't belong in either cljr or clojure-mode, and we should move it all to cider? |
While this makes sense, we're actually going to move the feature completely to cider. Don't update cljr at all for now and don't update clojure-mode either (compatibility's a bitch).
Exactly. Just submit the relevant code to cider, don't touch the other projects for now. We'll do the cleanup there after cljr 2.2 is released eventually. |
indeed. As @bbatsov said. |
Sounds like a plan! I'll work on a PR for cider for |
You may want to look into |
@bbatsov @benedekfazekas In the course of implementing this, I realized clj-refactor will also insert test declarations ( Should we proceed bringing this into cider and drop the |
This should be in cider as well. |
cljr accomplishes For a brand new file, So I am hesitant to move Open to suggestions / different ways of thinking about this. |
Define "parsing". I highly doubt cljr does anything particularly complex there, as I seem to recall this functionality is implemented completely in Elisp. |
FWIW, I think things like
Yes, it's in elisp, but it's still a fair amount of code. (defun cljr--add-test-declarations ()
(save-excursion
(let* ((ns (clojure-find-ns))
(source-ns (cljr--find-source-ns-of-test-ns ns (buffer-file-name))))
(cljr--insert-in-ns ":require")
(when source-ns
(insert "[" source-ns " :as sut]"))
(cljr--insert-in-ns ":require")
(insert (cond
((cljr--project-depends-on-p "midje")
cljr-midje-test-declaration)
((cljr--project-depends-on-p "expectations")
cljr-expectations-test-declaration)
((cljr--cljc-file?)
cljr-cljc-clojure-test-declaration)
(t cljr-clojure-test-declaration))))
(indent-region (point-min) (point-max)))) Note how many other (defun cljr--insert-in-ns (type &optional cljs?)
"DOC"
(cljr--goto-ns)
(when cljs?
(cljr--goto-cljs-branch))
(if (cljr--search-forward-within-sexp (concat "(" type))
(if (looking-at " *)")
(progn
(search-backward "(")
(forward-list 1)
(forward-char -1)
(insert " "))
(search-backward "(")
(forward-list 1)
(forward-char -1)
(newline-and-indent))
(forward-list 1)
(forward-char -1)
(newline-and-indent)
(insert "(" type " )")
(forward-char -1))) Note that it also calls 3 more |
Yes, pretty much what @Malabarba said. It didn't seem right to have all that code duplicated in both cljr and cider. Moving all of |
I'll have to take a closer look at the code there. @Malabarba's right that in principle such functions belong to |
A simple dirty fix would be to check in cljr for the new function and call it if available, otherwise fallback to the old one. In general, however, I'd prefer us to do more research/work and properly migrate all such functionality to cider/clojure-mode. |
I like the simple dirty fix as as short term solution, and agree about properly migrating the functionality for the long term. I'll start with a PR for clj-refactor for the dirty fix. |
PATH is expected to be an absolute file path. | ||
|
||
If PATH is nil, use the path to the file backing the current buffer." | ||
(cider-ensure-connected) |
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.
Like I said on the clj-refactor PR. I think this should return (clojure-expected-ns)
when not connected, instead of erroring out.
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 were going to preserve the functionality in clojure-mode
(which will be beneficial for inf-clojure
users) - this makes sense.
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.
It's your guys' call about whether to preserve the functionality. Do you know if clojure-expected-ns
is commonly used from other places besides cljr--add-ns-if-blank-clj-file
? Personally I would not miss it if it got removed from 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.
Well, I guess some people are using clj-refactor with inf-clojure, but I doubt there are many of them.
See clojure-emacs/clojure-mode#372