diff --git a/src/core/inheritDoc.ml b/src/core/inheritDoc.ml index 3c96ae0f619..fe4052f6b86 100644 --- a/src/core/inheritDoc.ml +++ b/src/core/inheritDoc.ml @@ -118,17 +118,28 @@ and build_class_field_doc ctx c_opt cf = ); let doc = ref cf.cf_doc in let no_args_cb add = + let rec find_in_parents classes = + match classes with + | [] -> () + | cl :: rest -> + try + let parent_cl, parent_cf = + if cf.cf_name = "new" then get_constructor cl + else get_class_field cl cf.cf_name + in + build_class_field_doc ctx parent_cl parent_cf; + add parent_cf.cf_doc; + if Option.is_none parent_cf.cf_doc then raise Not_found + with Not_found -> find_in_parents rest + in match c_opt with - | Some { cl_super = Some (csup,_) } -> - (try - let c_opt, cf_sup = - if cf.cf_name = "new" then get_constructor csup - else get_class_field csup cf.cf_name - in - build_class_field_doc ctx c_opt cf_sup; - add cf_sup.cf_doc - with Not_found -> ()) - | _ -> () + | Some c -> + let interfaces = List.rev (List.map (fun (cl, _) -> cl) c.cl_implements) in + begin match c.cl_super with + | Some (csup, _) -> find_in_parents (csup :: interfaces) + | None -> find_in_parents interfaces + end + | None -> () in build_doc ctx ~no_args_cb doc cf.cf_meta; cf.cf_doc <- !doc diff --git a/tests/server/src/cases/display/InheritDoc.hx b/tests/server/src/cases/display/InheritDoc.hx index e74c409e68c..8cd859ccc21 100644 --- a/tests/server/src/cases/display/InheritDoc.hx +++ b/tests/server/src/cases/display/InheritDoc.hx @@ -9,6 +9,15 @@ class InheritDoc extends DisplayTestCase { var c = new Chi{-1-}ld(); c.te{-2-}st(); Child.tes{-3-}t2(); + + final foo = new Foo(); + foo.te{-4-}st(); + final foo2 = new Foo2(); + foo2.te{-5-}st(); + final foo3 = new Foo3(); + foo3.te{-6-}st(); + final foo3inv = new Foo3Inv(); + foo3inv.te{-7-}st(); } } **/ @@ -35,5 +44,33 @@ class InheritDoc extends DisplayTestCase { }); var result = parseHover(); Assert.equals(' Child field 2 doc \n unrelated field doc ', result.result.item.args.field.doc); + + runHaxeJson([], DisplayMethods.Hover, { + file: file, + offset: offset(4) + }); + var result = parseHover(); + Assert.equals(' Foo doc \n GrandParent field doc ', result.result.item.args.field.doc); + + runHaxeJson([], DisplayMethods.Hover, { + file: file, + offset: offset(5) + }); + var result = parseHover(); + Assert.equals(' Foo doc \n IFoo doc ', result.result.item.args.field.doc); + + runHaxeJson([], DisplayMethods.Hover, { + file: file, + offset: offset(6) + }); + var result = parseHover(); + Assert.equals(' IFoo doc ', result.result.item.args.field.doc); + + runHaxeJson([], DisplayMethods.Hover, { + file: file, + offset: offset(7) + }); + var result = parseHover(); + Assert.equals(' IFoo doc ', result.result.item.args.field.doc); } -} \ No newline at end of file +} diff --git a/tests/server/test/templates/InheritDocTypes.hx b/tests/server/test/templates/InheritDocTypes.hx index 2047dceab12..36f88978cfc 100644 --- a/tests/server/test/templates/InheritDocTypes.hx +++ b/tests/server/test/templates/InheritDocTypes.hx @@ -16,6 +16,7 @@ class Parent extends GrandParent { class Child extends Parent { /** Child field doc **/ @:inheritDoc override public function test() {} + /** Child field 2 doc **/ @:inheritDoc(InheritDocTypes.Unrelated.unrelated) static public function test2() {} @@ -25,4 +26,42 @@ class Child extends Parent { class Unrelated { /** unrelated field doc */ static public function unrelated() {} -} \ No newline at end of file +} + +class Foo implements IFoo implements IFoo2 extends Parent { + /** Foo doc **/ + @:inheritDoc override public function test():Void {} +} + +class Foo2 implements IFoo implements IFoo2 { + public function new() {} + + /** Foo doc **/ + @:inheritDoc public function test():Void {} +} + +class Foo3 implements IFoo implements IEmptyFoo { + public function new() {} + + @:inheritDoc public function test():Void {} +} + +class Foo3Inv implements IEmptyFoo implements IFoo { + public function new() {} + + @:inheritDoc public function test():Void {} +} + +interface IEmptyFoo { + function test():Void; +} + +interface IFoo { + /** IFoo doc **/ + function test():Void; +} + +interface IFoo2 { + /** IFoo2 doc **/ + function test():Void; +}