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 hhvm-bot committed Jun 5, 2018
1 parent ed55b0a commit 59d1394
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 3 additions & 2 deletions hphp/hack/src/client/clientLsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ let hack_errors_to_lsp_diagnostic
| [] -> failwith "Expected at least one error in the error list"
in
let ({range; _}, message) = first_message in
let relatedLocations = additional_messages |> List.map ~f:(fun (location, message) ->
let relatedInformation = additional_messages |> List.map ~f:(fun (location, message) ->
{ PublishDiagnostics.
relatedLocation = location;
relatedMessage = message;
Expand All @@ -598,7 +598,8 @@ let hack_errors_to_lsp_diagnostic
code = PublishDiagnostics.IntCode (Errors.get_code error);
source = Some "Hack";
message;
relatedLocations;
relatedInformation;
relatedLocations = relatedInformation; (* legacy FB extension *)
}
in
(* The caller is required to give us a non-empty filename. If it is empty, *)
Expand Down
8 changes: 6 additions & 2 deletions hphp/hack/src/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 hphp/hack/src/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

0 comments on commit 59d1394

Please sign in to comment.