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

qualified-methods source #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eval
Copy link
Contributor

@eval eval commented Feb 18, 2024

This PR is a draft and meant for input.

This adds a source :compliment.sources.class-members/qualified-methods that should aid completions for Clojure v1.12.

Examples:

user=> (compliment.core/completions "java.util.Date/")
({:candidate "java.util.Date/UTC", :type :static-method}
 {:candidate "java.util.Date/new", :type :constructor}
 {:candidate "java.util.Date/from", :type :static-method}
 {:candidate "java.util.Date/wait", :type :method}
 {:candidate "java.util.Date/after", :type :method}
 {:candidate "java.util.Date/clone", :type :method}
 {:candidate "java.util.Date/parse", :type :static-method}
 {:candidate "java.util.Date/before", :type :method}
 {:candidate "java.util.Date/equals", :type :method}
 {:candidate "java.util.Date/getDay", :type :method}
 {:candidate "java.util.Date/notify", :type :method}
 {:candidate "java.util.Date/getDate", :type :method}
 {:candidate "java.util.Date/getTime", :type :method}
 {:candidate "java.util.Date/getYear", :type :method}
 {:candidate "java.util.Date/setDate", :type :method}
 {:candidate "java.util.Date/setTime", :type :method}
 {:candidate "java.util.Date/setYear", :type :method}
 {:candidate "java.util.Date/getClass", :type :method}
 {:candidate "java.util.Date/getHours", :type :method}
 {:candidate "java.util.Date/getMonth", :type :method}
 {:candidate "java.util.Date/hashCode", :type :method}
 {:candidate "java.util.Date/setHours", :type :method}
 {:candidate "java.util.Date/setMonth", :type :method}
 {:candidate "java.util.Date/toString", :type :method}
 {:candidate "java.util.Date/compareTo", :type :method}
 {:candidate "java.util.Date/notifyAll", :type :method}
 {:candidate "java.util.Date/toInstant", :type :method}
 {:candidate "java.util.Date/getMinutes", :type :method}
 {:candidate "java.util.Date/getSeconds", :type :method}
 {:candidate "java.util.Date/setMinutes", :type :method}
 {:candidate "java.util.Date/setSeconds", :type :method}
 {:candidate "java.util.Date/toGMTString", :type :method}
 {:candidate "java.util.Date/toLocaleString", :type :method}
 {:candidate "java.util.Date/getTimezoneOffset", :type :method})

;; Introducing documentation for constructors
user=> (println (compliment.core/documentation "java.util.Date/new"))
java.util.Date.new
  ()
  (String)
  (long)
  (int int int)
  (int int int int int)
  (int int int int int int)

Questions/TBD:

  • as this only makes sense when using Clojure 1.12 this source should probably be disabled by default.
    That would need some changes to how defsource adds sources and then something like (compliment.core/completions "java.util.Date/" {:sources/include #{:other/source}})?
  • when combined with source :compliment.sources.class-members/static-members there will be duplicates.
    Not sure if this needs handling.
  • documentation for constructors.
    Not sure if/what else to add (constructors shown are all public).

Do:

  • add tests

(interpose "\n")
join))
(let [sort-members (fn [[^Class cl members]]
[cl (sort-by #(.getParameterCount %)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This changes order of signatures from least arguments to most also for existing (static) members sources. This should help with picking the right annotations.

@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2024

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (41ac6c1) 94.73% compared to head (0ed280b) 93.79%.

Files Patch % Lines
src/compliment/sources/class_members.clj 83.54% 11 Missing and 2 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #117      +/-   ##
==========================================
- Coverage   94.73%   93.79%   -0.94%     
==========================================
  Files          12       12              
  Lines         854      886      +32     
  Branches       30       32       +2     
==========================================
+ Hits          809      831      +22     
- Misses         15       23       +8     
- Partials       30       32       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@eval eval force-pushed the qualified-methods branch 2 times, most recently from 82c10b0 to 398c3ba Compare February 18, 2024 17:42
@alexander-yakushev
Copy link
Owner

Thank you for getting onto this!

A couple of immediate comments.

  1. I see this not as a separate source, but as the part of current :static-members source (which would change the name to something like :qualified-members. Then, before giving user the result, it should check for Clojure version whether to only yield the static fields/methods, or all of them.
  2. Deduplication is important but it should not be done at the top level of the API. Each source has to deduplicate its candidates.
  3. Caching all qualified members per-class should be done in one place, not two separate caches for static methods and non-static ones.

@eval
Copy link
Contributor Author

eval commented Feb 19, 2024

Thanks for your feedback.

  • I see this not as a separate source, but as the part of current :static-members source (which would change the name to something like :qualified-members. Then, before giving user the result, it should check for Clojure version whether to only yield the static fields/methods, or all of them.

So it could be a patch that removes the :static-members-source? If so: should we keep the static-members-* public vars?

  • Deduplication is important but it should not be done at the top level of the API. Each source has to deduplicate its candidates.

Makes sense!

  • Caching all qualified members per-class should be done in one place, not two separate caches for static methods and non-static ones.

👍

@alexander-yakushev
Copy link
Owner

alexander-yakushev commented Feb 19, 2024

So it could be a patch that removes the :static-members-source? If so: should we keep the static-members-* public vars?

Yes, I think we can do that and bump the minor version of Compliment along. It will be a significant change after all.

This supports Clojure's 1.12 qualified methods and constructors. So not
only should static methods and fields be completed but also constructors
and instance methods via the same `Class/method` format, e.g. `Long/new`.
@eval
Copy link
Contributor Author

eval commented Feb 19, 2024

Made the changes. Let me know if something's missing.

@eval eval changed the title DRAFT qualified-methods source qualified-methods source Feb 19, 2024
@alexander-yakushev
Copy link
Owner

Hi @eval! Would you have the time to update this to the new change in 1.12 alpha? With static and non-static members being separated again, we can keep the current sources. The only thing that would change is that :members source would read the Class/ prefix, filter by it like it currently filters by a type tag, but then attach the prefix to the generated candidates.

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.

None yet

3 participants