Skip to content

Commit

Permalink
Merge pull request #164 from zachhaitz/master
Browse files Browse the repository at this point in the history
Don't autocomplete initialize
  • Loading branch information
soutaro committed Jul 7, 2020
2 parents eb1a360 + 228ed64 commit c968792
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/steep/project/completion_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def method_items_for_receiver_type(type, include_private:, prefix:, position:, i
if name.to_s.start_with?(prefix)
if word_name?(name.to_s)
method.method_types.each do |method_type|
next if disallowed_method?(name)
items << MethodNameItem.new(identifier: name,
range: range,
definition: method,
Expand Down Expand Up @@ -298,6 +299,13 @@ def index_for(string, line:, column:)
def inherited_method?(method, type)
method.implemented_in&.name&.name != type.name&.name
end

def disallowed_method?(name)
# initialize isn't invoked by developers when creating
# instances of new classes, so don't show it as
# an LSP option
name == :initialize
end
end
end
end
7 changes: 3 additions & 4 deletions test/completion_provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_on_method_identifier
end

provider.run(line: 1, column: 5).tap do |items|
assert_equal [:class, :initialize, :itself, :nil?, :tap, :to_s], items.map(&:identifier).sort
assert_equal [:class, :itself, :nil?, :tap, :to_s], items.map(&:identifier).sort
end
end
end
Expand Down Expand Up @@ -104,7 +104,6 @@ def test_dot_trigger
provider.run(line: 1, column: 4).tap do |items|
assert_equal [
{ :identifier=>:class, :inherited_method=>true },
{ :identifier=>:initialize, :inherited_method=>true },
{ :identifier=>:itself, :inherited_method=>true },
{ :identifier=>:nil?, :inherited_method=>true },
{ :identifier=>:size, :inherited_method=>false },
Expand Down Expand Up @@ -161,12 +160,12 @@ def world
EOR

provider.run(line: 3, column: 0).tap do |items|
assert_equal [:@foo1, :@foo2, :class, :gets, :initialize, :itself, :nil?, :puts, :require, :tap, :to_s, :world],
assert_equal [:@foo1, :@foo2, :class, :gets, :itself, :nil?, :puts, :require, :tap, :to_s, :world],
items.map(&:identifier).sort
end

provider.run(line: 5, column: 0).tap do |items|
assert_equal [:attr_reader, :block_given?, :class, :gets, :initialize, :itself, :new, :nil?, :puts, :require, :tap, :to_s],
assert_equal [:attr_reader, :block_given?, :class, :gets, :itself, :new, :nil?, :puts, :require, :tap, :to_s],
items.map(&:identifier).sort
end
end
Expand Down

0 comments on commit c968792

Please sign in to comment.