@@ -128,15 +128,6 @@ let definition state ~file ~line ~col ~extra ~package =
128128 match References. locForPos ~extra: {extra with locations} pos with
129129 | None -> Protocol. null
130130 | Some (_ , loc ) -> (
131- let zzzTODO =
132- References. allReferencesForLoc ~paths ForModule:package.pathsForModule
133- ~file ~extra ~all Modules:package.localModules
134- ~get Uri:(State. fileForUri state)
135- ~get Module:(State. fileForModule state ~package )
136- ~get Extra:(State. extraForModule state ~package )
137- loc
138- in
139-
140131 let locIsModule =
141132 match loc with
142133 | SharedTypes. LModule _ | TopLevelModule _ -> true
@@ -175,6 +166,53 @@ let definition ~path ~line ~col =
175166 in
176167 print_endline result
177168
169+ let references state ~file ~line ~col ~extra ~package =
170+ let open TopTypes in
171+ let locations =
172+ extra.SharedTypes. locations
173+ |> List. filter (fun (l , _ ) -> not l.Location. loc_ghost)
174+ in
175+ let pos = Utils. protocolLineColToCmtLoc ~line ~col in
176+
177+ match References. locForPos ~extra: {extra with locations} pos with
178+ | None -> Protocol. null
179+ | Some (_ , loc ) ->
180+ let allReferences =
181+ References. allReferencesForLoc ~paths ForModule:package.pathsForModule
182+ ~file ~extra ~all Modules:package.localModules
183+ ~get Uri:(State. fileForUri state)
184+ ~get Module:(State. fileForModule state ~package )
185+ ~get Extra:(State. extraForModule state ~package )
186+ loc
187+ in
188+ let allLocs =
189+ allReferences
190+ |> List. fold_left
191+ (fun acc (uri2 , references ) ->
192+ (references
193+ |> List. map (fun loc ->
194+ Protocol. stringifyLocation
195+ {
196+ uri = Uri2. toString uri2;
197+ range = Utils. cmtLocToRange loc;
198+ }))
199+ @ acc)
200+ []
201+ in
202+ " [\n " ^ (allLocs |> String. concat " ,\n " ) ^ " ]"
203+
204+ let references ~path ~line ~col =
205+ let state = TopTypes. empty () in
206+ let filePath = Files. maybeConcat (Unix. getcwd () ) path in
207+ let uri = Uri2. fromPath filePath in
208+ let result =
209+ match State. getFullFromCmt ~state ~uri with
210+ | Error _message -> Protocol. null
211+ | Ok (package , {file; extra} ) ->
212+ references state ~file ~line ~col ~extra ~package
213+ in
214+ print_endline result
215+
178216let test ~path =
179217 Uri2. stripPath := true ;
180218 match Files. readFile path with
@@ -202,6 +240,11 @@ let test ~path =
202240 ^ string_of_int col);
203241
204242 hover ~path ~line ~col
243+ | "ref" ->
244+ print_endline
245+ (" References " ^ path ^ " " ^ string_of_int line ^ " :"
246+ ^ string_of_int col);
247+ references ~path ~line ~col
205248 | "com" ->
206249 print_endline
207250 (" Complete " ^ path ^ " " ^ string_of_int line ^ " :"
0 commit comments