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

Fix info lookups from namespaces that don't yet exist #123

Merged
merged 1 commit into from
Sep 20, 2021

Conversation

plexus
Copy link
Contributor

@plexus plexus commented Sep 7, 2021

Currently when doing a var-info from a file before evaluating the ns form
always fails. The namespace object does not yet exist, and so none of the var
resolution strategies work.

However fully-qualified vars, namespace names, or built-ins (clojure.core
functions) could all be resolved, and it's frustrating that they aren't.

This adds a check to see if (find-ns ns) returns anything. If not then we are
initiating the lookup from a namespace that has not yet been defined, in which
case none of the lookup strategies will proceed, so we continue with doing the
lookup as if it had been initiated from clojure.core.

Before submitting a PR make sure the following things have been done:

  • The commits are consistent with our contribution guidelines
  • You've added tests to cover your change(s)
  • All tests are passing
  • The new code is not generating reflection warnings
  • You've updated the changelog (if adding/changing user-visible functionality)

Thanks!

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.

LGTM, the idea seems sound. Probably trying to require things would be excessively obstrusive.

Maybe worth adding some test coverage.

(some-> (find-ns unqualified-sym) (m/ns-meta)))
;; Lookups in files whose namespaces don't exist yet should still be able
;; to resolve built-ins and fully-qualified syms
(recur (assoc opts :ns 'clojure.core)))))
Copy link
Member

Choose a reason for hiding this comment

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

Very minor, but the large distance between the if and this branch makes it a bit hard to track the control flow.

By using an if-not instead one gets these "degenerate cases" out of one's way, similarly to https://wiki.c2.com/?GuardClause

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I've addressed this one. I'll still be adding a test and changelog etc.

@plexus plexus force-pushed the lookup-in-undefined-ns branch 2 times, most recently from 666599d to 10aee3d Compare September 8, 2021 10:16
Currently when doing a `var-info` from a file before evaluating the `ns` form
always fails. The namespace object does not yet exist, and so none of the var
resolution strategies work.

However fully-qualified vars, namespace names, or built-ins (clojure.core
functions) could all be resolved, and it's frustrating that they aren't.

This adds a check to see if `(find-ns ns)` returns anything. If not then we are
initiating the lookup from a namespace that has not yet been defined, in which
case none of the lookup strategies will proceed, so we continue with doing the
lookup as if it had been initiated from `clojure.core`.
@plexus plexus force-pushed the lookup-in-undefined-ns branch from 10aee3d to 99875ac Compare September 8, 2021 10:17
@plexus
Copy link
Contributor Author

plexus commented Sep 8, 2021

Added a test, appended the CHANGELOG, and swapped the if branches around as suggested by @vemv . I think from my side this is good to go.

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.

🍻

@bbatsov bbatsov merged commit 7d7f752 into clojure-emacs:master Sep 20, 2021
@bbatsov
Copy link
Member

bbatsov commented Sep 20, 2021

Nice improvement. Thanks!

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.

3 participants