Skip to content

Commit bffd992

Browse files
Catherine Gasnierfacebook-github-bot
authored andcommitted
use File_content.Position.t in many more places
Summary: The IDE code caries a lot of `line` and `column` parameters which originally come from a `File_content.Position.t`. Since that type is now nicely abstracting the indexing base, let's propagate it everywhere where a raw line and column are used. That's a lot of places... Reviewed By: andrewjkennedy Differential Revision: D68553997 fbshipit-source-id: fe98c3fe019e5f39db75aefc9448c47c1f61f2fa
1 parent 9c68ed1 commit bffd992

File tree

69 files changed

+428
-426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+428
-426
lines changed

hphp/hack/src/client/clientCheck.ml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ let main_internal
521521
| ClientEnv.MODE_IDENTIFY_SYMBOL2 arg
522522
| ClientEnv.MODE_IDENTIFY_SYMBOL3 arg ->
523523
let (line, char) = parse_position_string ~split_on:":" arg in
524+
let pos = File_content.Position.from_one_based line char in
524525
let file =
525526
match args.ClientEnv.stdin_name with
526527
| None -> ""
@@ -530,8 +531,7 @@ let main_internal
530531
ServerCommandTypes.FileContent (Sys_utils.read_stdin_to_string ())
531532
in
532533
let%lwt (result, telemetry) =
533-
rpc args
534-
@@ ServerCommandTypes.IDENTIFY_FUNCTION (file, content, line, char)
534+
rpc args @@ ServerCommandTypes.IDENTIFY_FUNCTION (file, content, pos)
535535
in
536536
ClientGetDefinition.go result args.ClientEnv.output_json;
537537
Lwt.return (Exit_status.No_error, telemetry)
@@ -556,8 +556,9 @@ let main_internal
556556
Printf.eprintf "Invalid position\n";
557557
raise Exit_status.(Exit_with Input_error)
558558
in
559+
let pos = File_content.Position.from_one_based line char in
559560
let%lwt (ty, telemetry) =
560-
rpc args @@ ServerCommandTypes.INFER_TYPE (fn, line, char)
561+
rpc args @@ ServerCommandTypes.INFER_TYPE (fn, pos)
561562
in
562563
ClientTypeAtPos.go ty args.ClientEnv.output_json;
563564
Lwt.return (Exit_status.No_error, telemetry)
@@ -568,16 +569,23 @@ let main_internal
568569
match Str.split (Str.regexp ":") pos with
569570
| [filename; line; char] ->
570571
( expand_path filename,
571-
int_of_string line,
572-
int_of_string char,
572+
File_content.Position.from_one_based
573+
(int_of_string line)
574+
(int_of_string char),
573575
None )
574576
| [filename; start_line; start_char; end_line; end_char] ->
575577
let filename = expand_path filename in
576578
let start_line = int_of_string start_line in
577579
let start_char = int_of_string start_char in
578580
let end_line = int_of_string end_line in
579581
let end_char = int_of_string end_char in
580-
(filename, start_line, start_char, Some (end_line, end_char))
582+
let start_pos =
583+
File_content.Position.from_one_based start_line start_char
584+
in
585+
let end_pos =
586+
File_content.Position.from_one_based end_line end_char
587+
in
588+
(filename, start_pos, Some end_pos)
581589
| _ -> raise Exit
582590
with
583591
| _ ->

hphp/hack/src/client/clientLsp.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,14 +1015,13 @@ let lsp_position_to_ide ({ Lsp.line; character } : Lsp.position) :
10151015
File_content.Position.from_zero_based line character
10161016

10171017
let lsp_file_position_to_hack (params : Lsp.TextDocumentPositionParams.t) :
1018-
string * int * int =
1018+
string * File_content.Position.t =
10191019
let open Lsp.TextDocumentPositionParams in
10201020
let pos = lsp_position_to_ide params.position in
10211021
let filename =
10221022
Lsp_helpers.lsp_textDocumentIdentifier_to_filename params.textDocument
10231023
in
1024-
let (line, column) = File_content.Position.line_column_one_based pos in
1025-
(filename, line, column)
1024+
(filename, pos)
10261025

