Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[display] Remove legacy diagnostics #11413

Draft
wants to merge 3 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ let run_or_diagnose ctx f =
let handle_diagnostics msg p kind =
ctx.has_error <- true;
add_diagnostics_message com msg p kind Error;
match com.report_mode with
| RMLegacyDiagnostics _ -> DisplayOutput.emit_legacy_diagnostics ctx.com
| RMDiagnostics _ -> DisplayOutput.emit_diagnostics ctx.com
| _ -> die "" __LOC__
DisplayOutput.emit_diagnostics ctx.com
in
if is_diagnostics com then begin try
f ()
Expand All @@ -20,10 +17,7 @@ let run_or_diagnose ctx f =
Error.recurse_error (fun depth err ->
add_diagnostics_message ~depth com (Error.error_msg err.err_message) err.err_pos DKCompilerMessage Error
) err;
(match com.report_mode with
| RMLegacyDiagnostics _ -> DisplayOutput.emit_legacy_diagnostics ctx.com
| RMDiagnostics _ -> DisplayOutput.emit_diagnostics ctx.com
| _ -> die "" __LOC__)
DisplayOutput.emit_diagnostics ctx.com;
| Parser.Error(msg,p) ->
handle_diagnostics (Parser.error_msg msg) p DKParserError
| Lexer.Error(msg,p) ->
Expand Down
6 changes: 0 additions & 6 deletions src/compiler/displayOutput.ml
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,6 @@ let handle_type_path_exception ctx p c is_import pos =
api.send_result (DisplayException.fields_to_json ctx fields kind (DisplayTypes.make_subject None pos));
end

let emit_legacy_diagnostics com =
let dctx = Diagnostics.run com in
let s = Json.string_of_json (DiagnosticsPrinter.json_of_diagnostics com dctx) in
DisplayPosition.display_position#reset;
raise (Completion s)

let emit_diagnostics com =
(match com.Common.json_out with
| None -> die "" __LOC__
Expand Down
9 changes: 0 additions & 9 deletions src/compiler/displayProcessing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ let handle_display_argument_old com file_pos actx =
| "memory" ->
actx.did_something <- true;
(try Memory.display_memory com with e -> prerr_endline (Printexc.get_backtrace ()));
| "diagnostics" ->
com.report_mode <- RMLegacyDiagnostics []
| _ ->
let file, pos = try ExtString.String.split file_pos "@" with _ -> failwith ("Invalid format: " ^ file_pos) in
let file = Helper.unquote file in
let file_unique = com.file_keys#get file in
let pos, smode = try ExtString.String.split pos "@" with _ -> pos,"" in
let create mode =
Parser.display_mode := mode;
Expand All @@ -45,10 +42,6 @@ let handle_display_argument_old com file_pos actx =
create DMDefault
| "module-symbols" ->
create (DMModuleSymbols None)
| "diagnostics" ->
com.report_mode <- RMLegacyDiagnostics [file_unique];
let dm = create DMNone in
{dm with dms_display_file_policy = DFPAlso; dms_per_file = true; dms_populate_cache = !ServerConfig.populate_cache_from_display}
| "statistics" ->
com.report_mode <- RMStatistics;
let dm = create DMNone in
Expand Down Expand Up @@ -348,8 +341,6 @@ let handle_display_after_finalization ctx tctx display_file_dot_path =
end;
process_global_display_mode com tctx;
begin match com.report_mode with
| RMLegacyDiagnostics _ ->
DisplayOutput.emit_legacy_diagnostics com
| RMDiagnostics _ ->
DisplayOutput.emit_diagnostics com
| RMStatistics ->
Expand Down
11 changes: 3 additions & 8 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ open Common
open CompilationCache
open Timer
open Type
open DisplayProcessingGlobals
open Ipaddr
open Json
open CompilationContext
Expand All @@ -28,15 +27,11 @@ let check_display_flush ctx f_otherwise = match ctx.com.json_out with
api.send_error errors
end
| _ ->
if is_diagnostics ctx.com then begin
if is_diagnostics ctx.com then
List.iter (fun cm ->
add_diagnostics_message ~depth:cm.cm_depth ctx.com cm.cm_message cm.cm_pos cm.cm_kind cm.cm_severity
) (List.rev ctx.messages);
(match ctx.com.report_mode with
| RMDiagnostics _ -> ()
| RMLegacyDiagnostics _ -> raise (Completion (Diagnostics.print ctx.com))
| _ -> die "" __LOC__)
end else
) (List.rev ctx.messages)
else
f_otherwise ()

let current_stdin = ref None
Expand Down
3 changes: 1 addition & 2 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ let s_compiler_stage = function

type report_mode =
| RMNone
| RMLegacyDiagnostics of (Path.UniqueKey.t list)
| RMDiagnostics of (Path.UniqueKey.t list)
| RMStatistics

Expand Down Expand Up @@ -893,7 +892,7 @@ let create compilation_step cs version args =
com

let is_diagnostics com = match com.report_mode with
| RMLegacyDiagnostics _ | RMDiagnostics _ -> true
| RMDiagnostics _ -> true
| _ -> false

let disable_report_mode com =
Expand Down
4 changes: 2 additions & 2 deletions src/context/display/diagnosticsPrinter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ let make_diagnostic kd p sev code args = {

let is_diagnostics_file com file_key =
match com.report_mode with
| RMLegacyDiagnostics [] | RMDiagnostics [] -> true
| RMLegacyDiagnostics file_keys | RMDiagnostics file_keys -> List.mem file_key file_keys
| RMDiagnostics [] -> true
| RMDiagnostics file_keys -> List.mem file_key file_keys
| _ -> false

module UnresolvedIdentifierSuggestion = struct
Expand Down
9 changes: 7 additions & 2 deletions tests/display/src/DisplayTestContext.hx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ class DisplayTestContext {
}

public function diagnostics():Array<Diagnostic<Dynamic>> {
var result = haxe.Json.parse(callHaxe('0@diagnostics'))[0];
return if (result == null) [] else result.diagnostics;
var args = ["--display", haxe.Json.stringify({jsonrpc:"2.0",id:0,method:"display/diagnostics",params:{"file":source.path}})];
var result = runHaxe(args, source.content);
if (result.hasError || result.stderr == "") {
throw new HaxeInvocationException(result.stderr, fieldName, args, source.content);
}
var result = haxe.Json.parse(result.stderr).result;
return if (result.result.length == 0) [] else result.result[0].diagnostics;
}

public function hasErrorMessage(f:()->Void, message:String) {
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue11020/compile.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-cp src
-main Main
--interp
--display "Main.hx@0@diagnostics"
--display '{"jsonrpc":"2.0","id":0,"method":"display/diagnostics","params":{"file":"Main.hx"}}'
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue6794/compile.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--main Main
--display "Main.hx@0@diagnostics"
--display '{"jsonrpc":"2.0","id":0,"method":"display/diagnostics","params":{"file":"Main.hx"}}'
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue9676/compile1D.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--main MainField
--display "MainField.hx@0@diagnostics"
--display '{"jsonrpc":"2.0","id":0,"method":"display/diagnostics","params":{"file":"MainField.hx"}}'
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue9676/compile2D.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--main MainExpr
--display "MainExpr.hx@0@diagnostics"
--display '{"jsonrpc":"2.0","id":0,"method":"display/diagnostics","params":{"file":"MainExpr.hx"}}'
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue9676/compile3D.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
--main MainMacro
--display "MainMacro.hx@0@diagnostics"
--display '{"jsonrpc":"2.0","id":0,"method":"display/diagnostics","params":{"file":"MainMacro.hx"}}'