documentSymbol emits span of entire construct
commit00d6912d92504401c79b832e9df7c6d8cd2d5d19
authorLucian Wischik <ljw@fb.com>
Wed, 30 May 2018 02:57:25 +0000 (29 19:57 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Wed, 30 May 2018 03:19:32 +0000 (29 20:19 -0700)
treebde62077c43b5eba2962a090a305c7c9eb0fce9d
parente35c22a5cd2857fd59641871bce7610b97afdb4a
documentSymbol emits span of entire construct

Summary:
This diff lights up two new features in Nuclide: (1) breadcrumbs bar, (2) in outline view, it highlights the construct that your caret is on. It also makes hackLsp more compatible with VSCode outline-view plugins.

Background: When I wrote HackLSP I thought that in documentSymbol, the "range" for each symbol referred just to the identifier. But industry practice has settled on it returning the entire range of the construct, e.g. for a class it returns the range from the beginning of "public class" to the end of "}".

(Clients have to decide how to reconstruct outline view from the flat list that is documentSymbol. Because of the above industry practice, they tend to reconstruct it based on range inclusion).

This diff moves Hack over to return the range of the entire construct as well for sake of textDocument/documentSymbol. (but for textDocument/definition it returns only the range of the identifier, similar to what VSCode does, so that e.g. when you hyperclick on `foo()` then it takes you to the `foo` in `public function foo`, rather than taking you to the `public`.)

PLAN: (1) Land this Hack change. (2) Once the Hack change has shipped widely enough, change Nuclide to reconstruct outline view based on range inclusion rather than containerName.

Nuclide also uses the full ranges to highlight the current item you're on in the outline view, and also to show breadcrumbs.

Reviewed By: pittsw

Differential Revision: D8179623

fbshipit-source-id: b158675d591bd5cae37de1c5efc0c37509ee91f5
hphp/hack/src/client/clientLsp.ml
hphp/hack/src/utils/symbolDefinition.ml