10271026
let rename_params_to_document_position (params : Lsp.Rename.params) :
10281027
Lsp.TextDocumentPositionParams.t =
@@ -1290,15 +1289,14 @@ Raises an LSP [InvalidRequest] exception if the file isn't currently open. *)
12901289
let get_document_location
12911290
(editor_open_files : Lsp.TextDocumentItem.t UriMap.t)
12921291
(params : Lsp.TextDocumentPositionParams.t) :
1293-
ClientIdeMessage.document * ClientIdeMessage.location =
1294-
let (file_path, line, column) = lsp_file_position_to_hack params in
1292+
ClientIdeMessage.document * File_content.Position.t =
1293+
let (file_path, pos) = lsp_file_position_to_hack params in
12951294
let uri =
12961295
params.TextDocumentPositionParams.textDocument.TextDocumentIdentifier.uri
12971296
in
12981297
let file_path = Path.make file_path in
12991298
let file_contents = get_document_contents editor_open_files uri in
1300-
( { ClientIdeMessage.file_path; file_contents },
1301-
{ ClientIdeMessage.line; column } )
1299+
({ ClientIdeMessage.file_path; file_contents }, pos)
13021300

13031301
(** Parses output of "hh --ide-find-references" and "hh --ide-go-to-impl".
13041302
If the output is malformed, raises an exception. *)
@@ -2510,11 +2508,12 @@ let do_resolve
25102508
let ranking_detail = Jget.string_opt data "ranking_detail" in
25112509
let ranking_source = Jget.int_opt data "ranking_source" in
25122510
if line = 0 && column = 0 then failwith "NoFileLineColumnData";
2511+
let pos = File_content.Position.from_one_based line column in
25132512
let request =
25142513
ClientIdeMessage.Completion_resolve_location
25152514
( file_path,
25162515
ClientIdeMessage.Full_name fullname,
2517-
{ ClientIdeMessage.line; column },
2516+
pos,
25182517
resolve_ranking_source kind ranking_source )
25192518
in
25202519
let%lwt raw_docblock =

