-
-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[display] refactor diagnostics a bit
see #9134
- Loading branch information
Showing
5 changed files
with
135 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
open Globals | ||
open Json | ||
open DisplayTypes | ||
open DiagnosticsKind | ||
open DisplayTypes | ||
open DiagnosticsTypes | ||
|
||
type t = DiagnosticsKind.t * pos | ||
|
||
module UnresolvedIdentifierSuggestion = struct | ||
type t = | ||
| UISImport | ||
| UISTypo | ||
|
||
let to_int = function | ||
| UISImport -> 0 | ||
| UISTypo -> 1 | ||
end | ||
|
||
open UnresolvedIdentifierSuggestion | ||
open CompletionItem | ||
open CompletionModuleType | ||
|
||
let json_of_diagnostics dctx = | ||
let diag = Hashtbl.create 0 in | ||
let add dk p sev args = | ||
let file = if p = null_pos then p.pfile else Path.get_real_path p.pfile in | ||
let diag = try | ||
Hashtbl.find diag file | ||
with Not_found -> | ||
let d = Hashtbl.create 0 in | ||
Hashtbl.add diag file d; | ||
d | ||
in | ||
if not (Hashtbl.mem diag p) then | ||
Hashtbl.add diag p (dk,p,sev,args) | ||
in | ||
let add dk p sev args = | ||
if dctx.global || p = null_pos || DisplayPosition.display_position#is_in_file p.pfile then add dk p sev args | ||
in | ||
List.iter (fun (s,p,suggestions) -> | ||
let suggestions = ExtList.List.filter_map (fun (s,item,r) -> | ||
match item.ci_kind with | ||
| ITType(t,_) when r = 0 -> | ||
let path = if t.module_name = t.name then (t.pack,t.name) else (t.pack @ [t.module_name],t.name) in | ||
Some (JObject [ | ||
"kind",JInt (to_int UISImport); | ||
"name",JString (s_type_path path); | ||
]) | ||
| _ when r = 0 -> | ||
(* TODO !!! *) | ||
None | ||
| _ -> | ||
Some (JObject [ | ||
"kind",JInt (to_int UISTypo); | ||
"name",JString s; | ||
]) | ||
) suggestions in | ||
add DKUnresolvedIdentifier p DiagnosticsSeverity.Error (JArray suggestions); | ||
) dctx.unresolved_identifiers; | ||
PMap.iter (fun p r -> | ||
if not !r then add DKUnusedImport p DiagnosticsSeverity.Warning (JArray []) | ||
) dctx.import_positions; | ||
List.iter (fun (s,p,kind,sev) -> | ||
add kind p sev (JString s) | ||
) (List.rev dctx.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]) | ||
) dctx.removable_code; | ||
Hashtbl.iter (fun p s -> | ||
add DKDeprecationWarning p DiagnosticsSeverity.Warning (JString s); | ||
) DeprecationCheck.warned_positions; | ||
Hashtbl.iter (fun file ranges -> | ||
List.iter (fun (p,e) -> | ||
let jo = JObject [ | ||
"expr",JObject [ | ||
"string",JString (Ast.Printer.s_expr e) | ||
] | ||
] in | ||
add DKInactiveBlock p DiagnosticsSeverity.Hint jo | ||
) ranges | ||
) dctx.dead_blocks; | ||
let jl = Hashtbl.fold (fun file diag acc -> | ||
let jl = Hashtbl.fold (fun _ (dk,p,sev,jargs) acc -> | ||
(JObject [ | ||
"kind",JInt (DiagnosticsKind.to_int dk); | ||
"severity",JInt (DiagnosticsSeverity.to_int sev); | ||
"range",Genjson.generate_pos_as_range p; | ||
"args",jargs | ||
]) :: acc | ||
) diag [] in | ||
(JObject [ | ||
"file",if file = "?" then JNull else JString file; | ||
"diagnostics",JArray jl | ||
]) :: acc | ||
) diag [] in | ||
let js = JArray jl in | ||
js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open Globals | ||
open Ast | ||
|
||
type diagnostics_context = { | ||
global : bool; | ||
mutable removable_code : (string * pos * pos) list; | ||
mutable import_positions : (pos,bool ref) PMap.t; | ||
mutable dead_blocks : (string,(pos * expr) list) Hashtbl.t; | ||
mutable unresolved_identifiers : (string * pos * (string * CompletionItem.t * int) list) list; | ||
mutable diagnostics_messages : (string * pos * DisplayTypes.DiagnosticsKind.t * DisplayTypes.DiagnosticsSeverity.t) list; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters