Sfoglia il codice sorgente

[display] improve constructor display and regex literal hover

Simon Krajewski 7 anni fa
parent
commit
6314c80a68
2 ha cambiato i file con 27 aggiunte e 3 eliminazioni
  1. 26 2
      src/typing/typerDisplay.ml
  2. 1 1
      tests/display/src/cases/Issue6275.hx

+ 26 - 2
src/typing/typerDisplay.ml

@@ -151,8 +151,32 @@ and display_expr ctx e_ast e dk with_type p =
 			| TCall({eexpr = TConst TSuper; etype = t},_) -> t,None
 			| TNew({cl_kind = KAbstractImpl a},tl,_) -> TType(abstract_module_type a tl,[]),None
 			| TNew(c,tl,_) ->
-				let t,_ = get_constructor ctx c tl p in
-				t,None
+				begin match fst e_ast with
+				| EConst (Regexp (r,opt)) ->
+					let present,absent = List.partition (String.contains opt) ['g';'i';'m';'s';'u'] in
+					let doc flag desc = Printf.sprintf "* %s: %s" (String.make 1 flag) desc in
+					let f c = match c with
+						| 'g' -> doc c "global split and replace"
+						| 'i' -> doc c "case insensitive matching"
+						| 'm' -> doc c "multiline matching"
+						| 's' -> doc c "dot also match newlines"
+						| 'u' -> doc c "use UTF-8 matching"
+						| _ -> assert false
+					in
+					let present = List.map f present in
+					let present = match present with [] -> [] | _ -> "\n\nActive flags:\n\n" :: present in
+					let absent = List.map f absent in
+					let absent = match absent with [] -> [] | _ -> "\n\nInactive flags:\n\n" :: absent in
+					(TInst(c,tl)),Some ("Regular expression\n\n" ^ (String.concat "\n" (present @ absent)))
+				| _ ->
+					let t,cf = get_constructor ctx c tl p in
+					let t = match follow t with
+						| TFun(args,_) -> TFun(args,TInst(c,tl))
+						| _ -> t
+					in
+					if Meta.has Meta.CoreApi c.cl_meta then merge_core_doc ctx c;
+					t,cf.cf_doc
+				end
 			| TTypeExpr (TClassDecl {cl_kind = KAbstractImpl a}) -> TType(abstract_module_type a (List.map snd a.a_params),[]),None
 			| TField(e1,FDynamic "bind") when (match follow e1.etype with TFun _ -> true | _ -> false) -> e1.etype,None
 			| TReturn (Some e1) -> loop e1 (* No point in letting the internal Dynamic surface (issue #5655) *)

+ 1 - 1
tests/display/src/cases/Issue6275.hx

@@ -13,7 +13,7 @@ class Issue6275 extends DisplayTestCase {
 	}
 	**/
 	function test() {
-		eq("s : String -> Void", type(pos(2)));
+		eq("s : String -> cases.Main", type(pos(2)));
 		eq(range(4, 5), position(pos(1)));
 		eq(range(1, 3), usage(pos(2))[0]);
 	}