Skip to content

Allow @:inheritDoc var field to search for documentation in implemented interfaces #12270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/core/inheritDoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 38 additions & 1 deletion tests/server/src/cases/display/InheritDoc.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
**/
Expand All @@ -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);
}
}
}
41 changes: 40 additions & 1 deletion tests/server/test/templates/InheritDocTypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand All @@ -25,4 +26,42 @@ class Child extends Parent {
class Unrelated {
/** unrelated field doc */
static public function unrelated() {}
}
}

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;
}
Loading