diff --git a/lib/yard/docstring.rb b/lib/yard/docstring.rb index e02524a6d..7d48001d0 100644 --- a/lib/yard/docstring.rb +++ b/lib/yard/docstring.rb @@ -46,6 +46,9 @@ def parser(*args) default_parser.new(*args) end # @return [CodeObjects::Base] the object that owns the docstring. attr_accessor :object + # @return [CodeObjects::Base] the namespace of the docstring + attr_reader :namespace + # @return [Range] line range in the {#object}'s file where the docstring was parsed from attr_accessor :line_range @@ -79,6 +82,7 @@ def self.new!(text, tags = [], object = nil, raw_data = nil, ref_object = nil) docstring.replace(text, false) docstring.object = object docstring.add_tag(*tags) + docstring.instance_variable_set("@namespace", object) docstring.instance_variable_set("@unresolved_reference", ref_object) docstring.instance_variable_set("@all", raw_data) if raw_data docstring @@ -102,6 +106,7 @@ def self.new!(text, tags = [], object = nil, raw_data = nil, ref_object = nil) # with. def initialize(content = '', object = nil) @object = object + @namespace = object @summary = nil @hash_flag = false @@ -330,9 +335,9 @@ def resolve_reference return if defined?(@unresolved_reference).nil? || @unresolved_reference.nil? return if CodeObjects::Proxy === @unresolved_reference - reference = @unresolved_reference + @namespace = @unresolved_reference @unresolved_reference = nil - self.all = [reference.docstring.all, @all].join("\n") + self.all = [@namespace.docstring.all, @all].join("\n") end end diff --git a/lib/yard/docstring_parser.rb b/lib/yard/docstring_parser.rb index 40b9cb5ae..7984c462c 100644 --- a/lib/yard/docstring_parser.rb +++ b/lib/yard/docstring_parser.rb @@ -224,7 +224,8 @@ def create_tag(tag_name, tag_buf = '') # Creates a {Tags::RefTag} def create_ref_tag(tag_name, name, object_name) - @tags << Tags::RefTagList.new(tag_name, P(object, object_name), name) + namespace = object && object.docstring ? object.docstring.namespace : object + @tags << Tags::RefTagList.new(tag_name, P(namespace, object_name), name) end # Creates a new directive using the registered {#library} diff --git a/spec/docstring_spec.rb b/spec/docstring_spec.rb index 999afd414..5ffa7229e 100644 --- a/spec/docstring_spec.rb +++ b/spec/docstring_spec.rb @@ -182,6 +182,25 @@ expect(tags.first.owner).to eq o end + it "uses the right namespace following ref tags through a docstring reference" do + YARD.parse_string <<-eof + class A + class B + # @param x + def b(x); end + end + # @param x (see B#b) + def a(x);end + end + class C + # (see A#a) + def c(x);end + end + eof + + expect(YARD::Registry.at('C#c').tags.map(&:name)).to eq ['x'] + end + it "returns an empty list (and warning) if circular reftags are found" do YARD.parse_string <<-eof class Foo