Skip to content

Commit 619f038

Browse files
committed
see how to hook it up
1 parent 2cd2d3f commit 619f038

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

analysis/src/Commands.ml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ let hover state ~file ~line ~col ~extra ~package =
103103
in
104104
match hoverText with
105105
| None -> Protocol.null
106-
| Some s -> Protocol.stringifyHover {contents = s} )
106+
| Some s -> Protocol.stringifyHover {contents = s})
107107

108108
let hover ~path ~line ~col =
109109
let state = TopTypes.empty () in
@@ -124,9 +124,19 @@ let definition state ~file ~line ~col ~extra ~package =
124124
|> List.filter (fun (l, _) -> not l.Location.loc_ghost)
125125
in
126126
let pos = Utils.protocolLineColToCmtLoc ~line ~col in
127+
127128
match References.locForPos ~extra:{extra with locations} pos with
128129
| None -> Protocol.null
129130
| Some (_, loc) -> (
131+
let zzzTODO =
132+
References.allReferencesForLoc ~pathsForModule:package.pathsForModule
133+
~file ~extra ~allModules:package.localModules
134+
~getUri:(State.fileForUri state)
135+
~getModule:(State.fileForModule state ~package)
136+
~getExtra:(State.extraForModule state ~package)
137+
loc
138+
in
139+
130140
let locIsModule =
131141
match loc with
132142
| SharedTypes.LModule _ | TopLevelModule _ -> true
@@ -151,7 +161,7 @@ let definition state ~file ~line ~col ~extra ~package =
151161
if skipZero then Protocol.null
152162
else
153163
Protocol.stringifyLocation
154-
{uri = Uri2.toString uri2; range = Utils.cmtLocToRange loc} )
164+
{uri = Uri2.toString uri2; range = Utils.cmtLocToRange loc})
155165

156166
let definition ~path ~line ~col =
157167
let state = TopTypes.empty () in
@@ -180,22 +190,22 @@ let test ~path =
180190
let line = i - 1 in
181191
let col = mlen - 1 in
182192
if mlen >= 3 then (
183-
( match String.sub rest 0 3 with
193+
(match String.sub rest 0 3 with
184194
| "def" ->
185195
print_endline
186-
( "Definition " ^ path ^ " " ^ string_of_int line ^ ":"
187-
^ string_of_int col );
196+
("Definition " ^ path ^ " " ^ string_of_int line ^ ":"
197+
^ string_of_int col);
188198
definition ~path ~line ~col
189199
| "hov" ->
190200
print_endline
191-
( "Hover " ^ path ^ " " ^ string_of_int line ^ ":"
192-
^ string_of_int col );
201+
("Hover " ^ path ^ " " ^ string_of_int line ^ ":"
202+
^ string_of_int col);
193203

194204
hover ~path ~line ~col
195205
| "com" ->
196206
print_endline
197-
( "Complete " ^ path ^ " " ^ string_of_int line ^ ":"
198-
^ string_of_int col );
207+
("Complete " ^ path ^ " " ^ string_of_int line ^ ":"
208+
^ string_of_int col);
199209
let currentFile, cout = Filename.open_temp_file "def" "txt" in
200210
lines
201211
|> List.iteri (fun j l ->
@@ -208,7 +218,7 @@ let test ~path =
208218
close_out cout;
209219
complete ~path ~line ~col ~currentFile;
210220
Sys.remove currentFile
211-
| _ -> () );
212-
print_newline () )
221+
| _ -> ());
222+
print_newline ())
213223
in
214224
lines |> List.iteri processLine

analysis/src/References.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ let forLocalStamp ~pathsForModule ~file ~extra ~allModules ~getModule ~getUri
384384
| None -> None
385385
| Some file -> (
386386
match getExtra name with
387-
| Error _ -> None
388-
| Ok extra -> (
387+
| None -> None
388+
| Some extra -> (
389389
match
390390
Hashtbl.find_opt extra.externalReferences
391391
thisModuleName
@@ -409,7 +409,7 @@ let forLocalStamp ~pathsForModule ~file ~extra ~allModules ~getModule ~getUri
409409
Some ((file.uri, local) :: externals))
410410

411411
let allReferencesForLoc ~pathsForModule ~getUri ~file ~extra ~allModules
412-
~getModule ~getExtra loc : _ option =
412+
~getModule ~getExtra loc =
413413
match loc with
414414
| Explanation _
415415
| Typed (_, NotFound)

analysis/src/State.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,14 @@ let fileForModule state ~package modname =
7575
match docsForModule modname state ~package with
7676
| None -> None
7777
| Some (file, _) -> Some file
78+
79+
let extraForModule state ~package modname =
80+
if Hashtbl.mem package.pathsForModule modname then
81+
let paths = Hashtbl.find package.pathsForModule modname in
82+
match SharedTypes.getSrc paths with
83+
| None -> None
84+
| Some src -> (
85+
match getFullFromCmt ~state ~uri:(Uri2.fromPath src) with
86+
| Ok (_package, {extra}) -> Some extra
87+
| Error _ -> None)
88+
else None

0 commit comments

Comments
 (0)