-
Notifications
You must be signed in to change notification settings - Fork 14
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
Mr Anderson does not correctly rewrite defrecord references with dashes #73
Comments
I am guessing the problem here is that mranderson does not do the |
happy to look at the PR for this too or at least if you could put together a test case demonstrating it, thx |
@benedekfazekas This would be a failing test case: Unfortunately, not too minimal, since it's also involving Instaparse. |
hm.. this is trickier than I thought originally. mranderson does replacements with java pkg style prefix (with since we just do a simple string based replacement in the ns body (for performance reasons) it is also tricky to check that the word before the sym is |
Hi @benedekfazekas, when I looked at this the last time I also was reading this section. And I was wondering if we could detect the difference between a fully qualified function call and a class usage if we would use the regex from the LispReader.java. There's a comment here: https://github.com/benedekfazekas/mranderson/blob/master/src/mranderson/move.clj#L211 saying it's too broad, but it would tell us the difference between:
in the replace function I believe. I didn't try that yet though. |
after looking at the |
Yes, and if we would see |
oh, got you now I think... maybe it is just the order of preds in the cond... the big question of course if changing the order breaks other things. will have a play with this |
ok so this is |
Yeah, ok. Btw. what about rewriting via tools.analyzer or something more clever in mr anderson. I guess you have experience with this, because of clojure-refactor. Would that be too slow in practice? Any ideas? I guess it would be quite an effort but way more reliable. Wdyt? |
the defacto analyzer now is clj-kondo which is rewrite-clj based (just like mranderson btw). I could use rewrite-clj or kondo to process the ns body but not sure how performant would that be... the idea between splitting processing the ns macro and the ns body is that ns body processing should be relatively simple -- this assumption deffo shows cracks here |
Sounds like we might be talking about some explorations I was wondering about too. Please let me know if anybody is diving into this as it might affect stuff I'll be looking into sometime soon. |
I've read the above but I want to make sure I understand. Is the crux of this issue that MrAnderson does not handle a Or is there also another separate issue? |
@lread The issue is that if you choose a rewrite prefix with a dash in its name (Cider uses For symbols that reference a function for example this works fine, but it does not work for records. Record references need to be made in Java style, where dashes are replaced with underscores. In the case of Instaparse Mr Anderson produced this record reference:
But this is wrong. It should be:
Since this is a Java class under the hood. |
Ah, thanks @r0man, I saw some conversation around But it is simply what you originally reported, it seems! |
well, it is just a tiny bit more tricky than that ;) the one thing to keep in mind that mranderson analyzes the ns macro (with rewrite clj) but does simple regexp based replace in the ns body. if the prefix has a dash in it mranderson has no way to decide if it needs to use dashed or underscored version of it in the body IF the symbol itself does not have dash or underscore in it. it would need to look at the surroundings (ie. understand the context) to be able to do it. |
Thanks for the clarification @benedekfazekas, that helps too. |
This commit changes the Mr Anderson project prefix from cider.nrepl.inlined-deps to cider.nrepl.inlined.deps. This avoids issues with renaming fully qualified record references. See benedekfazekas/mranderson#73
This commit changes the Mr Anderson project prefix from cider.nrepl.inlined-deps to cider.nrepl.inlined.deps. This avoids issues with renaming fully qualified record references. See benedekfazekas/mranderson#73
This commit changes the Mr Anderson project prefix from cider.nrepl.inlined-deps to cider.nrepl.inlined.deps. This avoids issues with renaming fully qualified record references. See benedekfazekas/mranderson#73
When rewriting dependencies with Mr Anderson and the rewrite prefix namespace contains dashes, defrecord instances are not referenced correctly.
Cider uses the "cider.nrepl.inlined-deps" prefix for it's rewritten dependencies.
Mr Anderson rewrites a record reference such as:
to this:
This is however not the right way to refer to a fully qualified record. The correct way would be to replace the dash in the name with an underscore (but only when referencing classes/records, not functions) :
I worked around this for now by using the "cider.nrepl.inlined.deps" namespace in Cider which avoid this issue.
The text was updated successfully, but these errors were encountered: