Selaa lähdekoodia

[display] introduce DiagnosticsKind.DKParserError

Jens Fischer 6 vuotta sitten
vanhempi
commit
ba016f54eb

+ 2 - 1
.vscode/settings.json

@@ -1,7 +1,8 @@
 {
 	"files.associations": {
 		"*.mly": "ocaml",
-		"*.ml": "ocaml"
+		"*.ml": "ocaml",
+		"Makefile.*": "makefile"
 	},
 	"[ocaml]": {
 		"editor.tabSize": 4

+ 1 - 1
src/compiler/main.ml

@@ -790,7 +790,7 @@ try
 	if com.display.dms_kind <> DMNone then begin
 		com.warning <-
 			if com.display.dms_error_policy = EPCollect then
-				(fun s p -> add_diagnostics_message com s p DisplayTypes.DiagnosticsSeverity.Warning)
+				(fun s p -> add_diagnostics_message com s p DKCompilerError DisplayTypes.DiagnosticsSeverity.Warning)
 			else
 				(fun msg p -> message ctx (CMWarning(msg,p)));
 		com.error <- error ctx;

+ 3 - 3
src/context/common.ml

@@ -143,7 +143,7 @@ end
 
 type shared_display_information = {
 	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.DiagnosticsKind.t * DisplayTypes.DiagnosticsSeverity.t) list;
 }
 
 type display_information = {
@@ -703,9 +703,9 @@ let utf16_to_utf8 str =
 	loop 0;
 	Buffer.contents b
 
-let add_diagnostics_message com s p sev =
+let add_diagnostics_message com s p kind sev =
 	let di = com.shared.shared_display_information in
-	di.diagnostics_messages <- (s,p,sev) :: di.diagnostics_messages
+	di.diagnostics_messages <- (s,p,kind,sev) :: di.diagnostics_messages
 
 open Printer
 

+ 4 - 19
src/context/display/diagnostics.ml

@@ -6,26 +6,11 @@ open Common
 open Display
 open DisplayTypes.DisplayMode
 
-module DiagnosticsKind = struct
-	type t =
-		| DKUnusedImport
-		| DKUnresolvedIdentifier
-		| DKCompilerError
-		| DKRemovableCode
-
-	let to_int = function
-		| DKUnusedImport -> 0
-		| DKUnresolvedIdentifier -> 1
-		| DKCompilerError -> 2
-		| DKRemovableCode -> 3
-end
-
 type diagnostics_context = {
 	com : Common.context;
 	mutable removable_code : (string * pos * pos) list;
 }
 
-open DiagnosticsKind
 open DisplayTypes
 
 let add_removable_code ctx s p prange =
@@ -58,10 +43,10 @@ let find_unused_variables com e =
 let check_other_things com e =
 	let had_effect = ref false in
 	let no_effect p =
-		add_diagnostics_message com "This code has no effect" p DiagnosticsSeverity.Warning;
+		add_diagnostics_message com "This code has no effect" p DKCompilerError DiagnosticsSeverity.Warning;
 	in
 	let pointless_compound s p =
-		add_diagnostics_message com (Printf.sprintf "This %s has no effect, but some of its sub-expressions do" s) p DiagnosticsSeverity.Warning;
+		add_diagnostics_message com (Printf.sprintf "This %s has no effect, but some of its sub-expressions do" s) p DKCompilerError DiagnosticsSeverity.Warning;
 	in
 	let rec compound s el p =
 		let old = !had_effect in
@@ -199,8 +184,8 @@ module Printer = struct
 		PMap.iter (fun p (r,_) ->
 			if not !r then add DKUnusedImport p DiagnosticsSeverity.Warning (JArray [])
 		) com.shared.shared_display_information.import_positions;
-		List.iter (fun (s,p,sev) ->
-			add DKCompilerError p sev (JString s)
+		List.iter (fun (s,p,kind,sev) ->
+			add kind p sev (JString s)
 		) com.shared.shared_display_information.diagnostics_messages;
 		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])

+ 1 - 1
src/context/typecore.ml

@@ -144,7 +144,7 @@ let pass_name = function
 
 let display_error ctx msg p = match ctx.com.display.DisplayMode.dms_error_policy with
 	| DisplayMode.EPShow | DisplayMode.EPIgnore -> ctx.on_error ctx msg p
-	| DisplayMode.EPCollect -> add_diagnostics_message ctx.com msg p DisplayTypes.DiagnosticsSeverity.Error
+	| DisplayMode.EPCollect -> add_diagnostics_message ctx.com msg p DisplayTypes.DiagnosticsKind.DKCompilerError DisplayTypes.DiagnosticsSeverity.Error
 
 let make_call ctx e el t p = (!make_call_ref) ctx e el t p
 

+ 16 - 0
src/core/displayTypes.ml

@@ -63,6 +63,22 @@ module DiagnosticsSeverity = struct
 		| Hint -> 4
 end
 
+module DiagnosticsKind = struct
+	type t =
+		| DKUnusedImport
+		| DKUnresolvedIdentifier
+		| DKCompilerError
+		| DKRemovableCode
+		| DKParserError
+
+	let to_int = function
+		| DKUnusedImport -> 0
+		| DKUnresolvedIdentifier -> 1
+		| DKCompilerError -> 2
+		| DKRemovableCode -> 3
+		| DKParserError -> 4
+end
+
 module CompletionResultKind = struct
 	type t =
 		| CRField of CompletionItem.t * pos

+ 1 - 1
src/typing/typeloadParse.ml

@@ -152,7 +152,7 @@ let parse_module' com m p =
 		match com.display.dms_error_policy with
 			| EPShow -> error msg p
 			| EPIgnore -> ()
-			| EPCollect -> add_diagnostics_message com msg p Error
+			| EPCollect -> add_diagnostics_message com msg p DKParserError Error
 	in
 	let pack,decls = match (!parse_hook) com file p with
 		| ParseSuccess data -> data

+ 1 - 0
tests/display/src/Diagnostic.hx

@@ -12,6 +12,7 @@ enum abstract DiagnosticKind<T>(Int) from Int to Int {
 	var DKUnresolvedIdentifier:DiagnosticKind<Array<{kind:UnresolvedIdentifierSuggestion, name:String}>>;
 	var DKCompilerError:DiagnosticKind<String>;
 	var DKRemovableCode:DiagnosticKind<{description:String, range:Range}>;
+	var DKParserError:DiagnosticKind<String>;
 }
 
 enum abstract DiagnosticSeverity(Int) {

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

@@ -8,7 +8,7 @@ class Issue7932 extends DisplayTestCase {
 	**/
 	function test() {
 		arrayEq([{
-			kind: DKCompilerError,
+			kind: DKParserError,
 			range: diagnosticsRange(pos(1), pos(2)),
 			severity: Error,
 			args: "Expected type parameter"