Skip to content

Commit

Permalink
Merge pull request #353 from jonathanhefner/search-results-call-seq-p…
Browse files Browse the repository at this point in the history
…arams

Extract basic `:call-seq:` params for search results
  • Loading branch information
jonathanhefner authored Dec 24, 2023
2 parents 9443521 + eb7b1fc commit 08b4252
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/sdoc/search_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@ def compute_tiebreaker_bonus(module_name, method_name, description)

def signature_for(rdoc_method)
sigil = rdoc_method.singleton ? "::" : "#"
params = rdoc_method.call_seq ? "(...)" : rdoc_method.params

params =
case rdoc_method.call_seq&.strip
when nil
rdoc_method.params
when /\A[^ (]+(?: -> .+)?\z/
"()"
when /\A[^ (]+(\(.*?\))(?: -> .+)?\z/
$1
else
"(...)"
end

"#{sigil}#{rdoc_method.name}#{params}"
end

Expand Down
41 changes: 40 additions & 1 deletion spec/search_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,46 @@ module Foo; def self.bar(x, y, z); end; end
_(SDoc::SearchIndex.signature_for(rdoc_method)).must_equal "::bar(x, y, z)"
end

it "uses '(...)' to represent params for :call-seq: methods" do
it "extracts params for basic :call-seq: methods" do
rdoc_module = rdoc_top_level_for(<<~RUBY).find_module_named("Foo")
module Foo
# :method: bar
# :call-seq:
# bar(x, y, z)
#
# Returns result.
# :method: bar!
# :call-seq:
# bar!(x, y, z) -> result
# :method: qux
# :call-seq:
# qux
# :method: qux?
# :call-seq:
# qux? -> result
# :method: fuga
# :call-seq:
# fuga(x = ' -> ') -> result
# :method: hoge
# :call-seq:
# hoge() -> (result)
end
RUBY

_(SDoc::SearchIndex.signature_for(rdoc_module.find_method("bar", false))).must_equal "#bar(x, y, z)"
_(SDoc::SearchIndex.signature_for(rdoc_module.find_method("bar!", false))).must_equal "#bar!(x, y, z)"
_(SDoc::SearchIndex.signature_for(rdoc_module.find_method("qux", false))).must_equal "#qux()"
_(SDoc::SearchIndex.signature_for(rdoc_module.find_method("qux?", false))).must_equal "#qux?()"
_(SDoc::SearchIndex.signature_for(rdoc_module.find_method("fuga", false))).must_equal "#fuga(x = ' -> ')"
_(SDoc::SearchIndex.signature_for(rdoc_module.find_method("hoge", false))).must_equal "#hoge()"
end

it "uses '(...)' to represent params for overloaded :call-seq: methods" do
rdoc_method = rdoc_top_level_for(<<~RUBY).find_module_named("Foo").find_method("bar", false)
module Foo
# :method: bar
Expand Down

0 comments on commit 08b4252

Please sign in to comment.