Skip to content

Commit

Permalink
Support LSP-compliant relatedInformation field
Browse files Browse the repository at this point in the history
Summary:
Include both the nuclide-specific `relatedLocations`, and the identical LSP-standard `relatedInformation`

fixes slackhq/vscode-hack#17

Reviewed By: pittsw, arxanas

Differential Revision: D8286533

fbshipit-source-id: 2b02928b875a44ee563e1999f9ba7a1f50a3bf2f
  • Loading branch information
fredemmott authored and facebook-github-bot committed Jun 5, 2018
1 parent ae50332 commit 30c21b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions hack/utils/lsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ module PublishDiagnostics = struct
code: diagnosticCode; (* the diagnostic's code. *)
source: string option; (* human-readable string, eg. typescript/lint *)
message: string; (* the diagnostic's message *)
relatedLocations: relatedLocation list;
relatedInformation: diagnosticRelatedInformation list;
relatedLocations: relatedLocation list; (* legacy FB extension *)
}

and diagnosticCode =
Expand All @@ -435,10 +436,13 @@ module PublishDiagnostics = struct
| Information (* 3 *)
| Hint (* 4 *)

and relatedLocation = {
and diagnosticRelatedInformation = {
relatedLocation: Location.t; (* wire: just "location" *)
relatedMessage: string; (* wire: just "message" *)
}

(* legacy FB extension *)
and relatedLocation = diagnosticRelatedInformation
end

(* DidOpenTextDocument notification, method="textDocument/didOpen" *)
Expand Down
2 changes: 2 additions & 0 deletions hack/utils/lsp_fmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ let print_diagnostics (r: PublishDiagnostics.params) : json =
"code", print_diagnosticCode diagnostic.code;
"source", Option.map diagnostic.source string_;
"message", Some (JSON_String diagnostic.message);
"relatedInformation",
Some (JSON_Array (List.map diagnostic.relatedInformation ~f:print_related));
"relatedLocations", Some (JSON_Array (List.map diagnostic.relatedLocations ~f:print_related));
]
in
Expand Down
6 changes: 5 additions & 1 deletion src/commands/lspCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1015,13 +1015,17 @@ begin
let related_to_lsp (loc, relatedMessage) =
let relatedLocation = Flow_lsp_conversions.loc_to_lsp_with_default loc ~default_uri in
{ Lsp.PublishDiagnostics.relatedLocation; relatedMessage; } in
let relatedInformation =
List.map error.Errors.Lsp_output.relatedLocations ~f:related_to_lsp
in
let diagnostic = { Lsp.PublishDiagnostics.
range = location.Lsp.Location.range;
severity;
code = Lsp.PublishDiagnostics.StringCode error.Errors.Lsp_output.code;
source = Some "Flow";
message = error.Errors.Lsp_output.message;
relatedLocations = List.map error.Errors.Lsp_output.relatedLocations ~f:related_to_lsp;
relatedInformation;
relatedLocations = relatedInformation; (* legacy fb extension *)
} in
SMap.add ~combine:List.append uri [diagnostic] all
in
Expand Down

0 comments on commit 30c21b9

Please sign in to comment.