Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 5e46a50

Browse files
committed
Format References.ml
1 parent 6284518 commit 5e46a50

File tree

1 file changed

+54
-61
lines changed

1 file changed

+54
-61
lines changed

src/References.ml

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -47,54 +47,54 @@ let definedForLoc ~file ~getModule locKind =
4747
| Constructor name -> (
4848
match Query.getConstructor file stamp name with
4949
| None -> None
50-
| Some constructor -> Some ([], `Constructor constructor) )
50+
| Some constructor -> Some ([], `Constructor constructor))
5151
| Field name -> (
5252
match Query.getField file stamp name with
5353
| None -> None
54-
| Some field -> Some ([], `Field field) )
54+
| Some field -> Some ([], `Field field))
5555
| _ -> (
5656
maybeLog
57-
( "Trying for declared " ^ tipToString tip ^ " " ^ string_of_int stamp
58-
^ " in file " ^ Uri2.toString file.uri );
57+
("Trying for declared " ^ tipToString tip ^ " " ^ string_of_int stamp
58+
^ " in file " ^ Uri2.toString file.uri);
5959
match Query.declaredForTip ~stamps:file.stamps stamp tip with
6060
| None -> None
61-
| Some declared -> Some (declared.docstring, `Declared) )
61+
| Some declared -> Some (declared.docstring, `Declared))
6262
in
6363
match locKind with
6464
| NotFound -> None
6565
| LocalReference (stamp, tip) | Definition (stamp, tip) ->
6666
inner ~file stamp tip
6767
| GlobalReference (moduleName, path, tip) ->
68-
( maybeLog ("Getting global " ^ moduleName);
69-
match
70-
getModule moduleName
71-
|> RResult.orError ("Cannot get module " ^ moduleName)
72-
with
73-
| Error e -> Error e
74-
| Ok file -> (
75-
let env = Query.fileEnv file in
76-
match
77-
Query.resolvePath ~env ~path ~getModule
78-
|> RResult.orError ("Cannot resolve path " ^ pathToString path)
79-
with
80-
| Error e -> Error e
81-
| Ok (env, name) -> (
82-
match
83-
Query.exportedForTip ~env name tip
84-
|> RResult.orError
85-
("Exported not found for tip " ^ name ^ " > " ^ tipToString tip)
86-
with
87-
| Error e -> Error e
88-
| Ok stamp -> (
89-
maybeLog ("Getting for " ^ string_of_int stamp ^ " in " ^ name);
90-
match
91-
inner ~file:env.file stamp tip
92-
|> RResult.orError "could not get defined"
93-
with
94-
| Error e -> Error e
95-
| Ok res ->
96-
maybeLog "Yes!! got it";
97-
Ok res ) ) ) )
68+
(maybeLog ("Getting global " ^ moduleName);
69+
match
70+
getModule moduleName
71+
|> RResult.orError ("Cannot get module " ^ moduleName)
72+
with
73+
| Error e -> Error e
74+
| Ok file -> (
75+
let env = Query.fileEnv file in
76+
match
77+
Query.resolvePath ~env ~path ~getModule
78+
|> RResult.orError ("Cannot resolve path " ^ pathToString path)
79+
with
80+
| Error e -> Error e
81+
| Ok (env, name) -> (
82+
match
83+
Query.exportedForTip ~env name tip
84+
|> RResult.orError
85+
("Exported not found for tip " ^ name ^ " > " ^ tipToString tip)
86+
with
87+
| Error e -> Error e
88+
| Ok stamp -> (
89+
maybeLog ("Getting for " ^ string_of_int stamp ^ " in " ^ name);
90+
match
91+
inner ~file:env.file stamp tip
92+
|> RResult.orError "could not get defined"
93+
with
94+
| Error e -> Error e
95+
| Ok res ->
96+
maybeLog "Yes!! got it";
97+
Ok res))))
9898
|> RResult.toOptionAndLog
9999

100100
let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
@@ -116,7 +116,7 @@ let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
116116
~exported:file.contents.exported declared.name.txt tip
117117
with
118118
| None -> None
119-
| Some declared -> Some (file, extra, declared) )
119+
| Some declared -> Some (file, extra, declared))
120120
else
121121
match getUri intfUri |> RResult.toOptionAndLog with
122122
| None -> None
@@ -126,8 +126,8 @@ let alternateDeclared ~file ~pathsForModule ~getUri declared tip =
126126
~exported:file.contents.exported declared.name.txt tip
127127
with
128128
| None -> None
129-
| Some declared -> Some (file, extra, declared) ) )
130-
| _ -> None )
129+
| Some declared -> Some (file, extra, declared)))
130+
| _ -> None)
131131

