Browse Source

[display] add isOutermostPattern to CRPattern (#7323)

* [display] add isOutermostPattern to CRPattern

closes #7287

* fix encoding
Jens Fischer 7 năm trước cách đây
mục cha
commit
53921a0804

+ 1 - 1
src/compiler/main.ml

@@ -1000,7 +1000,7 @@ with
 			| CRImport
 			| CRUsing
 			| CRNew
-			| CRPattern
+			| CRPattern _
 			| CRTypeRelation ->
 				DisplayOutput.print_toplevel fields
 			| CRField _

+ 2 - 2
src/core/ast.ml

@@ -180,7 +180,7 @@ and display_kind =
 	| DKDot
 	| DKStructure
 	| DKMarked
-	| DKPattern
+	| DKPattern of bool
 
 and expr_def =
 	| EConst of constant
@@ -718,7 +718,7 @@ let s_display_kind = function
 	| DKDot -> "DKDot"
 	| DKStructure -> "DKStructure"
 	| DKMarked -> "DKMarked"
-	| DKPattern -> "DKPattern"
+	| DKPattern _ -> "DKPattern"
 
 let s_expr e =
 	let rec s_expr_inner tabs (e,_) =

+ 4 - 2
src/core/displayTypes.ml

@@ -76,7 +76,7 @@ module CompletionResultKind = struct
 		| CRImport
 		| CRUsing
 		| CRNew
-		| CRPattern
+		| CRPattern of bool
 		| CROverride
 		| CRTypeRelation
 
@@ -124,7 +124,9 @@ module CompletionResultKind = struct
 			| CRImport -> 8,None
 			| CRUsing -> 9,None
 			| CRNew -> 10,None
-			| CRPattern -> 11,None
+			| CRPattern isOutermostPattern -> 11,Some (jobject [
+					"isOutermostPattern",jbool isOutermostPattern
+				])
 			| CROverride -> 12,None
 			| CRTypeRelation -> 13,None
 		in

+ 13 - 13
src/macro/macroApi.ml

@@ -475,14 +475,14 @@ and encode_fun f =
 	]
 
 and encode_display_kind dk =
-	let tag = match dk with
-	| DKCall -> 0
-	| DKDot -> 1
-	| DKStructure -> 2
-	| DKMarked -> 3
-	| DKPattern -> 4
+	let tag, pl = match dk with
+	| DKCall -> 0, []
+	| DKDot -> 1, []
+	| DKStructure -> 2, []
+	| DKMarked -> 3, []
+	| DKPattern outermost -> 4, [vbool outermost]
 	in
-	encode_enum ~pos:None ICType tag []
+	encode_enum ~pos:None ICType tag pl
 
 and encode_expr e =
 	let rec loop (e,p) =
@@ -770,12 +770,12 @@ and decode_ctype t =
 	| _ ->
 		raise Invalid_expr),p
 
-and decode_display_kind v = match fst (decode_enum v) with
-	| 0 -> DKCall
-	| 1 -> DKDot
-	| 2 -> DKStructure
-	| 3 -> DKMarked
-	| 4 -> DKPattern
+and decode_display_kind v = match (decode_enum v) with
+	| 0, [] -> DKCall
+	| 1, [] -> DKDot
+	| 2, [] -> DKStructure
+	| 3, [] -> DKMarked
+	| 4, [outermost] -> DKPattern (decode_bool outermost)
 	| _ -> raise Invalid_expr
 
 and decode_expr v =

+ 2 - 2
src/typing/matcher.ml

@@ -471,12 +471,12 @@ module Pattern = struct
 				let pat = loop e in
 				let locals' = ctx.locals in
 				ctx.locals <- locals;
-				ignore(TyperDisplay.handle_edisplay ctx e (if toplevel then DKPattern else dk) (WithType t));
+				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType t));
 				ctx.locals <- locals';
 				pat
 			| EDisplay(e,dk) ->
 				let pat = loop e in
-				ignore(TyperDisplay.handle_edisplay ctx e (if toplevel then DKPattern else dk) (WithType t));
+				ignore(TyperDisplay.handle_edisplay ctx e (DKPattern toplevel) (WithType t));
 				pat
 			| _ ->
 				fail()

+ 3 - 3
src/typing/typerDisplay.ml

@@ -134,7 +134,7 @@ let raise_toplevel ctx dk with_type po p =
 		| None -> None
 		| Some t -> Some (completion_type_of_type ctx t,completion_type_of_type ctx (follow t))
 	in
-	raise_fields (DisplayToplevel.collect ctx (match dk with DKPattern -> TKPattern p | _ -> TKExpr p) with_type) (CRToplevel ct) po
+	raise_fields (DisplayToplevel.collect ctx (match dk with DKPattern _ -> TKPattern p | _ -> TKExpr p) with_type) (CRToplevel ct) po
 
 let rec handle_signature_display ctx e_ast with_type =
 	ctx.in_display <- true;
@@ -475,10 +475,10 @@ let handle_edisplay ctx e dk with_type =
 			| _ ->
 				handle_display ctx e dk with_type
 		end
-	| DKPattern,DMDefault ->
+	| DKPattern outermost,DMDefault ->
 		begin try
 			handle_display ctx e dk with_type
 		with DisplayException(DisplayFields(l,CRToplevel _,p)) ->
-			raise_fields l CRPattern p
+			raise_fields l (CRPattern outermost) p
 		end
 	| _ -> handle_display ctx e dk with_type

+ 1 - 1
std/haxe/macro/Expr.hx

@@ -537,7 +537,7 @@ enum DisplayKind {
 	DKDot;
 	DKStructure;
 	DKMarked;
-	DKPattern;
+	DKPattern( outermost : Bool );
 }
 
 /**