Browse Source

[display] always consider `macro` and `display` blocks to be reachable

Simon Krajewski 6 years ago
parent
commit
bf1491bfb1
3 changed files with 35 additions and 28 deletions
  1. 2 3
      src/context/common.ml
  2. 1 1
      src/context/display/diagnostics.ml
  3. 32 24
      src/typing/typeloadParse.ml

+ 2 - 3
src/context/common.ml

@@ -154,12 +154,12 @@ end
 type shared_display_information = {
 	mutable import_positions : (pos,bool ref * placed_name list) PMap.t;
 	mutable diagnostics_messages : (string * pos * DisplayTypes.DiagnosticsKind.t * DisplayTypes.DiagnosticsSeverity.t) list;
+	mutable dead_blocks : (string,(pos * expr) list) Hashtbl.t;
 }
 
 type display_information = {
 	mutable unresolved_identifiers : (string * pos * (string * CompletionItem.t * int) list) list;
 	mutable interface_field_implementations : (tclass * tclass_field * tclass * tclass_field option) list;
-	mutable dead_blocks : (string,(pos * expr) list) Hashtbl.t;
 }
 
 (* This information is shared between normal and macro context. *)
@@ -421,12 +421,12 @@ let create version s_version args =
 			shared_display_information = {
 				import_positions = PMap.empty;
 				diagnostics_messages = [];
+				dead_blocks = Hashtbl.create 0;
 			}
 		};
 		display_information = {
 			unresolved_identifiers = [];
 			interface_field_implementations = [];
-			dead_blocks = Hashtbl.create 0;
 		};
 		sys_args = args;
 		debug = false;
@@ -504,7 +504,6 @@ let clone com =
 		display_information = {
 			unresolved_identifiers = [];
 			interface_field_implementations = [];
-			dead_blocks = Hashtbl.create 0;
 		};
 		defines = {
 			values = com.defines.values;

+ 1 - 1
src/context/display/diagnostics.ml

@@ -202,7 +202,7 @@ module Printer = struct
 				] in
 				add DKInactiveBlock p DiagnosticsSeverity.Hint jo
 			) ranges
-		) com.display_information.dead_blocks;
+		) com.shared.shared_display_information.dead_blocks;
 		let jl = Hashtbl.fold (fun file diag acc ->
 			let jl = Hashtbl.fold (fun _ (dk,p,sev,jargs) acc ->
 				(JObject [

+ 32 - 24
src/typing/typeloadParse.ml

@@ -189,6 +189,37 @@ module ConditionDisplay = struct
 			) None p;
 end
 
+module PdiHandler = struct
+	open Parser
+
+	let is_true defines e =
+		ParserEntry.is_true (ParserEntry.eval defines e)
+
+	let handle_pdi com file pdi =
+		let macro_defines = adapt_defines_to_macro_context com.defines in
+		List.iter (fun (p,e) ->
+			if DisplayPosition.display_position#enclosed_in p then begin
+				if is_true macro_defines e then
+					raise DisplayInMacroBlock;
+				begin match com.display.dms_kind with
+				| DMHover ->
+					raise (DisplayException.DisplayException(DisplayHover None))
+				| _ ->
+					()
+				end;
+			end;
+		) pdi.pd_dead_blocks;
+		begin match com.display.dms_kind with
+		| DMHover ->
+			List.iter (ConditionDisplay.check_condition com) pdi.pd_conditions;
+		| _ ->
+			()
+		end;
+		let display_defines = {macro_defines with values = PMap.add "display" "1" macro_defines.values} in
+		let dead_blocks = List.filter (fun (_,e) -> not (is_true display_defines e)) pdi.pd_dead_blocks in
+		if pdi.pd_dead_blocks <> [] then Hashtbl.replace com.shared.shared_display_information.dead_blocks file dead_blocks
+end
+
 let parse_module_file com file p =
 	let handle_parser_error msg p =
 		let msg = Parser.error_msg msg in
@@ -204,30 +235,7 @@ let parse_module_file com file p =
 			| (msg,p) :: _ -> handle_parser_error msg p
 			| [] -> ()
 			end;
-			if com.display.dms_kind <> DMNone then begin
-				List.iter (fun (p,e) ->
-					if DisplayPosition.display_position#enclosed_in p then begin
-						if not (Define.defined com.defines Define.Macro) then begin
-							let defines = adapt_defines_to_macro_context com.defines in
-							if ParserEntry.is_true (ParserEntry.eval defines e) then
-								raise DisplayInMacroBlock
-						end;
-						begin match com.display.dms_kind with
-						| DMHover ->
-							raise (DisplayException.DisplayException(DisplayHover None))
-						| _ ->
-							()
-						end;
-					end;
-				) pdi.pd_dead_blocks;
-			end;
-			begin match com.display.dms_kind with
-			| DMHover ->
-				List.iter (ConditionDisplay.check_condition com) pdi.pd_conditions;
-			| _ ->
-				()
-			end;
-			if pdi.pd_dead_blocks <> [] then Hashtbl.replace com.display_information.dead_blocks file pdi.pd_dead_blocks;
+			PdiHandler.handle_pdi com file pdi;
 			data
 		| ParseError(data,(msg,p),_) ->
 			handle_parser_error msg p;