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

Result#type and Result#prefix #40

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Result#type and Result#prefix #40

wants to merge 1 commit into from

Conversation

tompng
Copy link
Member

@tompng tompng commented Oct 22, 2024

To handle and override Symbol.all_symbols completion in IRB.
I'm thinking of using this from ruby/irb#1021

result = ReplTypeCompletor.analyze(':sym', binding:)
result.type #=> :symbol
result.prefix #=> "sym"

result = ReplTypeCompletor.analyze('[1, "2"].map(&:to_', binding:)
result.type #=> :call
result.prefix #=> "to_"
# Receiver type(Integer|String) of this :call is not exposed.

result = ReplTypeCompletor.analyze('def f(abc = 1); ab', binding:)
result.type #=> :lvar_or_method # abc(lvar) or abort(method)
result.prefix #=> "ab"
# Scope object (including self type, local variables) is not exposed.

Future plans

ReplTypeCompletor might drop returning Symbol.all_symbols because it has performance problem.

result = ReplTypeCompletor.analyze("puts :a", binding:)
result.type #=> :symbol
result.completion_candidates #=> [] (always empty array)

ReplTypeCompletor might add symbol hash key completion

hash = { foo: 1, bar: 2, baz: 3 }
result = ReplTypeCompletor.analyze("hash[:b", binding:)
result.type #=> :symbol or :symbol_hash_key(to distinguish from :symbol handled in IRB)
result.completion_candidates #=> ["ar", "az"]

To handle and override Symbol.all_symbols completion in IRB
@tompng tompng marked this pull request as draft October 27, 2024 06:24
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.

1 participant