Browse Source

add `@package` display mode (#5488)

It returns calculated package for a given display file, based on class paths configuration
Dan Korostelev 9 years ago
parent
commit
f4c6aeb5d5

+ 1 - 0
src/display/display.ml

@@ -18,6 +18,7 @@ exception DisplayPosition of Ast.pos list
 exception DisplaySubExpression of Ast.expr
 exception DisplayFields of (string * t * display_field_kind option * documentation) list
 exception DisplayToplevel of IdentifierType.t list
+exception DisplayPackage of string list
 
 let is_display_file file =
 	file <> "?" && Common.unique_full_path file = (!Parser.resume_display).pfile

+ 5 - 0
src/main.ml

@@ -1290,6 +1290,8 @@ try
 					| "usage" ->
 						Common.define com Define.NoCOpt;
 						DMUsage
+					| "package" ->
+						DMPackage
 					| "type" ->
 						Common.define com Define.NoCOpt;
 						DMType
@@ -1475,6 +1477,7 @@ try
 		let real = get_real_path (!Parser.resume_display).Ast.pfile in
 		(match get_module_path_from_file_path com real with
 		| Some path ->
+			if com.display = DMPackage then raise (Display.DisplayPackage (fst path));
 			classes := path :: !classes
 		| None ->
 			if not (Sys.file_exists real) then failwith "Display file does not exist";
@@ -1724,6 +1727,8 @@ with
 		error ctx ("Error: " ^ msg) Ast.null_pos
 	| Arg.Help msg ->
 		message ctx msg Ast.null_pos
+	| Display.DisplayPackage pack ->
+		raise (Completion (String.concat "." pack))
 	| Display.DisplayFields fields ->
 		let ctx = print_context() in
 		let fields = List.map (fun (name,t,kind,doc) -> name, s_type ctx t, kind, (match doc with None -> "" | Some d -> d)) fields in

+ 1 - 0
src/typing/common.ml

@@ -97,6 +97,7 @@ type display_mode =
 	| DMPosition
 	| DMToplevel
 	| DMResolve of string
+	| DMPackage
 	| DMType
 	| DMModuleSymbols
 	| DMDiagnostics

+ 1 - 1
src/typing/typer.ml

@@ -3860,7 +3860,7 @@ and handle_display ctx e_ast iscall with_type =
 			f
 	in
 	match ctx.com.display with
-	| DMResolve _ ->
+	| DMResolve _ | DMPackage ->
 		assert false
 	| DMType ->
 		let t = match e.eexpr with

+ 2 - 0
tests/misc/projects/display-package/compile1.hxml

@@ -0,0 +1,2 @@
+-cp src
+--display src/C1.hx@0@package

+ 0 - 0
tests/misc/projects/display-package/compile1.hxml.stderr


+ 2 - 0
tests/misc/projects/display-package/compile2.hxml

@@ -0,0 +1,2 @@
+-cp src
+--display src/pack/C2.hx@0@package

+ 1 - 0
tests/misc/projects/display-package/compile2.hxml.stderr

@@ -0,0 +1 @@
+pack

+ 1 - 0
tests/misc/projects/display-package/compile3.hxml

@@ -0,0 +1 @@
+--display src/pack/C2.hx@0@package

+ 1 - 0
tests/misc/projects/display-package/compile3.hxml.stderr

@@ -0,0 +1 @@
+src.pack

+ 0 - 0
tests/misc/projects/display-package/src/C1.hx


+ 0 - 0
tests/misc/projects/display-package/src/pack/C2.hx