-
Notifications
You must be signed in to change notification settings - Fork 181
info
and eldoc
ops: accept a Compliment-style context
parameter
#815
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
Changes from all commits
65c34d9
2010733
635ea13
e9ceb76
1313661
94cd87a
614df43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
(ns cider.nrepl.middleware.info | ||
(:require | ||
[compliment.context] | ||
[compliment.sources.class-members] | ||
[cider.nrepl.middleware.util :as util] | ||
[cider.nrepl.middleware.util.cljs :as cljs] | ||
[cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]] | ||
|
@@ -57,9 +59,47 @@ | |
blacklist | ||
util/transform-value)))) | ||
|
||
(defn- extract-class-from-compliment | ||
"Given a Compliment-style `context`, returns the inferred class name | ||
of the object placed at __prefix__." | ||
[ns-str context] | ||
(when (and (seq ns-str) | ||
(seq context)) | ||
(try | ||
(when-let [ns-obj (find-ns (symbol ns-str))] | ||
(let [c (compliment.context/cache-context context) | ||
^Class c (compliment.sources.class-members/try-get-object-class ns-obj c)] | ||
(some-> c .getName))) | ||
(catch Exception _ | ||
;; We can always be analyzing a broken context. | ||
nil)))) | ||
|
||
(defn info | ||
[{:keys [ns sym symbol class member] :as msg}] | ||
(let [[ns sym class member] (map misc/as-sym [ns (or sym symbol) class member]) | ||
[{:keys [ns sym class member context] | ||
legacy-sym :symbol | ||
:as msg}] | ||
(let [sym (or (not-empty legacy-sym) | ||
(not-empty sym)) | ||
class (try | ||
(or (when (and (seq class) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this nil-punning here? I still think it doesn't read very well. :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure of what the alternative would be (I had written a suggestion, but it wasn't accurate) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine either way - I just don't like much mixing the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (my main point was the one I made earlier - that probably checking for empty strings is redundant, although I understand your reasoning as well) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A nice convention is to exclusively use |
||
(seq ns) | ||
(find-ns (symbol ns))) | ||
(some-> ^Class (ns-resolve (find-ns (symbol ns)) | ||
(symbol class)) | ||
.getName)) | ||
(not-empty class) | ||
(when (some-> sym (str/starts-with? ".")) | ||
(extract-class-from-compliment ns context))) | ||
(catch Exception e | ||
nil)) | ||
java? (seq class) | ||
[ns sym class member] (mapv misc/as-sym [ns | ||
(cond-> sym | ||
(and (seq sym) | ||
java?) | ||
(str/replace #"^\." "")) | ||
class | ||
member]) | ||
env (cljs/grab-cljs-env msg) | ||
info-params (merge {:dialect :clj | ||
:ns ns | ||
|
@@ -68,10 +108,9 @@ | |
{:env env | ||
:dialect :cljs}))] | ||
(cond | ||
java? (info/info-java class (or member sym)) | ||
(and ns sym) (info/info* info-params) | ||
(and class member) (info/info-java class member) | ||
:else (throw (Exception. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
"Either \"symbol\", or (\"class\", \"member\") must be supplied"))))) | ||
:else nil))) | ||
|
||
(defn info-reply | ||
[msg] | ||
|
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.
Why do you need
not-empty
here?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.
For discarding empty strings
I don't necessarily expect them, but I've found it's a good habit to handle them.
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.
Yeah, I figured as much although clients are generally expected to omit params instead of sending empty strings. I don't think we've got any such checks in cider-nrepl, that's why I've mostly done "truthy" check instead. Anyways, not a big deal right now, but something we can discuss later for the sake of consistency.
Uh oh!
There was an error while loading. Please reload this page.
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.
🤝
In an ideal world we'd have something like Spec checking/coercion at the edges