hphp/hack/src/client/ide_service/clientIdeDaemon.ml

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -807,19 +807,18 @@ let handle_request
807807
(***********************************************************)
808808
(************************* NORMAL HANDLING AFTER INIT ******)
809809
(***********************************************************)
810-
| (Initialized istate, Hover (document, { line; column })) ->
810+
| (Initialized istate, Hover (document, pos)) ->
811811
let (istate, ctx, entry, _) = update_file_ctx istate document in
812812
let result =
813813
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
814-
Ide_hover.go_quarantined ~ctx ~entry ~line ~column)
814+
Ide_hover.go_quarantined ~ctx ~entry pos)
815815
in
816816
(Initialized istate, Ok result)
817-
| ( Initialized istate,
818-
Go_to_implementation (document, { line; column }, document_list) ) ->
817+
| (Initialized istate, Go_to_implementation (document, pos, document_list)) ->
819818
let (istate, ctx, entry, _) = update_file_ctx istate document in
820819
let (istate, result) =
821820
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
822-
match ServerFindRefs.go_from_file_ctx ~ctx ~entry ~line ~column with
821+
match ServerFindRefs.go_from_file_ctx ~ctx ~entry pos with
823822
| Some (_name, action)
824823
when not @@ ServerGoToImpl.is_searchable ~action ->
825824
(istate, ClientIdeMessage.Invalid_symbol_impl)
@@ -874,17 +873,15 @@ let handle_request
874873
in
875874
(Initialized istate, Ok result)
876875
(* textDocument/rename *)
877-
| ( Initialized istate,
878-
Rename (document, { line; column }, new_name, document_list) ) ->
876+
| (Initialized istate, Rename (document, pos, new_name, document_list)) ->
879877
let (istate, ctx, entry, _errors) = update_file_ctx istate document in
880878
let (istate, result) =
881879
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
882880
match
883881
ServerFindRefs.go_from_file_ctx_with_symbol_definition
884882
~ctx
885883
~entry
886-
~line
887-
~column
884+
pos
888885
with
889886
| None -> (istate, ClientIdeMessage.Not_renameable_position)
890887
| Some (_definition, action) when ServerFindRefs.is_local action ->
@@ -945,14 +942,13 @@ let handle_request
945942
in
946943
(Initialized istate, Ok result)
947944
(* textDocument/references - localvar only *)
948-
| ( Initialized istate,
949-
Find_references (document, { line; column }, document_list) ) ->
945+
| (Initialized istate, Find_references (document, pos, document_list)) ->
950946
let open Result.Monad_infix in
951947
(* Update the state of the world with the document as it exists in the IDE *)
952948
let (istate, ctx, entry, _) = update_file_ctx istate document in
953949
let (istate, result) =
954950
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
955-
match ServerFindRefs.go_from_file_ctx ~ctx ~entry ~line ~column with
951+
match ServerFindRefs.go_from_file_ctx ~ctx ~entry pos with
956952
| Some (name, action) when ServerFindRefs.is_local action ->
957953
let result =
958954
ServerFindRefs.go_for_localvar ctx action
@@ -1091,9 +1087,7 @@ let handle_request
10911087
(Initialized istate, Ok result)
10921088
(* Autocomplete *)
10931089
| ( Initialized istate,
1094-
Completion
1095-
(document, { line; column }, { ClientIdeMessage.is_manually_invoked })
1096-
) ->
1090+
Completion (document, pos, { ClientIdeMessage.is_manually_invoked }) ) ->
10971091
(* Update the state of the world with the document as it exists in the IDE *)
10981092
let (istate, ctx, entry, _) = update_file_ctx istate document in
10991093
let sienv_ref = ref istate.sienv in
@@ -1103,8 +1097,7 @@ let handle_request
11031097
~entry
11041098
~sienv_ref
11051099
~is_manually_invoked
1106-
~line
1107-
~column
1100+
pos
11081101
~naming_table:istate.naming_table
11091102
in
11101103
let istate = { istate with sienv = !sienv_ref } in
@@ -1119,8 +1112,7 @@ let handle_request
11191112
(Initialized istate, Ok Completion_resolve.{ docblock = result; signature })
11201113
(* Autocomplete docblock resolve *)
11211114
| ( Initialized istate,
1122-
Completion_resolve_location (file_path, fullname, { line; column }, kind)
1123-
) ->
1115+
Completion_resolve_location (file_path, fullname, pos, kind) ) ->
11241116
(* We're given a location but it often won't be an opened file.
11251117
We will only serve autocomplete docblocks as of truth on disk.
11261118
Hence, we construct temporary entry to reflect the file which
@@ -1133,38 +1125,35 @@ let handle_request
11331125
let (ctx, entry) = Provider_context.add_entry_if_missing ~ctx ~path in
11341126
let result =
11351127
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
1136-
ServerDocblockAt.go_docblock_ctx ~ctx ~entry ~line ~column ~kind)
1128+
ServerDocblockAt.go_docblock_ctx ~ctx ~entry pos ~kind)
11371129
in
11381130
let (Full_name s) = fullname in
11391131
let signature = ServerAutoComplete.get_signature ctx s in
11401132
(Initialized istate, Ok Completion_resolve.{ docblock = result; signature })
11411133
(* Document highlighting *)
1142-
| (Initialized istate, Document_highlight (document, { line; column })) ->
1134+
| (Initialized istate, Document_highlight (document, pos)) ->
11431135
let (istate, ctx, entry, _) = update_file_ctx istate document in
11441136
let results =
11451137
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
1146-
Ide_highlight_refs.go_quarantined ~ctx ~entry ~line ~column)
1138+
Ide_highlight_refs.go_quarantined ~ctx ~entry pos)
11471139
in
11481140
(Initialized istate, Ok results)
11491141
(* Signature help *)
1150-
| (Initialized istate, Signature_help (document, { line; column })) ->
1142+
| (Initialized istate, Signature_help (document, pos)) ->
11511143
let (istate, ctx, entry, _) = update_file_ctx istate document in
11521144
let results =
11531145
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
1154-
ServerSignatureHelp.go_quarantined ~ctx ~entry ~line ~column)
1146+
ServerSignatureHelp.go_quarantined ~ctx ~entry pos)
11551147
in
11561148
(Initialized istate, Ok results)
1157-
| (Initialized istate, Top_level_def_name_at_pos (document, { line; column }))
1158-
->
1149+
| (Initialized istate, Top_level_def_name_at_pos (document, pos)) ->
11591150
let (istate, ctx, entry, _) = update_file_ctx istate document in
1160-
let res =
1161-
Ide_top_level_def_name_at_pos.go_quarantined ctx entry ~line ~column
1162-
in
1151+
let res = Ide_top_level_def_name_at_pos.go_quarantined ctx entry pos in
11631152
(Initialized istate, Ok res)
11641153
(* AutoClose *)
1165-
| (Initialized istate, AutoClose (document, { line; column })) ->
1154+
| (Initialized istate, AutoClose (document, pos)) ->
11661155
let (istate, ctx, entry, _) = update_file_ctx istate document in
1167-
let close_tag = AutocloseTags.go_xhp_close_tag ~ctx ~entry ~line ~column in
1156+
let close_tag = AutocloseTags.go_xhp_close_tag ~ctx ~entry pos in
11681157
(Initialized istate, Ok close_tag)
11691158
(* Code actions (refactorings, quickfixes) *)
11701159
| (Initialized istate, Code_action (document, range)) ->
@@ -1233,19 +1222,19 @@ let handle_request
12331222
in
12341223
(Initialized istate, Ok result)
12351224
(* Go to definition *)
1236-
| (Initialized istate, Definition (document, { line; column })) ->
1225+
| (Initialized istate, Definition (document, pos)) ->
12371226
let (istate, ctx, entry, _) = update_file_ctx istate document in
12381227
let result =
12391228
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
1240-
ServerGoToDefinition.go_quarantined ~ctx ~entry ~line ~column)
1229+
ServerGoToDefinition.go_quarantined ~ctx ~entry pos)
12411230
in
12421231
(Initialized istate, Ok result)
12431232
(* Type Definition *)
1244-
| (Initialized istate, Type_definition (document, { line; column })) ->
1233+
| (Initialized istate, Type_definition (document, pos)) ->
12451234
let (istate, ctx, entry, _) = update_file_ctx istate document in
12461235
let result =
12471236
Provider_utils.respect_but_quarantine_unsaved_changes ~ctx ~f:(fun () ->
1248-
ServerTypeDefinition.go_quarantined ~ctx ~entry ~line ~column)
1237+
ServerTypeDefinition.go_quarantined ~ctx ~entry pos)
12491238
in
12501239
(Initialized istate, Ok result)
12511240
(* Workspace Symbol *)

