Skip to content

Commit dbf5501

Browse files
authored
Only show local completion when there is no receiver (#2290)
1 parent 1f6516a commit dbf5501

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

lib/ruby_lsp/listeners/completion.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ def complete_methods(node, name)
328328
def add_local_completions(node, name)
329329
return if @global_state.has_type_checker
330330

331+
# If the call node has a receiver, then it cannot possibly be a local variable
332+
return if node.receiver
333+
331334
range = range_from_location(T.must(node.message_loc))
332335

333336
@node_context.locals_for_scope.each do |local|

test/requests/completion_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,28 @@ def do_something(abc1, abc2, abc3)
11361136
end
11371137
end
11381138

1139+
def test_completion_for_locals_only_happens_when_there_is_no_receiver
1140+
source = +<<~RUBY
1141+
class Child
1142+
def do_something
1143+
abc = 123
1144+
1145+
foo.a
1146+
end
1147+
end
1148+
RUBY
1149+
1150+
with_server(source, stub_no_typechecker: true) do |server, uri|
1151+
server.process_message(id: 1, method: "textDocument/completion", params: {
1152+
textDocument: { uri: uri },
1153+
position: { line: 4, character: 9 },
1154+
})
1155+
1156+
result = server.pop_response.response
1157+
assert_empty(result.map(&:label))
1158+
end
1159+
end
1160+
11391161
private
11401162

11411163
def with_file_structure(server, &block)

0 commit comments

Comments
 (0)