Browse Source

make auto-generated @:structInit ctors inherit docs of parent ctors (closes #9956)

Aleksandr Kuzmenko 4 years ago
parent
commit
40e24dbbea

+ 3 - 2
src/typing/typeloadFields.ml

@@ -228,9 +228,10 @@ let ensure_struct_init_constructor ctx c ast_fields p =
 		cf.cf_doc <- doc_from_string (Buffer.contents doc_buf);
 		cf.cf_doc <- doc_from_string (Buffer.contents doc_buf);
 		cf.cf_expr <- Some e;
 		cf.cf_expr <- Some e;
 		cf.cf_type <- e.etype;
 		cf.cf_type <- e.etype;
-		cf.cf_meta <- [Meta.CompilerGenerated,[],null_pos];
+		cf.cf_meta <- [Meta.CompilerGenerated,[],null_pos; Meta.InheritDoc,[],null_pos];
 		cf.cf_kind <- Method MethNormal;
 		cf.cf_kind <- Method MethNormal;
-		c.cl_constructor <- Some cf
+		c.cl_constructor <- Some cf;
+		delay ctx PTypeField (fun() -> InheritDoc.build_class_field_doc ctx (Some c) cf)
 
 
 let transform_abstract_field com this_t a_t a f =
 let transform_abstract_field com this_t a_t a f =
 	let stat = List.mem_assoc AStatic f.cff_access in
 	let stat = List.mem_assoc AStatic f.cff_access in

+ 16 - 0
tests/server/src/TestCase.hx

@@ -1,3 +1,4 @@
+import haxe.PosInfos;
 import haxe.Exception;
 import haxe.Exception;
 import haxe.display.Position;
 import haxe.display.Position;
 import haxeserver.HaxeServerRequestResult;
 import haxeserver.HaxeServerRequestResult;
@@ -195,6 +196,21 @@ class TestCase implements ITest {
 		}
 		}
 	}
 	}
 
 
+	function assertClassField(completion:CompletionResult, name:String, ?callback:(field:JsonClassField)->Void, ?pos:PosInfos) {
+		for (item in completion.result.items) {
+			switch item.kind {
+				case ClassField if(item.args.field.name == name):
+					switch callback {
+						case null: Assert.pass(pos);
+						case fn: fn(item.args.field);
+					}
+					return;
+				case _:
+			}
+		}
+		Assert.fail(pos);
+	}
+
 	function assertHasCompletion<T>(completion:CompletionResult, f:DisplayItem<T>->Bool, ?p:haxe.PosInfos) {
 	function assertHasCompletion<T>(completion:CompletionResult, f:DisplayItem<T>->Bool, ?p:haxe.PosInfos) {
 		for (type in completion.result.items) {
 		for (type in completion.result.items) {
 			if (f(type)) {
 			if (f(type)) {

+ 28 - 0
tests/server/src/cases/display/issues/Issue9956.hx

@@ -0,0 +1,28 @@
+package cases.display.issues;
+
+class Issue9956 extends DisplayTestCase {
+	/**
+		import Issue9956Types;
+
+		class Main {
+			static function main() {
+				var c:Child = {{-1-}};
+			}
+		}
+	**/
+	function test(_) {
+		vfs.putContent("Issue9956Types.hx", getTemplate("Issue9956Types.hx"));
+		runHaxeJson([], DisplayMethods.Completion, {
+			file: file,
+			offset: offset(1),
+			wasAutoTriggered: false
+		});
+		var result = parseCompletion();
+		assertClassField(result, 'x', field -> {
+			Assert.equals('This is x', field.doc);
+		});
+		assertClassField(result, 'y', field -> {
+			Assert.equals('This is y', field.doc);
+		});
+	}
+}

+ 15 - 0
tests/server/test/templates/Issue9956Types.hx

@@ -0,0 +1,15 @@
+@:structInit
+class Parent {
+	/** This is y **/
+	var y:String;
+}
+
+@:structInit
+class Child extends Parent {
+	/** This is x **/
+	var x:Int;
+}
+
+function main() {
+	var c:Child = {};
+}