From 59d13948f72ae9f38784905d810d918e89c02606 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Tue, 5 Jun 2018 16:02:33 -0700 Subject: [PATCH] Support LSP-compliant `relatedInformation` field Summary: Include both the nuclide-specific `relatedLocations`, and the identical LSP-standard `relatedInformation` fixes PranayAgarwal/vscode-hack#17 Reviewed By: pittsw, arxanas Differential Revision: D8286533 fbshipit-source-id: 2b02928b875a44ee563e1999f9ba7a1f50a3bf2f --- hphp/hack/src/client/clientLsp.ml | 5 +++-- hphp/hack/src/utils/lsp.ml | 8 ++++++-- hphp/hack/src/utils/lsp_fmt.ml | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/hphp/hack/src/client/clientLsp.ml b/hphp/hack/src/client/clientLsp.ml index dd7894c21d8..9c4bc147026 100644 --- a/hphp/hack/src/client/clientLsp.ml +++ b/hphp/hack/src/client/clientLsp.ml @@ -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; @@ -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, *) diff --git a/hphp/hack/src/utils/lsp.ml b/hphp/hack/src/utils/lsp.ml index e7008cb4a8e..50fbf6c4aad 100644 --- a/hphp/hack/src/utils/lsp.ml +++ b/hphp/hack/src/utils/lsp.ml @@ -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 = @@ -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" *) diff --git a/hphp/hack/src/utils/lsp_fmt.ml b/hphp/hack/src/utils/lsp_fmt.ml index 0b7a3062f0c..cceddb66e0d 100644 --- a/hphp/hack/src/utils/lsp_fmt.ml +++ b/hphp/hack/src/utils/lsp_fmt.ml @@ -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 -- 2.11.4.GIT