Skip to content
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

cljr-slash using suggest-libspecs middleware op #532

Merged
merged 14 commits into from
Oct 11, 2022

Conversation

dgtized
Copy link
Contributor

@dgtized dgtized commented Sep 4, 2022

Implements #531. Still need to add changelog/readme updates if this approach is accepted.

If the defcustom cljr-slash-uses-suggest-libspec is enabled, cljr-slash will query the new suggest-libspec middleware op for suggested namespaces.

Currently it sends over the entire cljr-magic-require-namespaces as the preferred-aliases map, that may require pre-processing at some point, but the placeholder seems correct. It also correctly identifies if code block is in a conditional language context, and provides that information to the middleware to in order to assist generating recommendations.

Finally, as it's using completing-read to select namespaces, if the user inserts their own content into the response, that will be inserted as the new libspec. This allows the user to reference a new libspec, or edit it to include refers or require-macro. In the future, it might make sense to use the universal argument to temporarily force cljr-magic-requires to use :prompt, allowing a user to insert a require of their own choice more easily.

Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • The new code is not generating byte compile warnings (run cask exec emacs -batch -Q -L . -eval "(progn (setq byte-compile-error-on-warn t) (batch-byte-compile))" clj-refactor.el)
  • All tests are passing (run ./run-tests.sh)
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)
  • Fix wiki docs to reference the cljr-slash-uses-suggest-libspec defcustom

Thanks!

Calls the cljr middleware `suggest-libspec`, specifying a string representing
the alias-ref, a tuple specifying language context, and capturing the
`cljr-magic-require-namespaces` defcustom.
Detects the context of buffer and at point, returning a tuple consisting of the
language context of the buffer, and the language context at the current point.
If the `cljr-slash-uses-suggest-libspec` defcustom is enabled, the libspec
recommendations will come from the `suggest-libspec` middleware instead of
`namespace-aliases` by way of the `cljr--prompt-or-select-libspec` method.

No longer filtering the resulting libspec to check if
cljr--in-namespace-declaration is true, as that should be handled by the
backend, or if the user types in their own completing-read value, presumably
they want to include that regardless of the existing namespaces.

Completing-read is allowed to return user input, regardless of whether that is
a known libspec.
Copy link
Member

@vemv vemv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me. Thanks much!

I assume you've tried this over the real middleware we released for refactor-nrepl.

  • Does it work correctly?
  • Do you need this PR merged asap, or are you comfortable by working with your clj-refactor fork day-to-day?
  • Do you have any new feedback item for the refactor-nrepl middleware, or shall we implement it as planned?

Cheers - V

clj-refactor.el Outdated Show resolved Hide resolved
clj-refactor.el Outdated Show resolved Hide resolved
clj-refactor.el Outdated
Passes through the custom `cljr-magic-require-namespaces' so that
users can specify default recommended alias prefixes that may not
appear in the project yet."
(seq-let (buffer-context point-context) language-context
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seq-let is probably nice but this lib (and I, coincidentally) only use seq.el for "seq stuff", not for other conveniences which would increase cognitive load to casual maintainers.

I'm generally happy with let* (and prefer let* over let, no matter what)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed this to your recommendation. From my perspective, destructuring binding is much easier to follow over manually parsing out car/cadr of each element, but to each their own. I appreciate your concern about cognitive load from unfamiliar constructs, but it's also frustrating and discouraging as a contributor to so frequently encounter code included in emacs core that is then dismissed at review. Do you have a style guide somewhere that I could follow to discover which are recommended and which are discouraged instead of discovering all of these at review time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could follow to discover which are recommended and which are discouraged instead of discovering all of these at review time?

Not that I know of

Generally, afaict in clojure-emacs .el code we lean toward simple constructs. Even then, different reviewers might have different preferences.

My genuine recommendation would be to simply be ready to tweak some things upon request. I myself cannot predict the feedback I'll receive in the variety of repos I contibute to - some little churn on superficial things is just part of life! :)

clj-refactor.el Show resolved Hide resolved
clj-refactor.el Outdated Show resolved Hide resolved
tests/unit-test.el Show resolved Hide resolved
tests/unit-test.el Show resolved Hide resolved
tests/unit-test.el Outdated Show resolved Hide resolved
tests/unit-test.el Outdated Show resolved Hide resolved
tests/unit-test.el Show resolved Hide resolved
@dgtized
Copy link
Contributor Author

dgtized commented Sep 7, 2022

I believe I've addressed all outstanding concerns, updated external documentation and added a changelog entry as well as manually retesting it in a project. I would much prefer we merge this over letting it bitrot in review. It's not perfect but it will allow folks to start testing and working off of the new middleware so we can iterate from there. I believe the next steps beyond this PR on the cljr-refactor side are to address the reader conditional parsing in #533, and then document the new syntax for cljr-magic-require-namespaces in #530, though I think all of the logic there is in the middleware, so it's probably better to document that after it's implemented.

I believe that API is solid enough to move forward with. I didn't encounter anything critical with it in development, but now that the logic has moved into the middleware, it's likely we won't see issues in the recommendations until we encounter them in actual use.

Let me know if there is any other critical concerns that need to be addressed prior to merge.

@dgtized
Copy link
Contributor Author

dgtized commented Oct 9, 2022

Just checking back in to see what else needs to be done here before it's merged.

@vemv
Copy link
Member

vemv commented Oct 9, 2022

Thanks for the ping! Will check out today / tomorrow at most

@vemv vemv merged commit db89b55 into clojure-emacs:master Oct 11, 2022
@vemv
Copy link
Member

vemv commented Oct 11, 2022

Thanks again for this first step!

Should clojure-emacs/refactor-nrepl#384 be implemented as planned? Anything that came to mind more recently?

@dgtized
Copy link
Contributor Author

dgtized commented Oct 11, 2022

I think we can proceed with the remainder of clojure-emacs/refactor-nrepl#384 as planned. However, until #533 is implemented, we won't know the correct current language context at point. My expectation remains that we will have more tweaking required on the exact recommendations from the backend, but that won't be as visible until it's in use. I'll see if I can take a stab at #533 in the coming week or two, though so it can operate with the correct local information.

Thanks for merging this, and the review!

@vemv
Copy link
Member

vemv commented Oct 11, 2022

Nice! I'll try to advance on the middleware, do feel free to ping if you'd need to have it sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants