Skip to content

Commit

Permalink
Result#type and Result#prefix
Browse files Browse the repository at this point in the history
To handle and override Symbol.all_symbols completion in IRB
  • Loading branch information
tompng committed Oct 22, 2024
1 parent 053dc89 commit 482eda5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/repl_type_completor/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def initialize(analyze_result, binding, source_file)
@source_file = source_file
end

def type
@analyze_result[0]
end

def prefix
@analyze_result[1]
end

def completion_candidates
verbose, $VERBOSE = $VERBOSE, nil
candidates = case @analyze_result
Expand Down
2 changes: 2 additions & 0 deletions sig/repl_type_completor.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module ReplTypeCompletor
VERSION: String

class Result
def type: () -> Symbol
def prefix: () -> String
def completion_candidates: () -> Array[String]
def doc_namespace: (String) -> String?
end
Expand Down
3 changes: 3 additions & 0 deletions test/repl_type_completor/test_repl_type_completor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def test_method_block_sym
end

def test_symbol
result = ReplTypeCompletor.analyze(':symbol_prefix', binding: binding)
assert_equal :symbol, result.type
assert_equal 'symbol_prefix', result.prefix
prefix = ':test_com'
sym = :test_completion_symbol
assert_completion(prefix, include: sym.inspect.delete_prefix(prefix))
Expand Down

0 comments on commit 482eda5

Please sign in to comment.