浏览代码

[display] move removable_code to diagnostics context

see #5696
Simon Krajewski 7 年之前
父节点
当前提交
bca3e39348
共有 3 个文件被更改,包括 25 次插入18 次删除
  1. 2 2
      src/compiler/displayOutput.ml
  2. 0 2
      src/context/common.ml
  3. 23 14
      src/context/display/diagnostics.ml

+ 2 - 2
src/compiler/displayOutput.ml

@@ -615,8 +615,8 @@ let process_global_display_mode com tctx = match com.display.dms_kind with
 		Display.reference_position := null_pos;
 		Display.reference_position := null_pos;
 		raise_position usages
 		raise_position usages
 	| DMDiagnostics global ->
 	| DMDiagnostics global ->
-		Diagnostics.prepare com global;
-		raise_diagnostics (Diagnostics.Printer.print_diagnostics tctx global)
+		let dctx = Diagnostics.prepare com global in
+		raise_diagnostics (Diagnostics.Printer.print_diagnostics dctx tctx global)
 	| DMStatistics ->
 	| DMStatistics ->
 		let stats = Statistics.collect_statistics tctx in
 		let stats = Statistics.collect_statistics tctx in
 		raise_statistics (Statistics.Printer.print_statistics stats)
 		raise_statistics (Statistics.Printer.print_statistics stats)

+ 0 - 2
src/context/common.ml

@@ -107,7 +107,6 @@ type shared_display_information = {
 	mutable import_positions : (pos,bool ref * placed_name list) PMap.t;
 	mutable import_positions : (pos,bool ref * placed_name list) PMap.t;
 	mutable diagnostics_messages : (string * pos * DisplayTypes.DiagnosticsSeverity.t) list;
 	mutable diagnostics_messages : (string * pos * DisplayTypes.DiagnosticsSeverity.t) list;
 	mutable document_symbols : (string * DisplayTypes.SymbolInformation.t DynArray.t) list;
 	mutable document_symbols : (string * DisplayTypes.SymbolInformation.t DynArray.t) list;
-	mutable removable_code : (string * pos * pos) list;
 }
 }
 
 
 type display_information = {
 type display_information = {
@@ -515,7 +514,6 @@ let create version s_version args =
 				import_positions = PMap.empty;
 				import_positions = PMap.empty;
 				diagnostics_messages = [];
 				diagnostics_messages = [];
 				document_symbols = [];
 				document_symbols = [];
-				removable_code = [];
 			}
 			}
 		};
 		};
 		display_information = {
 		display_information = {

+ 23 - 14
src/context/display/diagnostics.ml

@@ -20,12 +20,16 @@ module DiagnosticsKind = struct
 		| DKRemovableCode -> 3
 		| DKRemovableCode -> 3
 end
 end
 
 
+type diagnostics_context = {
+	com : Common.context;
+	mutable removable_code : (string * pos * pos) list;
+}
+
 open DiagnosticsKind
 open DiagnosticsKind
 open DisplayTypes
 open DisplayTypes
 
 
-let add_removable_code com s p prange =
-	let di = com.shared.shared_display_information in
-	di.removable_code <- (s,p,prange) :: di.removable_code
+let add_removable_code ctx s p prange =
+	ctx.removable_code <- (s,p,prange) :: ctx.removable_code
 
 
 let find_unused_variables com e =
 let find_unused_variables com e =
 	let vars = Hashtbl.create 0 in
 	let vars = Hashtbl.create 0 in
@@ -105,22 +109,27 @@ let check_other_things com e =
 	in
 	in
 	loop true e
 	loop true e
 
 
-let prepare_field com cf = match cf.cf_expr with
+let prepare_field dctx cf = match cf.cf_expr with
 	| None -> ()
 	| None -> ()
 	| Some e ->
 	| Some e ->
-		find_unused_variables com e;
-		check_other_things com e;
-		DeprecationCheck.run_on_expr com e
+		find_unused_variables dctx e;
+		check_other_things dctx.com e;
+		DeprecationCheck.run_on_expr dctx.com e
 
 
 let prepare com global =
 let prepare com global =
+	let dctx = {
+		removable_code = [];
+		com = com;
+	} in
 	List.iter (function
 	List.iter (function
 		| TClassDecl c when global || is_display_file c.cl_pos.pfile ->
 		| TClassDecl c when global || is_display_file c.cl_pos.pfile ->
-			List.iter (prepare_field com) c.cl_ordered_fields;
-			List.iter (prepare_field com) c.cl_ordered_statics;
-			(match c.cl_constructor with None -> () | Some cf -> prepare_field com cf);
+			List.iter (prepare_field dctx) c.cl_ordered_fields;
+			List.iter (prepare_field dctx) c.cl_ordered_statics;
+			(match c.cl_constructor with None -> () | Some cf -> prepare_field dctx cf);
 		| _ ->
 		| _ ->
 			()
 			()
-	) com.types
+	) com.types;
+	dctx
 
 
 let is_diagnostics_run p = match (!Parser.display_mode) with
 let is_diagnostics_run p = match (!Parser.display_mode) with
 	| DMDiagnostics true -> true
 	| DMDiagnostics true -> true
@@ -148,8 +157,8 @@ module Printer = struct
 			| UISTypo -> 1
 			| UISTypo -> 1
 	end
 	end
 
 
-	let print_diagnostics ctx global =
-		let com = ctx.com in
+	let print_diagnostics dctx ctx global =
+		let com = dctx.com in
 		let diag = Hashtbl.create 0 in
 		let diag = Hashtbl.create 0 in
 		let add dk p sev args =
 		let add dk p sev args =
 			let file = Path.get_real_path p.pfile in
 			let file = Path.get_real_path p.pfile in
@@ -197,7 +206,7 @@ module Printer = struct
 		) com.shared.shared_display_information.diagnostics_messages;
 		) com.shared.shared_display_information.diagnostics_messages;
 		List.iter (fun (s,p,prange) ->
 		List.iter (fun (s,p,prange) ->
 			add DKRemovableCode p DiagnosticsSeverity.Warning (JObject ["description",JString s;"range",if prange = null_pos then JNull else Genjson.generate_pos_as_range prange])
 			add DKRemovableCode p DiagnosticsSeverity.Warning (JObject ["description",JString s;"range",if prange = null_pos then JNull else Genjson.generate_pos_as_range prange])
-		) com.shared.shared_display_information.removable_code;
+		) dctx.removable_code;
 		let jl = Hashtbl.fold (fun file diag acc ->
 		let jl = Hashtbl.fold (fun file diag acc ->
 			let jl = DynArray.fold_left (fun acc (dk,p,sev,jargs) ->
 			let jl = DynArray.fold_left (fun acc (dk,p,sev,jargs) ->
 				(JObject [
 				(JObject [