Skip to content

Commit 9a6d319

Browse files
committed
Refactor: disambiguate type of quertEnv.
1 parent 11b8276 commit 9a6d319

File tree

4 files changed

+67
-65
lines changed

4 files changed

+67
-65
lines changed

analysis/src/Hover.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ let digConstructor ~env ~package path =
22
match ProcessCmt.resolveFromCompilerPath ~env ~package path with
33
| `Not_found -> None
44
| `Stamp stamp -> (
5-
match Hashtbl.find_opt env.file.stamps.types stamp with
5+
match Hashtbl.find_opt env.qFile.stamps.types stamp with
66
| None -> None
77
| Some t -> Some (env, t))
88
| `Exported (env, name) -> (
9-
match Hashtbl.find_opt env.exported.types name with
9+
match Hashtbl.find_opt env.qExported.types name with
1010
| None -> None
1111
| Some stamp -> (
12-
match Hashtbl.find_opt env.file.stamps.types stamp with
12+
match Hashtbl.find_opt env.qFile.stamps.types stamp with
1313
| None -> None
1414
| Some t -> Some (env, t)))
1515
| _ -> None

analysis/src/NewCompletions.ml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ let getEnvWithOpens ~pos ~(env : ProcessCmt.queryEnv) ~package
145145
let rec loop opens =
146146
match opens with
147147
| env :: rest -> (
148-
Log.log ("Looking for env in " ^ Uri2.toString env.ProcessCmt.file.uri);
148+
Log.log ("Looking for env in " ^ Uri2.toString env.ProcessCmt.qFile.uri);
149149
match ProcessCmt.resolvePath ~env ~package ~path with
150150
| Some x -> Some x
151151
| None -> loop rest)
@@ -201,9 +201,9 @@ let localValueCompletions ~pos ~(env : ProcessCmt.queryEnv) suffix =
201201
let results =
202202
if suffix = "" || isCapitalized suffix then
203203
results
204-
@ completionForDeclareds ~pos env.file.stamps.modules suffix (fun m ->
204+
@ completionForDeclareds ~pos env.qFile.stamps.modules suffix (fun m ->
205205
Module m)
206-
@ (completionForConstructors env.exported.types env.file.stamps.types
206+
@ (completionForConstructors env.qExported.types env.qFile.stamps.types
207207
(* TODO declared thingsz *)
208208
suffix
209209
|> List.map (fun (c, t) ->
@@ -213,35 +213,35 @@ let localValueCompletions ~pos ~(env : ProcessCmt.queryEnv) suffix =
213213
let results =
214214
if suffix = "" || not (isCapitalized suffix) then
215215
results
216-
@ completionForDeclareds ~pos env.file.stamps.values suffix (fun v ->
216+
@ completionForDeclareds ~pos env.qFile.stamps.values suffix (fun v ->
217217
Value v)
218-
@ completionForDeclareds ~pos env.file.stamps.types suffix (fun t ->
218+
@ completionForDeclareds ~pos env.qFile.stamps.types suffix (fun t ->
219219
Type t)
220-
@ (completionForFields env.exported.types env.file.stamps.types suffix
220+
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
221221
|> List.map (fun (f, t) ->
222222
{(emptyDeclared f.fname.txt) with item = Field (f, t)}))
223223
else results
224224
in
225-
results |> List.map (fun x -> (env.file.uri, x))
225+
results |> List.map (fun x -> (env.qFile.uri, x))
226226

227227
let valueCompletions ~(env : ProcessCmt.queryEnv) suffix =
228-
Log.log (" - Completing in " ^ Uri2.toString env.file.uri);
228+
Log.log (" - Completing in " ^ Uri2.toString env.qFile.uri);
229229
let results = [] in
230230
let results =
231231
if suffix = "" || isCapitalized suffix then (
232232
(* Get rid of lowercase modules (#417) *)
233-
env.exported.modules
233+
env.qExported.modules
234234
|> Hashtbl.filter_map_inplace (fun name key ->
235235
match isCapitalized name with true -> Some key | false -> None);
236236
let moduleCompletions =
237-
completionForExporteds env.exported.modules env.file.stamps.modules
237+
completionForExporteds env.qExported.modules env.qFile.stamps.modules
238238
suffix (fun m -> Module m)
239239
in
240240
(* Log.log(" -- capitalized " ++ string_of_int(Hashtbl.length(env.exported.types)) ++ " exported types"); *)
241241
(* env.exported.types |> Hashtbl.iter((name, _) => Log.log(" > " ++ name)); *)
242242
results @ moduleCompletions
243243
@ ((* TODO declared thingsz *)
244-
completionForConstructors env.exported.types env.file.stamps.types
244+
completionForConstructors env.qExported.types env.qFile.stamps.types
245245
suffix
246246
|> List.map (fun (c, t) ->
247247
{(emptyDeclared c.cname.txt) with item = Constructor (c, t)})))
@@ -251,40 +251,40 @@ let valueCompletions ~(env : ProcessCmt.queryEnv) suffix =
251251
if suffix = "" || not (isCapitalized suffix) then (
252252
Log.log " -- not capitalized";
253253
results
254-
@ completionForExporteds env.exported.values env.file.stamps.values suffix
255-
(fun v -> Value v)
256-
@ completionForExporteds env.exported.types env.file.stamps.types suffix
254+
@ completionForExporteds env.qExported.values env.qFile.stamps.values
255+
suffix (fun v -> Value v)
256+
@ completionForExporteds env.qExported.types env.qFile.stamps.types suffix
257257
(fun t -> Type t)
258-
@ (completionForFields env.exported.types env.file.stamps.types suffix
258+
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
259259
|> List.map (fun (f, t) ->
260260
{(emptyDeclared f.fname.txt) with item = Field (f, t)})))
261261
else results
262262
in
263263
(* Log.log("Getting value completions " ++ env.file.uri);
264264
Log.log(String.concat(", ", results |. Belt.List.map(x => x.name.txt))); *)
265-
results |> List.map (fun x -> (env.file.uri, x))
265+
results |> List.map (fun x -> (env.qFile.uri, x))
266266

267267
let attributeCompletions ~(env : ProcessCmt.queryEnv) ~suffix =
268268
let results = [] in
269269
let results =
270270
if suffix = "" || isCapitalized suffix then
271271
results
272-
@ completionForExporteds env.exported.modules env.file.stamps.modules
272+
@ completionForExporteds env.qExported.modules env.qFile.stamps.modules
273273
suffix (fun m -> Module m)
274274
else results
275275
in
276276
let results =
277277
if suffix = "" || not (isCapitalized suffix) then
278278
results
279-
@ completionForExporteds env.exported.values env.file.stamps.values suffix
280-
(fun v -> Value v)
279+
@ completionForExporteds env.qExported.values env.qFile.stamps.values
280+
suffix (fun v -> Value v)
281281
(* completionForExporteds(env.exported.types, env.file.stamps.types, suffix, t => Type(t)) @ *)
282-
@ (completionForFields env.exported.types env.file.stamps.types suffix
282+
@ (completionForFields env.qExported.types env.qFile.stamps.types suffix
283283
|> List.map (fun (f, t) ->
284284
{(emptyDeclared f.fname.txt) with item = Field (f, t)}))
285285
else results
286286
in
287-
results |> List.map (fun x -> (env.file.uri, x))
287+
results |> List.map (fun x -> (env.qFile.uri, x))
288288

289289
(* TODO filter out things that are defined after the current position *)
290290
let resolveRawOpens ~env ~rawOpens ~package =
@@ -316,7 +316,7 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
316316
^ " "
317317
^ String.concat " "
318318
(resolvedOpens
319-
|> List.map (fun e -> Uri2.toString e.ProcessCmt.file.uri)));
319+
|> List.map (fun e -> Uri2.toString e.ProcessCmt.qFile.uri)));
320320
(* Last open takes priority *)
321321
let opens = List.rev resolvedOpens in
322322
match parts with
@@ -349,7 +349,7 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
349349
with
350350
| true ->
351351
Some
352-
( env.file.uri,
352+
( env.qFile.uri,
353353
{(emptyDeclared name) with item = FileModule name} )
354354
| false -> None)
355355
in
@@ -370,7 +370,7 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
370370
| [] -> []
371371
| first :: rest -> (
372372
Log.log ("-------------- Looking for " ^ first);
373-
match ProcessCmt.findInScope pos first env.file.stamps.values with
373+
match ProcessCmt.findInScope pos first env.qFile.stamps.values with
374374
| None -> []
375375
| Some declared -> (
376376
Log.log ("Found it! " ^ declared.name.txt);
@@ -411,7 +411,7 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
411411
|> Utils.filterMap (fun f ->
412412
if Utils.startsWith f.fname.txt suffix then
413413
Some
414-
( env.file.uri,
414+
( env.qFile.uri,
415415
{
416416
(emptyDeclared f.fname.txt) with
417417
item = Field (f, typ);

analysis/src/ProcessCmt.ml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ open Typedtree
22
open SharedTypes
33
open Infix
44

5-
type queryEnv = {file : file; exported : exported}
5+
type queryEnv = {qFile : file; qExported : exported}
66

7-
let fileEnv file = {file; exported = file.contents.exported}
7+
let fileEnv file = {qFile = file; qExported = file.contents.exported}
88

99
let itemsExtent items =
1010
let open Typedtree in
@@ -618,21 +618,22 @@ let rec resolvePathInner ~env ~path =
618618
match path with
619619
| Tip name -> Some (`Local (env, name))
620620
| Nested (subName, subPath) -> (
621-
match Hashtbl.find_opt env.exported.modules subName with
621+
match Hashtbl.find_opt env.qExported.modules subName with
622622
| None -> None
623623
| Some stamp -> (
624-
match Hashtbl.find_opt env.file.stamps.modules stamp with
624+
match Hashtbl.find_opt env.qFile.stamps.modules stamp with
625625
| None -> None
626626
| Some {item = kind} -> findInModule ~env kind subPath))
627627

