From 482eda5251a48f03b3243f45ad2e665bdf2874f9 Mon Sep 17 00:00:00 2001 From: tompng Date: Wed, 23 Oct 2024 00:14:51 +0900 Subject: [PATCH] Result#type and Result#prefix To handle and override Symbol.all_symbols completion in IRB --- lib/repl_type_completor/result.rb | 8 ++++++++ sig/repl_type_completor.rbs | 2 ++ test/repl_type_completor/test_repl_type_completor.rb | 3 +++ 3 files changed, 13 insertions(+) diff --git a/lib/repl_type_completor/result.rb b/lib/repl_type_completor/result.rb index 4d1c72b..b58db8a 100644 --- a/lib/repl_type_completor/result.rb +++ b/lib/repl_type_completor/result.rb @@ -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 diff --git a/sig/repl_type_completor.rbs b/sig/repl_type_completor.rbs index fd964ad..13371bd 100644 --- a/sig/repl_type_completor.rbs +++ b/sig/repl_type_completor.rbs @@ -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 diff --git a/test/repl_type_completor/test_repl_type_completor.rb b/test/repl_type_completor/test_repl_type_completor.rb index da17e88..c2ca7a2 100644 --- a/test/repl_type_completor/test_repl_type_completor.rb +++ b/test/repl_type_completor/test_repl_type_completor.rb @@ -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))