Browse Source

[display] use null instead of "null" for undefined defines

Jens Fischer 6 years ago
parent
commit
d992066b6f
2 changed files with 11 additions and 8 deletions
  1. 5 2
      src/core/display/completionItem.ml
  2. 6 6
      src/typing/typeloadParse.ml

+ 5 - 2
src/core/display/completionItem.ml

@@ -433,7 +433,7 @@ type t_kind =
 	| ITAnonymous of tanon
 	| ITExpression of texpr
 	| ITTypeParameter of tclass
-	| ITDefine of string * string
+	| ITDefine of string * string option
 
 type t = {
 	ci_kind : t_kind;
@@ -710,7 +710,10 @@ let to_json ctx index item =
 			end
 		| ITDefine(n,v) -> "Define",jobject [
 			"name",jstring n;
-			"value",jstring v;
+			"value",(match v with
+				| None -> jnull
+				| Some v -> jstring v
+			);
 			(* TODO: docs etc *)
 		]
 	in

+ 6 - 6
src/typing/typeloadParse.ml

@@ -161,11 +161,11 @@ module ConditionDisplay = struct
 	}
 
 	let convert_small_type com = function
-		| TNull -> "null",(Type.mk_mono(),CTMono)
-		| TBool b -> string_of_bool b,(com.basic.tbool,ct "Bool")
-		| TFloat f -> string_of_float f,(com.basic.tfloat,ct "Float")
-		| TString s -> "\"" ^ StringHelper.s_escape s ^ "\"",(com.basic.tstring,ct "String")
-		| TVersion(r,p) -> Semver.to_string (r,p),(com.basic.tstring,ct "String")
+		| TNull -> None,(Type.mk_mono(),CTMono)
+		| TBool b -> Some (string_of_bool b),(com.basic.tbool,ct "Bool")
+		| TFloat f -> Some (string_of_float f),(com.basic.tfloat,ct "Float")
+		| TString s -> Some ("\"" ^ StringHelper.s_escape s ^ "\""),(com.basic.tstring,ct "String")
+		| TVersion(r,p) -> Some (Semver.to_string (r,p)),(com.basic.tstring,ct "String")
 
 	let check_condition com e =
 		let rec loop (e,p) =
@@ -179,7 +179,7 @@ module ConditionDisplay = struct
 			let s,(t,ct) = convert_small_type com v in
 			DisplayException.raise_hover (match e with
 				| EConst(Ident(n)) -> CompletionItem.make_ci_define n s (t,ct)
-				| _ -> CompletionItem.make_ci_literal s (t,ct)
+				| _ -> CompletionItem.make_ci_literal (match s with | Some s -> s | None -> "null") (t,ct)
 			) None p;
 end