628628
and findInModule ~env kind path =
629629
match kind with
630-
| Structure {exported} -> resolvePathInner ~env:{env with exported} ~path
630+
| Structure {exported} ->
631+
resolvePathInner ~env:{env with qExported = exported} ~path
631632
| Ident modulePath -> (
632633
let stamp, moduleName, fullPath = joinPaths modulePath path in
633634
if stamp = 0 then Some (`Global (moduleName, fullPath))
634635
else
635-
match Hashtbl.find_opt env.file.stamps.modules stamp with
636+
match Hashtbl.find_opt env.qFile.stamps.modules stamp with
636637
| None -> None
637638
| Some {item = kind} -> findInModule ~env kind fullPath)
638639

@@ -643,7 +644,7 @@ let fromCompilerPath ~env path =
643644
| `GlobalMod name -> `GlobalMod name
644645
| `Path (stamp, _moduleName, path) -> (
645646
let res =
646-
match Hashtbl.find_opt env.file.stamps.modules stamp with
647+
match Hashtbl.find_opt env.qFile.stamps.modules stamp with
647648
| None -> None
648649
| Some {item = kind} -> findInModule ~env kind path
649650
in
@@ -720,8 +721,8 @@ struct
720721
match
721722
Hashtbl.find_opt
722723
(match tip = Type with
723-
| true -> env.exported.types
724-
| false -> env.exported.values)
724+
| true -> env.qExported.types
725+
| false -> env.qExported.values)
725726
name
726727
with
727728
| Some stamp ->
@@ -746,7 +747,7 @@ struct
746747
addExternalReference moduleName path Module loc;
747748
LModule (GlobalReference (moduleName, path, Module))
748749
| `Exported (env, name) -> (
749-
match Hashtbl.find_opt env.exported.modules name with
750+
match Hashtbl.find_opt env.qExported.modules name with
750751
| Some stamp ->
751752
addReference stamp loc;
752753
LModule (LocalReference (stamp, Module))
@@ -760,15 +761,15 @@ struct
760761
| `Global (moduleName, path) -> `Global (moduleName, path)
761762
| `Not_found -> `Not_found
762763
| `Exported (env, name) -> (
763-
match Hashtbl.find_opt env.exported.types name with
764+
match Hashtbl.find_opt env.qExported.types name with
764765
| None -> `Not_found
765766
| Some stamp -> (
766-
let declaredType = Hashtbl.find_opt env.file.stamps.types stamp in
767+
let declaredType = Hashtbl.find_opt env.qFile.stamps.types stamp in
767768
match declaredType with
768769
| Some declaredType -> `Local declaredType
769770
| None -> `Not_found))
770771
| `Stamp stamp -> (
771-
let declaredType = Hashtbl.find_opt env.file.stamps.types stamp in
772+
let declaredType = Hashtbl.find_opt env.qFile.stamps.types stamp in
772773
match declaredType with
773774
| Some declaredType -> `Local declaredType
774775
| None -> `Not_found)
@@ -1261,7 +1262,7 @@ let resolveFromStamps ~(env : queryEnv) ~path ~package ~pos =
12611262
| Tip name -> Some (env, name)
12621263
| Nested (name, inner) -> (
12631264
(* Log.log("Finding from stamps " ++ name); *)
1264-
match findInScope pos name env.file.stamps.modules with
1265+
match findInScope pos name env.qFile.stamps.modules with
12651266
| None -> None
12661267
| Some declared -> (
12671268
(* Log.log("found it"); *)
@@ -1286,14 +1287,14 @@ let resolveModuleFromCompilerPath ~env ~package path =
12861287
match resolvePath ~env ~package ~path with
12871288
| None -> None
12881289
| Some (env, name) -> (
1289-
match Hashtbl.find_opt env.exported.modules name with
1290+
match Hashtbl.find_opt env.qExported.modules name with
12901291
| None -> None
12911292
| Some stamp -> (
1292-
match Hashtbl.find_opt env.file.stamps.modules stamp with
1293+
match Hashtbl.find_opt env.qFile.stamps.modules stamp with
12931294
| None -> None
12941295
| Some declared -> Some (env, Some declared)))))
12951296
| `Stamp stamp -> (
1296-
match Hashtbl.find_opt env.file.stamps.modules stamp with
1297+
match Hashtbl.find_opt env.qFile.stamps.modules stamp with
12971298
| None -> None
12981299
| Some declared -> Some (env, Some declared))
12991300
| `GlobalMod moduleName -> (
@@ -1304,10 +1305,10 @@ let resolveModuleFromCompilerPath ~env ~package path =
13041305
Some (env, None))
13051306
| `Not_found -> None
13061307
| `Exported (env, name) -> (
1307-
match Hashtbl.find_opt env.exported.modules name with
1308+
match Hashtbl.find_opt env.qExported.modules name with
13081309
| None -> None
13091310
| Some stamp -> (
1310-
match Hashtbl.find_opt env.file.stamps.modules stamp with
1311+
match Hashtbl.find_opt env.qFile.stamps.modules stamp with
13111312
| None -> None
13121313
| Some declared -> Some (env, Some declared)))
13131314

@@ -1332,18 +1333,18 @@ let resolveFromCompilerPath ~env ~package path =
13321333
let rec getSourceUri ~(env : queryEnv) ~package path =
13331334
match path with
13341335
| File (uri, _moduleName) -> uri
1335-
| NotVisible -> env.file.uri
1336+
| NotVisible -> env.qFile.uri
13361337
| IncludedModule (path, inner) -> (
13371338
Log.log "INCLUDED MODULE";
13381339
match resolveModuleFromCompilerPath ~env ~package path with
13391340
| None ->
13401341
Log.log "NOT FOUND";
13411342
getSourceUri ~env ~package inner
1342-
| Some (env, _declared) -> env.file.uri)
1343+
| Some (env, _declared) -> env.qFile.uri)
13431344
| ExportedModule (_, inner) -> getSourceUri ~env ~package inner
13441345

13451346
let exportedForTip ~(env : queryEnv) name tip =
13461347
match tip with
1347-
| Value -> Hashtbl.find_opt env.exported.values name
1348-
| Field _ | Constructor _ | Type -> Hashtbl.find_opt env.exported.types name
1349-
| Module -> Hashtbl.find_opt env.exported.modules name
1348+
| Value -> Hashtbl.find_opt env.qExported.values name
1349+
| Field _ | Constructor _ | Type -> Hashtbl.find_opt env.qExported.types name
1350+
| Module -> Hashtbl.find_opt env.qExported.modules name

analysis/src/References.ml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ let definedForLoc ~file ~package locKind =
135135
None
136136
| Some stamp -> (
137137
maybeLog ("Getting for " ^ string_of_int stamp ^ " in " ^ name);
138-
match inner ~file:env.file stamp tip with
138+
match inner ~file:env.qFile stamp tip with
139139
| None ->
140140
Log.log "could not get defined";
141141
None
@@ -200,13 +200,13 @@ let resolveModuleReference ~file ~package (declared : moduleKind declared) =
200200
match ProcessCmt.fromCompilerPath ~env path with
201201
| `Not_found -> None
202202
| `Exported (env, name) -> (
203-
match Hashtbl.find_opt env.exported.modules name with
203+
match Hashtbl.find_opt env.qExported.modules name with
204204
| None -> None
205205
| Some stamp -> (
206-
match Hashtbl.find_opt env.file.stamps.modules stamp with
206+
match Hashtbl.find_opt env.qFile.stamps.modules stamp with
207207
| None -> None
208208
| Some md ->
209-
Some (env.file, Some md)
209+
Some (env.qFile, Some md)
210210
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *)))
211211
| `Global (moduleName, path) -> (
212212
match ProcessCmt.fileForModule ~package moduleName with
@@ -216,13 +216,13 @@ let resolveModuleReference ~file ~package (declared : moduleKind declared) =
216216
match ProcessCmt.resolvePath ~env ~package ~path with
217217
| None -> None
218218
| Some (env, name) -> (
219-
match Hashtbl.find_opt env.exported.modules name with
219+
match Hashtbl.find_opt env.qExported.modules name with
220220
| None -> None
221221
| Some stamp -> (
222-
match Hashtbl.find_opt env.file.stamps.modules stamp with
222+
match Hashtbl.find_opt env.qFile.stamps.modules stamp with
223223
| None -> None
224224
| Some md ->
225-
Some (env.file, Some md)
225+
Some (env.qFile, Some md)
226226
(* Some((env.file.uri, validateLoc(md.name.loc, md.extentLoc))) *)
227227
))))
228228
| `Stamp stamp -> (
@@ -344,7 +344,7 @@ let definitionForLoc ~package ~file loc =
344344
| Some stamp ->
345345
(* oooh wht do I do if the stamp is inside a pseudo-file? *)
346346
maybeLog ("Got stamp " ^ string_of_int stamp);
347-
definition ~file:env.file ~package stamp tip)))
347+
definition ~file:env.qFile ~package stamp tip)))
348348

