Browse Source

[display] check invalid dependencies for texpr-based display

closes #8991
Simon Krajewski 5 years ago
parent
commit
2fe5916068
2 changed files with 27 additions and 2 deletions
  1. 6 2
      src/context/display/displayTexpr.ml
  2. 21 0
      tests/server/src/DisplayTests.hx

+ 6 - 2
src/context/display/displayTexpr.ml

@@ -143,8 +143,12 @@ let check_display_file ctx cs =
 			let p = DisplayPosition.display_position#get in
 			let cfile = cc#find_file (Path.unique_full_path p.pfile) in
 			let path = (cfile.c_package,get_module_name_of_cfile p.pfile cfile) in
-			let m = cc#find_module path in
-			check_display_module ctx cc cfile m
+			(* We have to go through type_module_hook because one of the module's dependencies could be
+			   invalid (issue #8991). *)
+			begin match !TypeloadModule.type_module_hook ctx path null_pos with
+			| None -> raise Not_found
+			| Some m -> check_display_module ctx cc cfile m
+			end
 		with Not_found ->
 			(* Special case for diagnostics: It's not treated as a display mode, but we still want to invalidate the
 				current file in order to run diagnostics on it again. *)

+ 21 - 0
tests/server/src/DisplayTests.hx

@@ -259,4 +259,25 @@ typedef Foo = {
 		var result = parseHover().result;
 		Assert.isNull(result);
 	}
+
+	function testIssue8991() {
+		var mainHx = 'class Main {
+	static function main() {
+		C.inst{-1-}ance;
+	}
+}';
+		var cHx = 'class C {
+	public static var instance:Int;
+}';
+		var mainHx = Marker.extractMarkers(mainHx);
+		vfs.putContent("Main.hx", mainHx.source);
+		vfs.putContent("C.hx", cHx);
+
+		runHaxe(["--no-output", "-main", "Main"]);
+		runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("C.hx")});
+		runHaxeJson([], DisplayMethods.Hover, {file: new FsPath("Main.hx"), offset: mainHx.markers[1]});
+
+		var result = parseHover().result;
+		Assert.equals(DisplayItemKind.ClassField, result.item.kind);
+	}
 }