Skip to content

Commit cf7aca2

Browse files
committed
Only show one level of namespace when completing class names
1 parent dc45340 commit cf7aca2

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

History.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
* RDoc::RDoc#generate was added to allow multiple generators to be used with
55
a set of parsed file info.
66
* RDoc::Options#finish can be called multiple times now.
7+
* `ri -i` only shows one level of namespace when completing class names.
78
* Bug fixes
89
* Remove windows-specific test for test_check_files, it is too hard to do.
910
Ruby commit r30811 by Usaku Nakamura.
1011
* Remove unnecessary (and wrong) platform-dependent hacks. Ruby commit
1112
r30829 by Usaku Nakamura.
13+
* Completing via Array#[<tab> in `ri -i` no longer crashes.
1214

1315
=== 3.5.3 / 2010-02-06
1416

lib/rdoc/ri/driver.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ def complete name
524524
klass_name = method ? name : klass
525525

526526
if name !~ /#|\./ then
527-
completions.push(*klasses.grep(/^#{klass_name}/))
527+
completions = klasses.grep(/^#{klass_name}[^:]*$/)
528+
completions.concat klasses.grep(/^#{name}[^:]*$/) if name =~ /::$/
528529
elsif selector then
529530
completions << klass if classes.key? klass
530531
elsif classes.key? klass_name then
@@ -910,7 +911,7 @@ def list_methods_matching name
910911
methods = store.instance_methods[ancestor]
911912

912913
if methods then
913-
matches = methods.grep(/^#{method}/)
914+
matches = methods.grep(/^#{Regexp.escape method.to_s}/)
914915

915916
matches = matches.map do |match|
916917
"#{klass}##{match}"
@@ -924,7 +925,7 @@ def list_methods_matching name
924925
methods = store.class_methods[ancestor]
925926

926927
next unless methods
927-
matches = methods.grep(/^#{method}/)
928+
matches = methods.grep(/^#{Regexp.escape method.to_s}/)
928929

929930
matches = matches.map do |match|
930931
"#{klass}::#{match}"

test/test_rdoc_ri_driver.rb

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def test_complete
249249

250250
@driver.stores = [store]
251251

252-
assert_equal %w[Foo Foo::Bar], @driver.complete('F')
252+
assert_equal %w[Foo ], @driver.complete('F')
253253
assert_equal %w[ Foo::Bar], @driver.complete('Foo::B')
254254

255255
assert_equal %w[Foo#Bar], @driver.complete('Foo#'), 'Foo#'
@@ -269,7 +269,7 @@ def test_complete_ancestor
269269
def test_complete_classes
270270
util_store
271271

272-
assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F')
272+
assert_equal %w[Foo ], @driver.complete('F')
273273
assert_equal %w[Foo:: Foo::Bar Foo::Baz], @driver.complete('Foo::')
274274
assert_equal %w[ Foo::Bar Foo::Baz], @driver.complete('Foo::B')
275275
end
@@ -278,7 +278,8 @@ def test_complete_multistore
278278
util_multi_store
279279

280280
assert_equal %w[Bar], @driver.complete('B')
281-
assert_equal %w[Foo Foo::Bar Foo::Baz], @driver.complete('F')
281+
assert_equal %w[Foo], @driver.complete('F')
282+
assert_equal %w[Foo::Bar Foo::Baz], @driver.complete('Foo::B')
282283
end
283284

284285
def test_display
@@ -603,6 +604,24 @@ def test_list_methods_matching
603604
@driver.list_methods_matching('Foo::Bar.')
604605
end
605606

607+
def test_list_methods_matching_regexp
608+
util_store
609+
610+
index = RDoc::AnyMethod.new nil, '[]'
611+
@cFoo.add_method index
612+
@store.save_method @cFoo, index
613+
614+
c_index = RDoc::AnyMethod.new nil, '[]'
615+
c_index.singleton = true
616+
@cFoo.add_method c_index
617+
@store.save_method @cFoo, c_index
618+
619+
@store.save_cache
620+
621+
assert_equal %w[Foo#[]], @driver.list_methods_matching('Foo#[]')
622+
assert_equal %w[Foo::[]], @driver.list_methods_matching('Foo::[]')
623+
end
624+
606625
def test_load_method
607626
util_store
608627

0 commit comments

Comments
 (0)