-
Notifications
You must be signed in to change notification settings - Fork 121
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
Type based completion using Prism and RBS #708
Conversation
a8d1547
to
46ae44b
Compare
Using static analysis to provide auto-completion is a surprising direction for IRB which already has access to a lot of dynamic information. It seems like you are reimplementing features that belong more to a static type checker such as Steep or Sorbet or IDE features already covered by the Ruby LSP. I wonder if IRB is the right place for this? |
Yes, it's a reimplemention but has some difference from other static type checker.
So I think it is worth making a static + dynamic type analyzer specialized for REPL. |
Since we're going to need a full analyzer with dependency on |
14ca0bb
to
92d2639
Compare
7fe5db3
to
121ae29
Compare
121ae29
to
43fbbe2
Compare
43fbbe2
to
dadd45b
Compare
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.
Honestly this looks great. It's super impressive how much work you've put in.
Please let me know if there's anything in the prism API that could be added to help you.
dadd45b
to
b8137d4
Compare
lib/irb/type_completion/types.rb
Outdated
end | ||
end | ||
|
||
def self.type_from_object_recursive(object, max_level:) |
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 let's just do 1 level for now + limit it to 50 samples maybe. In Rails console it's not rare to call users = User.some_scope.to_a
, which could have thousands of objects.
…w, calculation depth is 1
976487d
to
12efb40
Compare
386d0ca
to
124f80f
Compare
…definition is not supported)
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.
Amazing work 👍
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.
I'd agree with shipping this feature with Ruby 3.3
Functions I would like to add gradually:
- Freely change the completer within the IRB session
- To display a kind of a "backtrace" of how the completion candidates are created with one simple command
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.
✨
(ruby/irb#708) * Add completor using prism and rbs * Add TypeCompletion test * Switchable completors: RegexpCompletor and TypeCompletion::Completor * Add completion info to irb_info * Complete reserved words * Fix [*] (*) {**} and prism's change of KeywordParameterNode * Fix require, frozen_string_literal * Drop prism<=0.16.0 support * Add Completor.last_completion_error for debug report * Retrieve `self` and `Module.nesting` in more safe way * Support BasicObject * Handle lvar and ivar get exception correctly * Skip ivar reference test of non-self object in ruby < 3.2 * BaseScope to RootScope, move method objects constant under Methods * Remove unused Splat struct * Drop deeply nested array/hash type calculation from actual object. Now, calculation depth is 1 * Refactor loading rbs in test, change preload_in_thread not to cache Thread object * Use new option added in prism 0.17.1 to parse code with localvars * Add Prism version check and warn when :type completor cannot be enabled * build_type_completor should skip truffleruby (because endless method definition is not supported) ruby/irb@1048c7ed7a
Implement type based autocompletion #734 using Prism and RBS
Default completor is still
:regexp
. To enable:type
completor, writeIRB.conf[:COMPLETOR] = :type
to irbrc.When Prism is available
When Prism and RBS is available
When Prism is not available, it fallbacks to RegexpCompletor
This pull request will port gem katakata_irb's completion(https://github.com/tompng/katakata_irb/) to IRB.