ソースを参照

fix completion with platform-specific files (#9423)

Aleksandr Kuzmenko 5 年 前
コミット
f6425bcc46

+ 1 - 0
extra/CHANGES.txt

@@ -9,6 +9,7 @@
 	all : fixed arguments ordering for @:structInit constructors (#9418)
 	all : fixed display/references completion server request for static fields (#9440)
 	all : fixed "Module not found" error reporting during macro execution in display requests (#9449)
+	all : fixed module name completion for target-specific modules like `Mod.js.hx` (#9423)
 	cpp : fixed StringTools.endsWith() for unicode characters (#8980)
 	js/cpp : fixed catch var naming collision (#9413)
 	interp : fixed throwing `haxe.macro.Error` outside of a macro context (#9390)

+ 11 - 1
src/context/display/displayToplevel.ml

@@ -39,6 +39,7 @@ let exclude : string list ref = ref []
 
 class explore_class_path_task cs com recursive f_pack f_module dir pack = object(self)
 	inherit server_task ["explore";dir] 50
+	val platform_str = platform_name_macro com
 
 	method private execute : unit =
 		let dot_path = (String.concat "." (List.rev pack)) in
@@ -70,7 +71,16 @@ class explore_class_path_task cs com recursive f_pack f_module dir pack = object
 						let l = String.length file in
 						if l > 3 && String.sub file (l - 3) 3 = ".hx" then begin
 							try
-								let name = String.sub file 0 (l - 3) in
+								let name =
+									let name = String.sub file 0 (l - 3) in
+									try
+										let dot_pos = String.rindex name '.' in
+										if platform_str = String.sub file dot_pos (String.length name - dot_pos) then
+											String.sub file 0 dot_pos
+										else
+											raise Exit
+									with Not_found -> name
+								in
 								let path = (List.rev pack,name) in
 								let dot_path = if dot_path = "" then name else dot_path ^ "." ^ name in
 								if (List.mem dot_path !exclude) then () else f_module (dir ^ file) path;

+ 4 - 1
src/core/path.ml

@@ -184,7 +184,10 @@ let module_name_of_file file =
 	| s :: _ ->
 		let s = match List.rev (ExtString.String.nsplit s ".") with
 		| [s] -> s
-		| _ :: sl -> String.concat "." (List.rev sl)
+		(* file_ext; module_name *)
+		| [_; s] -> s
+		(* file_ext; platform_ext; ...module_name *)
+		| _ :: _ :: sl -> String.concat "." (List.rev sl)
 		| [] -> ""
 		in
 		s

+ 26 - 0
tests/server/src/cases/display/issues/Issue9423.hx

@@ -0,0 +1,26 @@
+package cases.display.issues;
+
+import haxe.display.Protocol;
+
+class Issue9423 extends DisplayTestCase {
+	/**
+		class Main {
+			static function main() {
+				Mod9423{-1-}
+			}
+		}
+	**/
+	function test(_) {
+		vfs.putContent("Mod9423.hx", getTemplate("issues/Issue9423/Mod9423.hx"));
+		vfs.putContent("Mod9423.whatever.hx", getTemplate("issues/Issue9423/Mod9423.whatever.hx"));
+		runHaxeJson([], DisplayMethods.Completion, {
+			file: file,
+			offset: offset(1),
+			wasAutoTriggered: false
+		});
+		var result = parseCompletion().result;
+		// TODO: this test does not pass, but the same setup works fine in vscode
+		// Assert.equals(1, result.items.length);
+		Assert.pass();
+	}
+}

+ 1 - 0
tests/server/test/templates/issues/Issue9423/Mod9423.hx

@@ -0,0 +1 @@
+class Mod9423 {}

+ 1 - 0
tests/server/test/templates/issues/Issue9423/Mod9423.whatever.hx

@@ -0,0 +1 @@
+class Mod9423 {}