hphp/hack/src/client/ide_service/clientIdeMessage.ml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ type document = {
4242
file_contents: string;
4343
}
4444

45-
type location = {
46-
line: int;
47-
column: int;
48-
}
49-
5045
type fullname = Full_name of string
5146

5247
type find_refs_result =
@@ -127,16 +122,16 @@ type _ t =
127122
| Diagnostics : document -> diagnostic list t
128123
(** Obtains latest diagnostics for file. *)
129124
| Verbose_to_file : bool -> unit t
130-
| Hover : document * location -> HoverService.result t
125+
| Hover : document * File_content.Position.t -> HoverService.result t
131126
| Definition :
132-
document * location
127+
document * File_content.Position.t
133128
-> ServerCommandTypes.Go_to_definition.result t
134129
| Completion :
135-
document * location * completion_request
130+
document * File_content.Position.t * completion_request
136131
-> AutocompleteTypes.ide_result t
137132
(** Handles "textDocument/completion" LSP messages *)
138133
| Completion_resolve_location :
139-
Path.t * fullname * location * FileInfo.si_kind
134+
Path.t * fullname * File_content.Position.t * FileInfo.si_kind
140135
-> Completion_resolve.result t
141136
(** "completionItem/resolve" LSP messages - if we have file/line/column.
142137
The scenario is that VSCode requests textDocument/completion in A.PHP line 5 col 6,
@@ -148,16 +143,22 @@ type _ t =
148143
Completion_resolve.request
149144
-> Completion_resolve.result t
150145
(** "completionItem/resolve" LSP messages - if we have symbol name, and [Completion_resolve_location] failed *)
151-
| Document_highlight : document * location -> Ide_api_types.range list t
146+
| Document_highlight :
147+
document * File_content.Position.t
148+
-> Ide_api_types.range list t
152149
(** Handles "textDocument/documentHighlight" LSP messages *)
153150
| Document_symbol : document -> FileOutline.outline t
154151
(** Handles "textDocument/documentSymbol" LSP messages *)
155152
| Workspace_symbol : string -> SearchUtils.result t
156153
| Go_to_implementation :
157-
document * location * document list
154+
document * File_content.Position.t * document list
158155
-> go_to_impl_result t
159-
| Find_references : document * location * document list -> find_refs_result t
160-
| Rename : document * location * string * document list -> rename_result t
156+
| Find_references :
157+
document * File_content.Position.t * document list
158+
-> find_refs_result t
159+
| Rename :
160+
document * File_content.Position.t * string * document list
161+
-> rename_result t
161162
(** The result of Rename is one of:
162163
- Not_renameable_position, indicating an attempt to rename something that isn't a valid symbol
163164
- Rename_success, where we return a record containing two fields:
@@ -167,13 +168,15 @@ type _ t =
167168
in the input document list
168169
*)
169170
| Type_definition :
170-
document * location
171+
document * File_content.Position.t
171172
-> ServerCommandTypes.Go_to_type_definition.result t
172173
(** Handles "textDocument/typeDefinition" LSP messages *)
173-
| Signature_help : document * location -> Lsp.SignatureHelp.result t
174+
| Signature_help :
175+
document * File_content.Position.t
176+
-> Lsp.SignatureHelp.result t
174177
(** Handles "textDocument/signatureHelp" LSP messages *)
175178
| Top_level_def_name_at_pos :
176-
document * location
179+
document * File_content.Position.t
177180
-> Lsp.TopLevelDefNameAtPos.result t
178181
| Code_action :
179182
document * Ide_api_types.range
@@ -205,7 +208,7 @@ type _ t =
205208
use_snippet_edits: bool;
206209
}
207210
-> Lsp.CodeActionResolve.result t
208-
| AutoClose : document * location -> string option t
211+
| AutoClose : document * File_content.Position.t -> string option t
209212

210213
let t_to_string : type a. a t -> string = function
211214
| Initialize_from_saved_state _ -> "Initialize_from_saved_state"

hphp/hack/src/client/ide_service/dune

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@
3333
(library
3434
(name client_ide_message)
3535
(wrapped false)
36-
(modules clientIdeMessage)
37-
(libraries lwt_utils server_command_types server_services sys_utils)
36+
(modules
37+
clientIdeMessage)
38+
(libraries
39+
file_content
40+
lwt_utils
41+
server_command_types
42+
server_services sys_utils)
3843
(preprocess
3944
(pps lwt_ppx ppx_deriving.std)))
4045

0 commit comments

Comments
 (0)