Skip to content

Commit 34eb499

Browse files
committed
Refactor: no need to pass getModule around.
1 parent f34394f commit 34eb499

File tree

3 files changed

+20
-41
lines changed

3 files changed

+20
-41
lines changed

analysis/src/Commands.ml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ let dumpLocations ~package ~file ~extra =
99
let hover =
1010
match hoverText with None -> "" | Some s -> String.escaped s
1111
in
12-
let uriLocOpt =
13-
References.definitionForLoc ~package ~file
14-
~getModule:(ProcessCmt.fileForModule ~package)
15-
loc
16-
in
12+
let uriLocOpt = References.definitionForLoc ~package ~file loc in
1713
let def =
1814
match uriLocOpt with
1915
| None -> Protocol.null
@@ -69,11 +65,7 @@ let hover ~file ~line ~col ~extra ~package =
6965
| SharedTypes.LModule _ | TopLevelModule _ -> true
7066
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
7167
in
72-
let uriLocOpt =
73-
References.definitionForLoc ~package ~file
74-
~getModule:(ProcessCmt.fileForModule ~package)
75-
loc
76-
in
68+
let uriLocOpt = References.definitionForLoc ~package ~file loc in
7769
let skipZero =
7870
match uriLocOpt with
7971
| None -> false
@@ -86,9 +78,7 @@ let hover ~file ~line ~col ~extra ~package =
8678
in
8779
if skipZero then Protocol.null
8880
else
89-
let hoverText =
90-
Hover.newHover ~file ~package loc
91-
in
81+
let hoverText = Hover.newHover ~file ~package loc in
9282
match hoverText with
9383
| None -> Protocol.null
9484
| Some s -> Protocol.stringifyHover {contents = s})
@@ -117,11 +107,7 @@ let definition ~file ~line ~col ~extra ~package =
117107
| SharedTypes.LModule _ | TopLevelModule _ -> true
118108
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
119109
in
120-
let uriLocOpt =
121-
References.definitionForLoc ~package ~file
122-
~getModule:(ProcessCmt.fileForModule ~package)
123-
loc
124-
in
110+
let uriLocOpt = References.definitionForLoc ~package ~file loc in
125111
match uriLocOpt with
126112
| None -> Protocol.null
127113
| Some (uri2, loc) ->
@@ -160,7 +146,6 @@ let references ~file ~line ~col ~extra ~package =
160146
let allReferences =
161147
References.allReferencesForLoc ~package ~file ~extra
162148
~allModules:package.localModules ~getUri:ProcessCmt.fileForUri
163-
~getModule:(ProcessCmt.fileForModule ~package)
164149
~getExtra:(ProcessCmt.extraForModule ~package)
165150
loc
166151
in

analysis/src/NewCompletions.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ let determineCompletion items =
139139
*)
140140
let getEnvWithOpens ~pos ~(env : ProcessCmt.queryEnv) ~package
141141
~(opens : ProcessCmt.queryEnv list) path =
142-
(* Query.resolvePath(~env, ~path, ~getModule) *)
143142
match ProcessCmt.resolveFromStamps ~env ~path ~package ~pos with
144143
| Some x -> Some x
145144
| None ->
@@ -288,20 +287,20 @@ let attributeCompletions ~(env : ProcessCmt.queryEnv) ~suffix =
288287
results |> List.map (fun x -> (env.file.uri, x))
289288

290289
(* TODO filter out things that are defined after the current position *)
291-
let resolveRawOpens ~env ~getModule ~rawOpens ~package =
290+
let resolveRawOpens ~env ~rawOpens ~package =
292291
(* TODO Stdlib instead of Pervasives *)
293292
let packageOpens = "Pervasives" :: package.TopTypes.opens in
294293
Log.log ("Package opens " ^ String.concat " " packageOpens);
295294
let opens =
296295
resolveOpens ~env
297296
~previous:
298297
(List.map ProcessCmt.fileEnv
299-
(packageOpens |> Utils.filterMap getModule))
298+
(packageOpens |> Utils.filterMap (ProcessCmt.fileForModule ~package)))
300299
rawOpens ~package
301300
in
302301
opens
303302

