-
Notifications
You must be signed in to change notification settings - Fork 111
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
Combine cljs and clj namespace alias candidates for magic requires #528
Comments
A few specific cases to consider:
One other future improvement to consider is: Consider merging defcustom mappings with the list returned by the middlewareIn addition to prompting for alias -> namespace mappings from the middleware, a user can add custom mappings to Unfortunately, currently, the defcustom does not mark if an alias is for a particular language context. For the default settings, it will add |
Thanks much for the issue! Will read carefully and ponder on it. As a quick one, did you know about clj-refactor.el/clj-refactor.el Lines 1945 to 1949 in 32883b3
(This feature is best explained at clojure-emacs/refactor-nrepl#369 ) I'm giving it great use. Do you think it would compose well with what you envision? Any possible conflict, necessary refinement, etc? |
I was aware of |
I'm not sure about |
Yeah, nowadays I only use |
Would you be so generous to fill a table approximately like this...?
With all possible iterations. That way I'll be able to see the intent/impact without any misunderstanding. Thanks - V |
I believe I've already accounted for this both in the comment above & in test cases included in the PR. I will attempt to summarize again though; If a codebase contains a previous usage of If a codebase contains multiple usages of an If the codebase contains no matches for the alias, then it fallback to the listing in The key difference is the current file extension is not material. If I'm in a cljs, file and I'm referencing a cljc library, when I go to a clj or cljc file I still want to see that alias suggested because it's likely it's still applicable. If I'm in a cljc file, then I want suggestions from both cljs and cljc aliases as I may be using a library from either. The annotations simply represent file types they have previously appeared in as relayed by the middle-ware, leaving the decision to the user to decide if that's the appropriate namespace to use for the given alias. In table form I guess that's:
Also, as before, if Again, I made sure to add the change under a defcustom, so this is all opt-in behavior. Every new method is tested and I'm happy to field questions if there are gaps there. |
Thanks for the table!
Regardless, features are meant to be agreed-on, non-transient, and coordinated with refactor-nrepl. Otherwise you can always experiment indefinitely in a local fork (which, if you ask me, is exactly what I do for my own productivity). I'll check #528 (comment) carefully, but please note that every time that I'm reading something that wasn't quite the requested thing (e.g. paragraphs, PR code), I'm taking time away from other things. |
n.b. I'm essentally asking for this sort of collaboration model https://github.com/clj-kondo/clj-kondo/blob/af9db3c2bbf0ed592254b0f179ffef345de3a626/doc/dev.md#start-with-an-issue-before-writing-code which is not exactly unusual. I'd understand if it can be frustrating at first, but ultimately everyone benefits from it! |
I have no trouble with that collaboration model. I also understand that it can be frustrating for you to have a change dropped in your lap without sufficient context. I do appreciate your time, and I realize you are maintaining a number of different projects, so I do understand that it takes time to get in and out of context. That is why I have tried to carefully explain the scope of the problem to help clarify context, both in the original PR and then again in this issue at your request. I apologize if that has turned out to be too verbose or somehow unclear and made it worse, that is not my intent. I'm just trying to improve the Clojurescript development experience in Emacs, and to give back to open source tooling that I have benefited form. Unfortunately, I am still uncertain what the next steps are. I would greatly appreciate feedback on the feature as I believe it's a substantial improvement on the existing behavior that others will benefit from. I do appreciate that can take a while and you are busy with many projects, so I can wait if that's the current issue. I am worried that there is some kind of misunderstanding and you are waiting on something from me. I know we discussed adding an issue requesting changes to the refactor-nrepl middleware, both to simplify this feature and to support additional feature. I'm still prepared to work on that, but I believe those are dependent on our agreement on the overarching feature described here. Is there anything else I can contribute in terms of further development or explanation to help move this along as it currently stands? |
(getting back to this asap) |
I've drafted my thoughts and will split this issue into 3-4 issues soon enough |
Any updates on splitting this into smaller issues? |
It's coming! Sorry for the delay
…On Mon, Aug 15, 2022 at 11:20 PM Charles Comstock ***@***.***> wrote:
Any updates on splitting this into smaller issues?
—
Reply to this email directly, view it on GitHub
<#528 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAI354RB3LZYDQREZR5WOH3VZKYDJANCNFSM535LYLWQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Alright, so the split is as follows: #530 Each issue depends on the previous one. If interested you'd work on 530 and 531. I'd work on 384. Sorry for the slowness, this was some dense design work which I spread across several days. Do feel free to check out 384 carefully and possibly seek any clarification. I have the feeling that the middleware would be implemented quite quicker than the tickets. Also, because of its design, it can be incrementally implemented (e.g. leave fancy Cheers - V |
This is the companion feature issue for #525 as requested.
Currently if a
cljr-slash
magic require is triggered in a project with mixed cljs, cljc and clj files,cljr-slash
first prompts for the language context and then only allows selection of namespace aliases from cases that were previously seen in that context.As example, in
scratch.cljc
if I typegl/
After selecting
clj
I get:And if I select
cljs
I am prompted to select eitherthi.ng.geom.line
orthi.ng.geom.gl.core
, which then adds the selected namespace:In this case, both
thi.ng.geom.line
&thi.ng.geom.gl.core
are cljc libraries and are applicable in both a clj and cljs context. However for my example project,thi.ng.geom.gl.core
has only been used in a cljs context previously, so the middleware incorrectly believes that alias is only applicable in a cljs context.There are several problems above, but I think think the two most critical is that
cljr-slash
incorrectly assumes that namespaces previously encountered in one context should only be presented in a matching context. The second and overlapping interface problem is that it prompts twice, and doesn't suggest all the available choices for the user to decide in a single prompt.In #525, with the defcustom
cljr-magic-require-prompts-includes-context
enabled, the behavior is:This is a single prompt, and allows the user to make their own determination if the other available aliases are applicable in the current context. This functionality is complete in #525 without requiring any changes to the middleware.
Potential Future Improvements
Force a prompt where language context does matter
In #525 if only one namespace usage matches an alias, regardless of the language context, it will immediately insert that without prompting. If we had more reliable detection of language context, or even if the current file did not match any of the language contexts the alias had previously been seen in, then it could prompt the user to verify the new require makes sense before inserting a new require.
Simplifying middleware response to reduce elisp code and allow more fine grained responses in the future
#525 converts the middleware responses from an EDN format like:
Into a list of lists like:
What I would propose is that the middleware should instead return something like:
This would reduce the amount of elisp code to convert formats, and allow for future extensions. By listing exact libspecs, it allows the completing-read to return a libspec typed in by the user manually. It also allows suggesting libspecs for an alias with an
:as-alias
,:refer
or:include-macros
. A good example would be to promp with the following libspec in a CLJS file:[clojure.test :as t :refer [deftest is] :include-macros true]
. This could also be extended to include a suggested ranking order, or another field for inserting matching:import
fields, if we can reliably associate requires aliases to imports.Automatically Suggest Reader Conditionals for Alias in CLJC file
Occasionally in a CLJC file, duplicate aliases are used in a reader conditional so that multiple libraries with identical functions can be used under a single namespace alias. For those cases, the middleware could respond something like:
Critically, it should only suggest a reader conditional if an existing libspec in the project uses a reader conditional to dispatch between different namespaces under a single alias. The latter two examples would only show up if there were clj or cljs files using that libspec in the project. This might be one of the few cases where a matching alias should be excluded from the prompt if the context does not match, as I don't think you can use a reader conditional in a cljs or clj file, and in those cases we should prefer the context specific namespace.
The text was updated successfully, but these errors were encountered: