From 00d6912d92504401c79b832e9df7c6d8cd2d5d19 Mon Sep 17 00:00:00 2001 From: Lucian Wischik Date: Tue, 29 May 2018 19:57:25 -0700 Subject: [PATCH] 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 | 14 +++++++++++--- hphp/hack/src/utils/symbolDefinition.ml | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hphp/hack/src/client/clientLsp.ml b/hphp/hack/src/client/clientLsp.ml index 46cd1e09ac2..c28b06c69f5 100644 --- a/hphp/hack/src/client/clientLsp.ml +++ b/hphp/hack/src/client/clientLsp.ml @@ -538,7 +538,14 @@ let lsp_range_to_ide (range: Lsp.range) : Ide_api_types.range = ed = lsp_position_to_ide range.end_; } -let hack_symbol_definition_to_lsp_location +let hack_symbol_definition_to_lsp_construct_location + (symbol: string SymbolDefinition.t) + ~(default_path: string) + : Lsp.Location.t = + let open SymbolDefinition in + hack_pos_to_lsp_location symbol.span ~default_path + +let hack_symbol_definition_to_lsp_identifier_location (symbol: string SymbolDefinition.t) ~(default_path: string) : Lsp.Location.t = @@ -791,7 +798,8 @@ let do_definition (conn: server_conn) (ref_unblocked_time: float ref) (params: D | [] -> [] | (_occurrence, None) :: l -> hack_to_lsp l | (_occurrence, Some definition) :: l -> - (hack_symbol_definition_to_lsp_location definition ~default_path:file) :: (hack_to_lsp l) + (hack_symbol_definition_to_lsp_identifier_location definition ~default_path:file) + :: (hack_to_lsp l) in hack_to_lsp filtered_results @@ -1039,7 +1047,7 @@ let do_documentSymbol { SymbolInformation. name = definition.name; kind = hack_to_lsp_kind definition.kind; - location = hack_symbol_definition_to_lsp_location definition ~default_path:filename; + location = hack_symbol_definition_to_lsp_construct_location definition ~default_path:filename; containerName; } in diff --git a/hphp/hack/src/utils/symbolDefinition.ml b/hphp/hack/src/utils/symbolDefinition.ml index 1afa3db7f11..7b41fd45415 100644 --- a/hphp/hack/src/utils/symbolDefinition.ml +++ b/hphp/hack/src/utils/symbolDefinition.ml @@ -38,8 +38,8 @@ and 'a t = { name : string; full_name : string; id : string option; - pos : 'a Pos.pos; - span : 'a Pos.pos; + pos : 'a Pos.pos; (* covers the span of just the identifier *) + span : 'a Pos.pos; (* covers the span of the entire construct, including children *) modifiers : modifier list; children : 'a t list option; params : 'a t list option; -- 2.11.4.GIT