Skip to content

Commit d9c100f

Browse files
authored
Merge pull request #8 from ruby/fix_closed_completion
Do not completion `foo()bar` `:"foo"bar`
2 parents 8ab8496 + cb30c74 commit d9c100f

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/repl_type_completor.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def analyze_code(code, binding = Object::TOPLEVEL_BINDING)
8181
[:require_relative, content]
8282
end
8383
when Prism::SymbolNode
84+
return unless !target_node.closing || target_node.empty?
85+
8486
name = target_node.value.to_s
8587
if parents.last.is_a? Prism::BlockArgumentNode # method(&:target)
8688
receiver_type, _scope = calculate_type_scope.call target_node
@@ -89,6 +91,8 @@ def analyze_code(code, binding = Object::TOPLEVEL_BINDING)
8991
[:symbol, name] unless name.empty?
9092
end
9193
when Prism::CallNode
94+
return if target_node.opening
95+
9296
name = target_node.message.to_s
9397
return [:lvar_or_method, name, calculate_scope.call] if target_node.receiver.nil?
9498

test/repl_type_completor/test_repl_type_completor.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ def test_call
6464
assert_doc_namespace('Object::rand', 'Object.rand')
6565
end
6666

67+
def test_closed_no_completion
68+
# `:"bin"` should not complete `:"bin"ding`
69+
assert_nil(ReplTypeCompletor.analyze(':"bin"', binding: binding))
70+
# `ex()` should not complete `ex()it`
71+
assert_nil(ReplTypeCompletor.analyze('ex()', binding: binding))
72+
end
73+
6774
def test_lvar
6875
bind = eval('lvar = 1; binding')
6976
assert_completion('lva', binding: bind, include: 'r')

0 commit comments

Comments
 (0)