304-
let getItems ~full ~package ~rawOpens ~getModule ~allModules ~pos ~parts =
303+
let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
305304
Log.log
306305
("Opens folkz > "
307306
^ string_of_int (List.length rawOpens)
@@ -310,7 +309,7 @@ let getItems ~full ~package ~rawOpens ~getModule ~allModules ~pos ~parts =
310309
let env = ProcessCmt.fileEnv full.file in
311310
let packageOpens = "Pervasives" :: package.TopTypes.opens in
312311
Log.log ("Package opens " ^ String.concat " " packageOpens);
313-
let resolvedOpens = resolveRawOpens ~env ~getModule ~rawOpens ~package in
312+
let resolvedOpens = resolveRawOpens ~env ~rawOpens ~package in
314313
Log.log
315314
("Opens nows "
316315
^ string_of_int (List.length resolvedOpens)
@@ -681,9 +680,7 @@ let computeCompletions ~full ~maybeText ~package ~pos =
681680
in
682681
let findItems ~exact parts =
683682
let items =
684-
getItems ~full ~package ~rawOpens
685-
~getModule:(ProcessCmt.fileForModule ~package)
686-
~allModules ~pos ~parts
683+
getItems ~full ~package ~rawOpens ~allModules ~pos ~parts
687684
in
688685
match parts |> List.rev with
689686
| last :: _ when exact ->

analysis/src/References.ml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ let orLog message v =
292292
None
293293
| _ -> v
294294

295-
let definitionForLoc ~package ~file ~getModule loc =
295+
let definitionForLoc ~package ~file loc =
296296
match loc with
297297
| Typed (_, Definition (stamp, tip)) -> (
298298
maybeLog "Trying to find a defintion for a definition";
@@ -332,7 +332,7 @@ let definitionForLoc ~package ~file ~getModule loc =
332332
maybeLog
333333
("Global defn " ^ moduleName ^ " " ^ pathToString path ^ " : "
334334
^ tipToString tip);
335-
match getModule moduleName with
335+
match ProcessCmt.fileForModule ~package moduleName with
336336
| None -> None
337337
| Some file -> (
338338
let env = ProcessCmt.fileEnv file in
@@ -369,8 +369,7 @@ let rec pathFromVisibility visibilityPath current =
369369
let pathFromVisibility visibilityPath tipName =
370370
pathFromVisibility visibilityPath (Tip tipName)
371371

372-
let forLocalStamp ~package ~file ~extra ~allModules ~getModule ~getExtra stamp
373-
tip =
372+
let forLocalStamp ~package ~file ~extra ~allModules ~getExtra stamp tip =
374373
let env = ProcessCmt.fileEnv file in
375374
let open Infix in
376375
match
@@ -420,7 +419,7 @@ let forLocalStamp ~package ~file ~extra ~allModules ~getModule ~getExtra stamp
420419
allModules
421420
|> List.filter (fun name -> name <> file.moduleName)
422421
|> Utils.filterMap (fun name ->
423-
match getModule name with
422+
match ProcessCmt.fileForModule ~package name with
424423
| None -> None
425424
| Some file -> (
426425
match getExtra name with
@@ -448,27 +447,25 @@ let forLocalStamp ~package ~file ~extra ~allModules ~getModule ~getExtra stamp
448447
in
449448
(file.uri, local) :: externals)
450449

451-
let allReferencesForLoc ~package ~getUri ~file ~extra ~allModules ~getModule
452-
~getExtra loc =
450+
let allReferencesForLoc ~package ~getUri ~file ~extra ~allModules ~getExtra loc
451+
=
453452
match loc with
454453
| Explanation _
455454
| Typed (_, NotFound)
456455
| LModule NotFound
457456
| TopLevelModule _ | Constant _ ->
458457
[]
459458
| TypeDefinition (_, _, stamp) ->
460-
forLocalStamp ~package ~file ~extra ~allModules ~getModule ~getExtra stamp
461-
Type
459+
forLocalStamp ~package ~file ~extra ~allModules ~getExtra stamp Type
462460
| Typed (_, (LocalReference (stamp, tip) | Definition (stamp, tip)))
463461
| LModule (LocalReference (stamp, tip) | Definition (stamp, tip)) ->
464462
maybeLog
465463
("Finding references for " ^ Uri2.toString file.uri ^ " and stamp "
466464
^ string_of_int stamp ^ " and tip " ^ tipToString tip);
467-
forLocalStamp ~package ~file ~extra ~allModules ~getModule ~getExtra stamp
468-
tip
465+
forLocalStamp ~package ~file ~extra ~allModules ~getExtra stamp tip
469466
| LModule (GlobalReference (moduleName, path, tip))
470467
| Typed (_, GlobalReference (moduleName, path, tip)) -> (
471-
match getModule moduleName with
468+
match ProcessCmt.fileForModule ~package moduleName with
472469
| None -> []
473470
| Some file -> (
474471
let env = ProcessCmt.fileEnv file in
@@ -485,5 +482,5 @@ let allReferencesForLoc ~package ~getUri ~file ~extra ~allModules ~getModule
485482
("Finding references for (global) " ^ Uri2.toString env.file.uri
486483
^ " and stamp " ^ string_of_int stamp ^ " and tip "
487484
^ tipToString tip);
488-
forLocalStamp ~package ~file ~extra ~allModules ~getModule ~getExtra
489-
stamp tip))))
485+
forLocalStamp ~package ~file ~extra ~allModules ~getExtra stamp tip)
486+
)))

0 commit comments

Comments
 (0)