-
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
Better completion using types #734
Comments
To help us better test this feature, what do you think about adding |
Looks good. I don't know if its easy or hard, but we should try it. Lrama https://github.com/ruby/lrama started to use RBS and Steep |
Firstly, thank you for the considerable effort you've put into this feature ❤️ General Feedback
The reason for the latter is due to the critical nature of this feature in the users' workflow. If anything goes wrong, it could heavily impact our users and potentially erode their trust in IRB. The introduction of the current autocompletion with Ruby 3.1, which was enabled by default, led to numerous issues as seen in #445. Although I believe this feature will be better tested and reviewed with our team of IRB maintainers, I'd like to avoid a similar situation as much as possible. Public Rollout (Enabling by Default)Personally, I think we can aim for the end of next year. However, before that, we need to:
Hopefully by then we can drop Ruby 2.7 and add Prism as a dependency too. Questions about Maintenance and Future DevelopmentWith the completion results now depending on a variety of factors, such as users' type signatures, community-contributed signatures, and the type analyzer itself, we need to consider:
Additional Thoughts/Concerns
|
Add Completion section to
Type analyzing is simple (less functional) than Steep. We should determine fixing the difference is possible in the simplified specification or not. (aims to avoid extra maintenance cost)
Measure how many user enabling and re-disabling it. Any idea of comparing with extra maintenace effort?
We can simplify some of the analysis that causing maintenance problem. example:
Yes, we should. |
That's helpful and I did notice that. But what I'm asking is in a broader sense, like:
It will be great to have a few examples demonstrating this in the readme so we set the right expectation to other maintainers and our users. I think there could also be cases where it's more powerful than Steep given we have runtime info? Examples of them should be mentioned too.
I think we have limited options to measure the benefit it brings to the community. Code searching may not be too helpful because if people enable this at project-level Wrt the extra effort, I think the we can get a sense of it by counting PRs associated with these components. I haven't think of a way to compare the two though. It's likely that we won't be able to make any clear rule on this, but it's important that we keep this in mind.
Thank you for these examples 👍
That integration could require some extra work because currently its console can't talk to individual threads directly. |
For reporting issues, single file repro is hard because of the setup to create binding(self object, module nesting, variables) and environment(sig, rbs_collection.yaml).
Looks good 👍 |
@tompng Can you start another PR, maybe on top of #708, to draft the documentation for this feature? I think we need to cover these:
|
I read part of IRB#708 and this discussion. Thanks for making the Issue. My thoughts
|
I vaguely think that it would be helpful to have a debugging feature that displays something like a backtrace of why the current list of autocomplete candidates was generated. |
#708 can do something like this: irb(main):001> a, b = 1, 'a'
=> [1, "a"]
irb(main):002> IRB::TypeCompletion::Completor.new.analyze('[a, b].map(&:a', binding)
=> [:call, Integer | String, "a", false]
irb(main):003> res = IRB::TypeCompletion::Completor.new.analyze('a.times {|aa| a', binding)
=> [:lvar_or_method, "a", #<IRB::TypeCompletion::Scope:0x0000000107740dd0>]
irb(main):004> res[2].local_variables
=> ["aa", "res", "a", "b", "_"]
irb(main):005> res[2].self_type
=> Object I think adding a method or command that takes |
Now asking to change the current implementation, but I think a benefit of extracting the completor implementation to a gem is that it will give us better dependency control and simpler implementation: With the current approach, we need to passively check the version of If
And in IRB, we simply ask users to have |
I see. That's right, it makes sense. NamingAs a separate gem, the name Completion APII think completion_candidates and doc_namespace api is enough for the first version. |
I've been thinking the word
I think it matches the fact that we combine typing and binding information together to power the completion. But I'm not sure if people would think the name If the above idea doesn't sound good, I'd go with |
Naming is always the hardest thing :) I don't have a strong opinion but I feel it's better to include |
I slightly prefer using |
Compared with |
I agree with Stan. I prefer |
|
Finished by #772 |
@tompng Thank you for the vision and the tremendous effort you put into it! |
Background
Current RegexpCompletor has many limitations. It can't complete chained methods. Many wrong completions.
For better completion, we need to parse the incomplete input and perform type analysis.
We need to use
RBS
and an error tolerant parser likePrism
.PullRequest
WIP pull request is opend in #708.
Fallbacks to RegexpCompletor if Prism is not available.
Performance
RBS loading performance depends on
rbs_collection.yml
and project's rbs size undersig/
dir. It takes 0.168721s when there is no yml and sig.Completion performane depends on code size editing in irb. For example below, it only analyze
"n.times do\n _1."
with binding that knows the actual value ofn
.Analyzing 1161 lines takes 0.072726s. For comparision, coloring code takes 0.057202s
Accuracy
Comparision with current RegexpCompletor
As far as I know, the new completor can complete every case that RegexpCompletor can complete, even if RBS is not available.
With RBS
When RBS is available, it can complete more.
In Rails apps
Adding
rbs_collection.yaml
andsig/*.rbs
to the Rails project will significantly improve accuracy.Article.first.author.email.und
can completeString#underscore
if types are defined in project's sig directory.Providing good completion experience in
rails console
will be a motivation for users to write.rbs
in their project.Other type analysis libraries
This completor is a REPL-first type analyzer. It uses few information about the project codebase and many dynamic information from binding. Other type analyzer uses lots of project's code and no binding information.
I think it's hard to use another type analyzer and integrate with binding information. Maybe this could change in the future.
Where to have this code, IRB or bundled/default gem?
I want to have this code inside IRB's repository.
I want to enable it by default, so this code should be inside IRB or default/bundled gem, not normal gem that needs installation.
Want to completely replace RegexpCompletor in the future, I think default completor can be controlled inside IRB.
I think the possible user of REPL-first completor is only IRB.
It's easy to decide and have it inside IRB. As a bundled or default gem, it should be discussed in
bugs.ruby-lang.org
.My opinion is, let's include it, get feedbacks, consider splitting it or not later.
The text was updated successfully, but these errors were encountered: