always use textEdits for autocomplete
commit8cd1addc6e195353e36f5880914ee895e99401d9
authorLucian Wischik <ljw@fb.com>
Thu, 17 Mar 2022 16:08:06 +0000 (17 09:08 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 17 Mar 2022 16:08:06 +0000 (17 09:08 -0700)
tree2c8bc2bc760f2ec568129f3b88729b7331d8a67d
parent4e18379eb2e5a56ed9ba7698a56e0ed7a0296bbe
always use textEdits for autocomplete

Summary:
LSP recommends to use text-edits for autocomplete
```
 * The `insertText` is subject to interpretation by the client side.
 * Some tools might not take the string literally. For example
 * VS Code when code complete is requested in this example
 * `con<cursor position>` and a completion item with an `insertText` of
 * `console` is provided it will only insert `sole`. Therefore it is
 * recommended to use `textEdit` instead since it avoids additional client
 * side interpretation.
```

Prior to this diff, Hack would default to using insertText unless it had been sent the initializationOption "useTextEditAutocomplete" in which case it would use the (better) TextEdit.

After this diff, it will now always use TextEdit.

We know that VSCode supports TextEdit autocomplete: https://github.com/microsoft/language-server-protocol/issues/264#issuecomment-346864271

Does emacs support TextEdit autocomplete? It looks like it: https://github.com/emacs-lsp/lsp-mode/blob/ea6f2f8d0beaa713feaed1688ea0610392199eda/lsp-completion.el#L554-L572

Does Vim support TextEdit autocomplete? I don't know...

Does Atom support TextEdit autocomplete? It didn't three years ago, but I don't know the status now.

Note: the code still uses insertText for snippets, like it always did. I can't remember the reason for this. Is it because Nuclide didn't support insertText for snippets? Is it because we just didn't get around to it? I can't remember. Anyway, I left it as is.

Reviewed By: Wilfred

Differential Revision: D34911115

fbshipit-source-id: 42f78f50800493725014746871620470bec5bd16
hphp/hack/src/client/clientLsp.ml
hphp/hack/src/utils/lsp/lsp.ml
hphp/hack/src/utils/lsp/lsp.mli
hphp/hack/src/utils/lsp/lsp_fmt.ml
hphp/hack/test/integration/test_lsp.py