-
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
Prompt for namespaces with language context annotation #525
Prompt for namespaces with language context annotation #525
Conversation
e434948
to
9e34cee
Compare
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.
Thanks much - code coverage looking great!
Hope not to bother much, but could you please refrain from using cl-*
facilities? Rationale
clj-refactor.el
Outdated
@@ -85,6 +86,14 @@ Any other non-nil value means to add the form without asking." | |||
(string :tag "Full namespace"))) | |||
:safe #'listp) | |||
|
|||
(defcustom cljr-magic-require-prompts-includes-context nil | |||
"Whether `cljs-slash' should include the language context in magic |
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.
"Whether `cljs-slash' should include the language context in magic | |
"Whether `cljr-slash' should include the language context in magic |
"Whether `cljs-slash' should include the language context in magic | |
"Whether `cljs-slash' should include the language context in magic |
I can switch the cl-destructuring-bind to Also I know the reason everybody avoided (require 'cl) is it infected core methods and left it confusing which behavior was in use, but I thought I do appreciate the maintenance concern, though to that end I hope someday we can eliminate I'll fix the typos and switch cl-destructuring-bind to pcase-let and then wait to hear for your preferred approach on replacing the cl-loop over the hash-table. |
ffff579
to
a68e2d9
Compare
Thanks much for the thoughtful response and subsequent commits.
Could you sum up what's needed in a refactor-nrepl issue? I'll be pleased to deliver it asap. |
Thanks, and thank you for you time spent reviewing as well. After some further thought it's not quite so tricky as I thought with seq-mapcat, though I still maintain the cl-loop is more readable here. If anything I'm more concerned about the maintainability of the mutation in the map/reduce. Regardless it's covered by a pretty comprehensive test. Changing from cl-loop to seq-mapcat changed the order of the list but the structure is still stable. I still think that replacing the entirety of Thanks again for your time. |
And you're probably right. The likelihood of removing this breaking something is slim to none IMO and given our limited resources I wouldn't go overboard maintaining a private API that's unlikely to be used by anyone. And I'll reiterate my opinion that replacing the |
@@ -36,6 +36,7 @@ | |||
(require 'yasnippet) | |||
(require 'paredit) | |||
(require 'multiple-cursors-core) | |||
(require 'cl-macs) |
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 this still needed?
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.
Quite unlikely. It has been cl-lib
for a very long 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.
clj-refactor is using cl-case, cl-incf, and cl-assert all of which are not present in cl-lib but are present in the cl-macs wrapper.
Should I add a note to the readme for this? It's user facing, but the cljr-slash feature doesn't appear to be documented there. |
It could be added in https://github.com/clojure-emacs/clj-refactor.el/wiki#magic-requires |
Happy to document it in the wiki once this is merged, I guess I was mostly curious if there was any other documentation I should update or add in this PR. |
From your screenshot, it looks like typing What if it inserted both, via a reader conditional? Especially if there's exactly just one choice for each of I know it might be some extra work but I think it's the right thing to do. It would sound very intuitive and enjoyable for users. Feel free to keep in mind this (likely) requirement when creating an issue against refactor-nrepl. Cheers - V |
I agree that case would be magical and I'm game to incrementally improve in that direction. However, I want to clarify the most common use case for this is not with libraries that have a different namespace and the same alias delineated by a reader conditional. The main use case for this change is using a known alias for a cljc library in clj file when previously it's only been used in a cljs file or the first time it shows up in a clj file and it's only been used in a cljs or cljc file. Those cases do not require a reader conditional regardless if it's in a cljc, clj, or cljs file. Before this PR those cases all required first to confirm that I wanted to search cljs or clj contexts and then allowed me to select a matching namespace. The new behavior allows the user to choose whichever library is most appropriate for the context and only treats the language context as a hint. Likewise, there are a few cases where an alias is commonly referring to a cljc library in a group of cljs files, and an entirely different library in a set of clj files but the library is not a replacement for the other. As example, I have some code where gl/ refers to Now for a few cases like |
There is one case where we can reliably insert a reader conditional, and that is when there is already a reader conditional for that alias in the project. I do however agree that it is out of scope for this PR. Note that there is no need for a reader conditional in your final example. You can simply refer to clojure.test. This sugar has been available since the 1.9.198 release of ClojureScript. See the Sugar section here: https://clojurescript.org/guides/ns-forms |
Agreed that we can reliably insert a reader conditional if it's in the project already, but AFAIK the middleware does not currently expose enough information to reliably suggest that to the user. I believe in this case it would report that as Thank you for reminding me of the clojure.test/cljs.test sugar, I'll give that a try. |
The counterpoint to working "gradually" is that I would like to avoid giving users intermediate UXs that are not representative of what we actually intend to do long-term. Likewise we also should avoid creating commits that would represent "transient states" - those can be considered churn. Very similarly, an hypothetical excess of PRs has a cost to reviewers. I would suggest that we operate in the following manner:
Thanks very much again for the work so far! -V |
If enabled, use `cljr--magic-prompt-or-select-namespace` with candidates from `cljr--magic-require-candidates` to prompt the user for which namespace to resolve an alias for.
Attempted to add tests using `cljr--in-namespace-declaration`, but that method appears to always return nil, and isn't actually working. Left that be on the other non `cljr-magic-require-prompts-include-context` path to avoid changes in behavior. Given current behavior this test is not strictly necessary on the prompting path, as candidates with existing references should already be filtered out. Leaving it for now to keep the behavior close to before. Also, there is the possibility that the `cljr--magic-prompt-or-select-namespace` could allow users to type in a custom libspec at the prompt, in which case we would still need to filter to ensure it was not a duplicate. Added some test coverage to `cljr--resolve-alias`.
It was definitely in use for cl-assert, cl-first, cl-case and a couple other examples, so probably included by one of the many libraries referenced. However this PR also added cl-loop and cl-destructuring-bind usage, so better to make it explicit.
c078368
to
123e8e3
Compare
Out of #528 where I could understand @dgtized's intent better, I designed the following split of tickets: #530 I believe the end result will be vastly simpler. In the end, as described in clojure-emacs/refactor-nrepl#384, It's better to start again from a clean slate. |
Rewrites #521 using a defcustom
cljr-magic-require-prompts-includes-context
. This is also the followup to #522, which introduced refactors to cleanly apply this change. This is an improvement to thecljr-slash
magic require functionality, where inserting a slash after an alias used elsewhere in the project will be automatically added as a namespace alias for the current file.If the defcustom
cljr-magic-require-prompts-includes-context
is set tot
,cljr-slash
will prompt for namespace completion if there is more then one match or short-circuit if only one. Instead of first prompting for language context, it now shows all the possible contexts(:clj)
,(:cljs)
, and(:clj, cljs)
the alias has been referred to elsewhere in the project along with the recommended libspec. Aliases that are shared across more then one language with the same namespace are now grouped into a single option, allowingcljr-slash
to short-circuit and add the require without prompting.If the defcustom is false, it uses the existing behavior, which if in a
cljc
file will first prompt for the language context, and then prompt for potential libspec entries to resolve the alias.Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
cask exec emacs -batch -Q -L . -eval "(progn (setq byte-compile-error-on-warn t) (batch-byte-compile))" clj-refactor.el
)./run-tests.sh
)Thanks!