132132
let resolveModuleReference ~file ~getModule (declared : moduleKind declared) =
133133
match declared.item with
@@ -144,9 +144,7 @@ let resolveModuleReference ~file ~getModule (declared : moduleKind declared) =
144144
| None -> None
145145
| Some md ->
146146
Some (env.file, Some md)
147-
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *)
148-
)
149-
)
147+
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *)))
150148
| `Global (moduleName, path) -> (
151149
match getModule moduleName with
152150
| None -> None
@@ -163,25 +161,20 @@ let resolveModuleReference ~file ~getModule (declared : moduleKind declared) =
163161
| Some md ->
164162
Some (env.file, Some md)
165163
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *)
166-
)
167-
)
168-
)
169-
)
164+
))))
170165
| `Stamp stamp -> (
171166
match Hashtbl.find_opt file.stamps.modules stamp with
172167
| None -> None
173168
| Some md ->
174169
Some (file, Some md)
175-
(* Some((file.uri, validateLoc(md.name.loc, md.extentLoc))) *)
176-
)
170+
(* Some((file.uri, validateLoc(md.name.loc, md.extentLoc))) *))
177171
| `GlobalMod name -> (
178172
match getModule name with
179173
| None -> None
180174
| Some file ->
181175
(* maybeLog("Congrats, found a global mod"); *)
182-
Some (file, None)
183-
)
184-
| _ -> None )
176+
Some (file, None))
177+
| _ -> None)
185178

186179
let validateLoc (loc : Location.t) (backup : Location.t) =
187180
if loc.loc_start.pos_cnum = -1 then
@@ -206,18 +199,18 @@ let resolveModuleDefinition ~file ~getModule stamp =
206199
| None -> Utils.topLoc (Uri2.toPath file.uri)
207200
| Some declared -> validateLoc declared.name.loc declared.extentLoc
208201
in
209-
Some (file.uri, loc) )
202+
Some (file.uri, loc))
210203

211204
let definition ~file ~getModule stamp tip =
212205
match tip with
213206
| Constructor name -> (
214207
match Query.getConstructor file stamp name with
215208
| None -> None
216-
| Some constructor -> Some (file.uri, constructor.cname.loc) )
209+
| Some constructor -> Some (file.uri, constructor.cname.loc))
217210
| Field name -> (
218211
match Query.getField file stamp name with
219212
| None -> None
220-
| Some field -> Some (file.uri, field.fname.loc) )
213+
| Some field -> Some (file.uri, field.fname.loc))
221214
| Module -> resolveModuleDefinition ~file ~getModule stamp
222215
| _ -> (
223216
match Query.declaredForTip ~stamps:file.stamps stamp tip with
@@ -227,7 +220,7 @@ let definition ~file ~getModule stamp tip =
227220
let env = Query.fileEnv file in
228221
let uri = Query.getSourceUri ~env ~getModule declared.modulePath in
229222
maybeLog ("Inner uri " ^ Uri2.toString uri);
230-
Some (uri, loc) )
223+
Some (uri, loc))
231224

232225
let orLog message v =
233226
match v with
@@ -250,8 +243,8 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
250243
| None -> None
251244
| Some (file, _extra, declared) ->
252245
let loc = validateLoc declared.name.loc declared.extentLoc in
253-
Some (file.uri, loc) )
254-
else None )
246+
Some (file.uri, loc))
247+
else None)
255248
| Explanation _
256249
| Typed (_, NotFound)
257250
| LModule (NotFound | Definition (_, _))
@@ -266,16 +259,16 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
266259
|> orLog "No paths found" |?> getSrc |> orLog "No src found"
267260
with
268261
| None -> None
269-
| Some src -> Some (Uri2.fromPath src, Utils.topLoc src) )
262+
| Some src -> Some (Uri2.fromPath src, Utils.topLoc src))
270263
| LModule (LocalReference (stamp, tip))
271264
| Typed (_, LocalReference (stamp, tip)) ->
272265
maybeLog ("Local defn " ^ tipToString tip);
273266
definition ~file ~getModule stamp tip
274267
| LModule (GlobalReference (moduleName, path, tip))
275268
| Typed (_, GlobalReference (moduleName, path, tip)) -> (
276269
maybeLog
277-
( "Global defn " ^ moduleName ^ " " ^ pathToString path ^ " : "
278-
^ tipToString tip );
270+
("Global defn " ^ moduleName ^ " " ^ pathToString path ^ " : "
271+
^ tipToString tip);
279272
match getModule moduleName with
280273
| None -> None
281274
| Some file -> (
@@ -286,6 +279,6 @@ let definitionForLoc ~pathsForModule ~file ~getUri ~getModule loc =
286279
match Query.exportedForTip ~env name tip with
287280
| None -> None
288281
| Some stamp ->
289-
(** oooh wht do I do if the stamp is inside a pseudo-file? *)
282+
(* oooh wht do I do if the stamp is inside a pseudo-file? *)
290283
maybeLog ("Got stamp " ^ string_of_int stamp);
291-
definition ~file:env.file ~getModule stamp tip ) ) )
284+
definition ~file:env.file ~getModule stamp tip)))

0 commit comments

Comments
 (0)