From d034793bd327d78aba0d99d719336d597e2413b0 Mon Sep 17 00:00:00 2001 From: Seba Gamboa Date: Tue, 29 Sep 2015 11:51:21 -0300 Subject: Handle return types --- .../mruby/handlers/c/header/function_handler.rb | 15 +++++++++++++-- lib/yard/mruby/templates/helpers/html_helper.rb | 6 ++++-- spec/handlers/c/header/function_handler_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/yard/mruby/handlers/c/header/function_handler.rb b/lib/yard/mruby/handlers/c/header/function_handler.rb index 6bdb8a6..11f8efc 100644 --- a/lib/yard/mruby/handlers/c/header/function_handler.rb +++ b/lib/yard/mruby/handlers/c/header/function_handler.rb @@ -1,8 +1,11 @@ module YARD::MRuby::Handlers::C::Header class FunctionHandler < Base MATCH = / - MRB_(API|INLINE)\s+((\w+\s+)+)(\w+)\s*\( + MRB_(API|INLINE)\s+ + ((struct\s+)?\w+(\s*\*)?)\s* + ((\w+\s+)+)?(\w+)\s*\( /mx + #\(([\w\*,]*)\) handles MATCH statement_class ToplevelStatement @@ -14,11 +17,19 @@ module YARD::MRuby::Handlers::C::Header def handle_function(statement) header = self.header(statement.file) - statement.source.scan(MATCH) do |type, prefix, _, name, *args| +["API", "mrb_value", nil, nil, nil, nil, "sample_api_method"] + statement.source.scan(MATCH) do |type, retype, _,_,_,_, name, *args| + puts args.inspect register FunctionObject.new(header, name) do |obj| if statement.comments register_docstring(obj, statement.comments.source, statement) end + + if retype != 'void' + obj.add_tag(YARD::Tags::Tag.new(:return,"", "")) unless obj.has_tag?(:return) + obj.tag(:return).types = [retype] + end + end end end diff --git a/lib/yard/mruby/templates/helpers/html_helper.rb b/lib/yard/mruby/templates/helpers/html_helper.rb index 46b8664..7d1e159 100644 --- a/lib/yard/mruby/templates/helpers/html_helper.rb +++ b/lib/yard/mruby/templates/helpers/html_helper.rb @@ -5,11 +5,13 @@ module YARD::MRuby::Templates def fsignature(func, link = true, show_extras = true) name = func.name - title = "%s" % [h(name)] + prefix = 'void' + params = 'void' + title = "%s %s( %s )" % [h(prefix), h(name), h(params)] if link url = url_for(func) - link_url(url, title, :title => title) + link_url(url, title, :title => name) else title end diff --git a/spec/handlers/c/header/function_handler_spec.rb b/spec/handlers/c/header/function_handler_spec.rb index dc42c91..ff1d2a8 100644 --- a/spec/handlers/c/header/function_handler_spec.rb +++ b/spec/handlers/c/header/function_handler_spec.rb @@ -17,4 +17,26 @@ describe YARD::MRuby::Handlers::C::Header::FunctionHandler do foo = Registry.at('mrb_foo') expect(foo.docstring).to eq 'DOCSTRING' end + + it "should store the return type" do + header_line <<-eof + MRB_API mrb_value mrb_foo( void ); + eof + + foo = Registry.at('mrb_foo') + expect(foo.tag(:return).types).to eq ['mrb_value'] + end + + it "should keep return type independently from docs" do + header_line <<-eof + /** + * @return DOCSTRING + */ + MRB_API mrb_value mrb_foo( void ); + eof + + foo = Registry.at('mrb_foo') + expect(foo.tag(:return).text).to eq 'DOCSTRING' + expect(foo.tag(:return).types).to eq ['mrb_value'] + end end -- cgit v1.2.3