Skip to content

Commit 181bd1f

Browse files
committed
Refactor references command.
1 parent f935ce5 commit 181bd1f

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

analysis/src/Commands.ml

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ let hover ~path ~line ~col =
8585
| None -> Protocol.null
8686
| Some s -> Protocol.stringifyHover {contents = s}))
8787
in
88-
8988
print_endline result
9089

9190
let definition ~path ~line ~col =
@@ -126,37 +125,36 @@ let definition ~path ~line ~col =
126125

127126
print_endline result
128127

129-
let references ~file ~line ~col ~extra ~package =
130-
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
131-
match References.locItemForPos ~extra pos with
132-
| None -> Protocol.null
133-
| Some locItem ->
134-
let allReferences =
135-
References.allReferencesForLocItem ~package ~file ~extra locItem
136-
in
137-
let allLocs =
138-
allReferences
139-
|> List.fold_left
140-
(fun acc (uri2, references) ->
141-
(references
142-
|> List.map (fun loc ->
143-
Protocol.stringifyLocation
144-
{
145-
uri = Uri2.toString uri2;
146-
range = Utils.cmtLocToRange loc;
147-
}))
148-
@ acc)
149-
[]
150-
in
151-
"[\n" ^ (allLocs |> String.concat ",\n") ^ "\n]"
152-
153128
let references ~path ~line ~col =
154129
let uri = Uri2.fromLocalPath path in
155130
let result =
156131
match ProcessCmt.getFullFromCmt ~uri with
157132
| Error _message -> Protocol.null
158-
| Ok (package, {file; extra}) -> references ~file ~line ~col ~extra ~package
133+
| Ok (package, {file; extra}) -> (
134+
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
135+
match References.locItemForPos ~extra pos with
136+
| None -> Protocol.null
137+
| Some locItem ->
138+
let allReferences =
139+
References.allReferencesForLocItem ~package ~file ~extra locItem
140+
in
141+
let allLocs =
142+
allReferences
143+
|> List.fold_left
144+
(fun acc (uri2, references) ->
145+
(references
146+
|> List.map (fun loc ->
147+
Protocol.stringifyLocation
148+
{
149+
uri = Uri2.toString uri2;
150+
range = Utils.cmtLocToRange loc;
151+
}))
152+
@ acc)
153+
[]
154+
in
155+
"[\n" ^ (allLocs |> String.concat ",\n") ^ "\n]")
159156
in
157+
160158
print_endline result
161159

162160
let documentSymbol ~path =

0 commit comments

Comments
 (0)