Skip to content

Commit bc5e9d0

Browse files
committed
refactor topLoc
1 parent d6866d8 commit bc5e9d0

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

analysis/src/Commands.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ let references ~path ~line ~col =
130130
let loc =
131131
match locOpt with
132132
| Some loc -> loc
133-
| None -> Utils.topLoc (Uri2.toPath uri2)
133+
| None -> Uri2.toTopLevelLoc uri2
134134
in
135135
Protocol.stringifyLocation
136136
{uri = Uri2.toString uri2; range = Utils.cmtLocToRange loc}

analysis/src/References.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ let resolveModuleDefinition ~(file : File.t) ~package stamp =
279279
| Some (file, declared) ->
280280
let loc =
281281
match declared with
282-
| None -> Utils.topLoc (Uri2.toPath file.uri)
282+
| None -> Uri2.toTopLevelLoc file.uri
283283
| Some declared -> validateLoc declared.name.loc declared.extentLoc
284284
in
285285
Some (file.uri, loc))
@@ -332,7 +332,7 @@ let definitionForLocItem ~full:{file; package} locItem =
332332
| None -> None
333333
| Some paths ->
334334
let uri = getUri paths in
335-
Some (uri, Utils.topLoc (Uri2.toPath uri)))
335+
Some (uri, Uri2.toTopLevelLoc uri))
336336
| LModule (LocalReference (stamp, tip))
337337
| Typed (_, _, LocalReference (stamp, tip)) ->
338338
maybeLog ("Local defn " ^ tipToString tip);

analysis/src/Uri2.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module Uri : sig
1010
val toPath : t -> string
1111

1212
val toString : t -> string
13+
14+
val toTopLevelLoc : t -> Location.t
1315
end = struct
1416
type t = {path : string; uri : string}
1517

@@ -30,6 +32,12 @@ end = struct
3032

3133
let toPath {path} = path
3234

35+
let toTopLevelLoc {path} =
36+
let topPos =
37+
{Lexing.pos_fname = path; pos_lnum = 1; pos_bol = 0; pos_cnum = 0}
38+
in
39+
{Location.loc_start = topPos; Location.loc_end = topPos; loc_ghost = false}
40+
3341
let toString {uri} = if !stripPath then Filename.basename uri else uri
3442
end
3543

analysis/src/Utils.ml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
let topLoc fname =
2-
{
3-
Location.loc_start =
4-
{Lexing.pos_fname = fname; pos_lnum = 1; pos_bol = 0; pos_cnum = 0};
5-
Location.loc_end =
6-
{Lexing.pos_fname = fname; pos_lnum = 1; pos_bol = 0; pos_cnum = 0};
7-
loc_ghost = false;
8-
}
9-
101
(**
112
* `startsWith(string, prefix)`
123
* true if the string starts with the prefix

0 commit comments

Comments
 (0)