Browse Source

track fields that block others in completion

closes #12254
Simon Krajewski 3 months ago
parent
commit
f72f084f78

+ 20 - 3
src/context/display/displayFields.ml

@@ -35,7 +35,7 @@ let get_submodule_fields ctx path =
 	) tl in
 	tl
 
-let collect_static_extensions ctx items e p =
+let collect_static_extensions ctx blocked_items items e p =
 	let opt_type t =
 		match t with
 		| TLazy f ->
@@ -81,7 +81,13 @@ let collect_static_extensions ctx items e p =
 			end
 		| _ ->
 			acc
-		in
+	in
+	let handle_field c cf acc =
+		if Hashtbl.mem blocked_items cf.cf_name then
+			acc
+		else
+			handle_field c cf acc
+	in
 	let rec loop acc = function
 		| [] ->
 			acc
@@ -142,6 +148,17 @@ let collect ctx e_ast e dk with_type p =
 		let ct = CompletionType.from_type (get_import_status ctx) ~values:(get_value_meta cf.cf_meta) cf.cf_type in
 		make_ci_class_field (CompletionClassField.make cf CFSMember origin true) (cf.cf_type,ct)
 	in
+	let blocked_items = Hashtbl.create 0 in
+	let should_access c cf stat =
+		if Hashtbl.mem blocked_items cf.cf_name then
+			false
+		else if should_access c cf stat then
+			true
+		else begin
+			Hashtbl.add blocked_items cf.cf_name ();
+			false
+		end
+	in
 	let rec loop items t =
 		let is_new_item items name = not (PMap.mem name items) in
 		let rec browse_interfaces c acc =
@@ -345,7 +362,7 @@ let collect ctx e_ast e dk with_type p =
 	(* Collect fields of the type *)
 	let items = loop items e.etype in
 	(* Add static extensions *)
-	let items = collect_static_extensions ctx items e p in
+	let items = collect_static_extensions ctx blocked_items items e p in
 	let items = PMap.fold (fun item acc -> item :: acc) items [] in
 	let items = sort_fields items WithType.value (TKField p) in
 	try

+ 2 - 0
tests/display/build-rpc.hxml

@@ -0,0 +1,2 @@
+build.hxml
+-D display.protocol=jsonrpc

+ 25 - 0
tests/display/src/cases/Issue12254.hx

@@ -0,0 +1,25 @@
+package cases;
+
+class Issue12254 extends DisplayTestCase {
+	/**
+		using Issue12254.Tools;
+
+		class C {
+			public function new() {}
+			@:noCompletion public function f() {}
+		}
+
+		class Tools {
+			static public function f(c:C, s:String) {}
+		}
+
+		function main() {
+			var c = new C();
+			c.{-1-}
+		}
+	**/
+	function test() {
+		final fields = fields(pos(1));
+		eq(0, fields.length);
+	}
+}