-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
orchard.namespace/read-namespace fails if the ns form includes reader conditionals #142
Comments
Thanks much for the report! Not sure if agree with the suggested fix. Isn't it possible to read .cljc files using the same mechanism that Clojure does?
|
@vemv My apologies, I had looked at clojure.core/read, miss-read the docs and discounted - because I wasn't using correctly.
The changes:
|
Sounds good like that! Makes sense. Let us know if you're up for a PR, otherwise we can take it from here 👍 |
Yup, will do a PR |
@alasdairm I went ahead with #145, still thanks much for the snippet! 🍻 |
@vemv You're welcome. |
Expected behavior
orchard.namespace/read-namespace should pull out the name from the first (ns ..,) form in any cljc file.
Actual behavior
orchard.namespace/read-namespace returns nil if the ns form includes a reader conditional.
(the EDN read throws an exception that is caught by the catch block).
Steps to reproduce the problem
Can be reproduced in two ways - from CIDER or by adding a test to Orchard that (IMO) should pass (but fails).
From CIDER
create a project with a mix of files with and without reader conditionals in their ns forms
E.g.
Select load all project files
Browse all namespaces
observe that the files with reader conditionals have not been loaded.
By adding a test to Orchard
Add a test that passes a file with reader conditionals to read-namespace
Run the test
Error reported - read-namespace returns nil rather than ns1
Environment & Version information
CIDER 1.2.0 (Nice), nREPL 0.9.0
refactor-nrepl/refactor-nrepl "3.1.0"
cider/cider-nrepl "0.27.4"
cider/orchard "0.8.0"
Clojure version
Clojure 1.10.1
Java version
Java 14.0.2
Operating system
Windows 10
Suggested fix [edited]
The problem is that clojure.edn/read throws an exception if it encounters a reader conditional. The exception is caught and nil returned.
Instead of clojure.edn/read use clojure.core/read with read-eval bound to false and passing in an option of :read-cond :allow.
Another solution would be to first try the clojure.edn/read and, if that fails, fall back to a regex match if the clojure.edn/read fails. There is a trade-off here - a regex will find non-top-level forms.
Sample code can be supplied in a pull request if this approach is acceptable.
The text was updated successfully, but these errors were encountered: