-
-
Notifications
You must be signed in to change notification settings - Fork 247
[Fix #310,#311] clojure-expected-ns with src/cljc #312
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Fix #310,#311] clojure-expected-ns with src/cljc #312
Conversation
(- (length (file-name-extension (buffer-file-name) t)))))) | ||
(replace-regexp-in-string | ||
"_" "-" (mapconcat 'identity (cdr (split-string relative "/")) ".")))) | ||
(defun clojure-project-dir () |
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.
Turns out this implementation is problematic. See clojure-emacs/cider#1215
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 fix solves the problematic namespaces for 99.9% of affected projects. Let's solve one problem at a time?
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 mentioned this mostly because if we have the same function here, there'll be little point in fixing the problem in cider. Anyways, that's not terribly important right now.
6b299d9
to
faa9941
Compare
(sans-file-sep (mapconcat 'identity (cdr (split-string sans-file-type "/")) ".")) | ||
(sans-underscores (replace-regexp-in-string "_" "-" sans-file-sep))) | ||
;; Drop prefix from ns for projects with structure src/{clj,cljs,cljc} | ||
(replace-regexp-in-string "\\`\\(clj.\\|cljs.\\|cljc.\\)" "" sans-underscores))) |
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.
clj[sc]?.
Not sure if something isn't needed for cljx as well.
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.
Updated with cljx
support too
0b9d5de
to
7dcb52e
Compare
(sans-file-sep (mapconcat 'identity (cdr (split-string sans-file-type "/")) ".")) | ||
(sans-underscores (replace-regexp-in-string "_" "-" sans-file-sep))) | ||
;; Drop prefix from ns for projects with structure src/{clj,cljs,cljc} | ||
(replace-regexp-in-string "\\`clj[scx]?." "" sans-underscores))) |
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 .
here for any character or this an oversight?
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.
The bad ns look like clj.foo.bar.baz
if we don't remove the .
after clj
then that will be the first character in the ns.
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's why I asked - .
will match any character. You need to escape it.
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.
done
Mention those 2 bugfixes in the changelog as well. |
7dcb52e
to
118bbfc
Compare
…c/cljc When the source path is src/clj{,c,s,x} instead of just src/ clojure-expected ns would create namespaces like clj.my-project.my-ns whereas what's wanted is my-project.my-ns. Reading boot.clj or project.clj to find out the user's src dirs is out of scope for clojure-mode, so we use the simply heuristic that no namespace should start with clj, cljc or cljs because these are the idiomatic source directories in multi-source projects. When improving clojure-expected-ns I extracted out two utilities, clojure-project-dir and clojure-project-relative-path. These utilities already exist in clj-refactor so I opted to make them public rather than private, as they are generally useful.
118bbfc
to
4be6843
Compare
done |
Everything looks solid now. Thanks! |
When the source path is src/{clj,cljc,cljs} instead of just src/
clojure-expected ns would create namespaces like clj.my-project.my-ns
whereas what's wanted is my-project.my-ns.
Reading boot.clj or project.clj to find out the user's src dirs is out
of scope for clojure-mode, so we use the simply heuristic that no
namespace should start with clj, cljc or cljs because these are the
idiomatic source directories in multi-source projects.
When improving clojure-expected-ns I extracted out two utilities,
clojure-project-dir and clojure-project-relative-path. These
utilities already exist in clj-refactor so I opted to make them public
rather than private, as they are generally useful.