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

Allow fallback to xref backends if cider-nrepl is unloaded #3145

Merged
merged 1 commit into from
Feb 4, 2022

Conversation

vedang
Copy link
Contributor

@vedang vedang commented Feb 2, 2022

This commit addresses the following use-case: Connecting to a running
REPL which does not have cider-nrepl middleware loaded.

This can happen when connecting to remote REPLs, and even
locally (admittedly minor use-case) if you don't want to turn the
middleware on.

If cider--xref-backend returns nil, xref will move on to the next
backend. This allows using something like dumb-jump to move around
in the code-base, while also getting the benefits of a REPL window.


Before submitting the 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): No, I think this is a minor change, it is useful to me so I'm pushing it back to the community.
  • All tests are passing (eldev test): Did not check this, I hope they are.
  • All code passes the linter (eldev lint) which is based on elisp-lint and includes: Did not check linter, but there are no errors from M-x checkdoc
  • You've updated the changelog (if adding/changing user-visible functionality): Not sure this is user-visible, it simply improves the UX
  • You've updated the user manual (if adding/changing user-visible functionality):same as above

Thanks!

This commit addresses the following use-case: Connecting to a running
REPL which does not have `cider-nrepl` middleware loaded.

This can happen when connecting to remote REPLs, and even
locally (admittedly minor use-case) if you don't want to turn the
middleware on.

If `cider--xref-backend` returns nil, `xref` will move on to the next
backend. This allows using something like `dumb-jump` to move around
in the code-base, while also getting the benefits of a REPL window.
'cider)
;; Check if `cider-nrepl` middleware is loaded. Allows fallback to other xref
;; backends, if cider-nrepl is not loaded.
(when (cider-nrepl-op-supported-p "ns-path")
Copy link
Member

Choose a reason for hiding this comment

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

Won't it be better to check about this in the backend itself? Or if we go with your proposal I'd remove the connected checks in the backend implementation.

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'm not sure I understand. I made the change in this particular function because of this line:

(when cider-use-xref
          (add-hook 'xref-backend-functions #'cider--xref-backend cider-xref-fn-depth 'local))

The documentation for xref-backend-functions says that the provided function -- cider--xref-backend in this case -- should return either nil (not applicable) or an xref-backend (value for function dispatch). Once a value is returned, that backend is the only one which is used.

In the case of cider, once the backend function is registered, it will always return a truthy value of 'cider. Registration is done when cider-mode is invoked, and undone in cleanup.

Hence, I think, a basic check should be done in cider--xref-backend and better, more detailed checks should be done in the actual functions (as are implemented today).

Copy link
Member

Choose a reason for hiding this comment

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

But will this work properly if someone sideloads the middleware later? The way you describe it seems that that if the backend evaluates to nil at registration time it will just be discarded until cider-mode gets reloaded.

@vedang
Copy link
Contributor Author

vedang commented Feb 3, 2022 via email

@bbatsov
Copy link
Member

bbatsov commented Feb 4, 2022

Got it. I just wasn't sure when exactly is this function invoked.

@bbatsov bbatsov merged commit 2bc5f1e into clojure-emacs:master Feb 4, 2022
bbatsov added a commit that referenced this pull request Feb 4, 2022
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