Skip to content

Commit

Permalink
Fix method completion on explicit self (#1399)
Browse files Browse the repository at this point in the history
* Fix TextEdit#range for method completion

* ensure message_loc is not nil
  • Loading branch information
bjarosze authored Feb 23, 2024
1 parent b1e1092 commit 0c21f7a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ruby_lsp/listeners/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def build_method_completion(entry, node)
Interface::CompletionItem.new(
label: name,
filter_text: name,
text_edit: Interface::TextEdit.new(range: range_from_node(node), new_text: name),
text_edit: Interface::TextEdit.new(range: range_from_location(T.must(node.message_loc)), new_text: name),
kind: Constant::CompletionItemKind::METHOD,
label_details: Interface::CompletionItemLabelDetails.new(
detail: "(#{entry.parameters.map(&:decorated_name).join(", ")})",
Expand Down
1 change: 1 addition & 0 deletions test/requests/completion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ def process
assert_equal(["bar", "baz"], result.map(&:filter_text))
assert_equal(["bar", "baz"], result.map { |completion| completion.text_edit.new_text })
assert_equal(["(a, b)", "(c, d)"], result.map { |completion| completion.label_details.detail })
assert_equal([9, 9], result.map { |completion| completion.text_edit.range.start.character })
end

def test_completion_for_methods_named_with_uppercase_characters
Expand Down

0 comments on commit 0c21f7a

Please sign in to comment.