349349
let isVisible (declared : _ SharedTypes.declared) =
350350
declared.exported
@@ -385,7 +385,7 @@ let forLocalStamp ~package ~file ~extra stamp tip =
385385
| Some local ->
386386
maybeLog ("Checking externals: " ^ string_of_int stamp);
387387
let externals =
388-
match declaredForTip ~stamps:env.file.stamps stamp tip with
388+
match declaredForTip ~stamps:env.qFile.stamps stamp tip with
389389
| None -> []
390390
| Some declared ->
391391
if isVisible declared then (
@@ -474,11 +474,12 @@ let allReferencesForLoc ~package ~file ~extra loc =
474474
match ProcessCmt.exportedForTip ~env name tip with
475475
| None -> []
476476
| Some stamp -> (
477-
match ProcessCmt.fileForUri env.file.uri with
477+
match ProcessCmt.fileForUri env.qFile.uri with
478478
| Error _ -> []
479479
| Ok (file, extra) ->
480480
maybeLog
481-
("Finding references for (global) " ^ Uri2.toString env.file.uri
482-
^ " and stamp " ^ string_of_int stamp ^ " and tip "
483-
^ tipToString tip);
481+
("Finding references for (global) "
482+
^ Uri2.toString env.qFile.uri
483+
^ " and stamp " ^ string_of_int stamp ^ " and tip "
484+
^ tipToString tip);
484485
forLocalStamp ~package ~file ~extra stamp tip))))

0 commit comments

Comments
 (0)