Skip to content
Permalink
Browse files

Band-aid regression in as-you-type formatting support for vscode

Summary:
Minimal fix for T29372533, suitable for cherry-picking.

This will probably want to be reverted as part of an actual fix - but
until that happens, band-aiding it in the LSP code feels cleaner than
in hackfmt itself.

Differential Revision: D8062267
  • Loading branch information...
fredemmott committed May 21, 2018
1 parent a7cdefc commit 2760d8639821b2c3105b2a0a3af7a437bed5f83b
Showing with 9 additions and 2 deletions.
  1. +9 −2 hphp/hack/src/client/clientLsp.ml
@@ -1185,14 +1185,21 @@ let do_signatureHelp

let do_documentOnTypeFormatting
(editor_open_files: Lsp.TextDocumentItem.t SMap.t)
(from: string)
(params: DocumentOnTypeFormatting.params)
: DocumentOnTypeFormatting.result =
let open DocumentOnTypeFormatting in
let open TextDocumentIdentifier in
let fixup_position position =
(* temporary workaround for T29372533: Nuclide points at the trigger character... *)
if from = "nuclide" then position
(* ... but other LSP editors such as vscode point one character later *)
else {position with character = position.character - 1}
in
let action = ServerFormatTypes.Position
{ Ide_api_types.
filename = lsp_uri_to_path params.textDocument.uri;
position = lsp_position_to_ide params.position;
position = lsp_position_to_ide (fixup_position params.position);
} in
do_formatting_common editor_open_files action params.options

@@ -2076,7 +2083,7 @@ let handle_event
| Main_loop menv, Client_message c when c.method_ = "textDocument/onTypeFormatting" ->
cancel_if_stale client c short_timeout;
parse_documentOnTypeFormatting c.params
|> do_documentOnTypeFormatting menv.editor_open_files
|> do_documentOnTypeFormatting menv.editor_open_files env.from
|> print_documentOnTypeFormatting |> Jsonrpc.respond to_stdout c

(* textDocument/didOpen notification *)

0 comments on commit 2760d86

Please sign in to comment.
You can’t perform that action at this time.