Skip to content

Commit eafc2f3

Browse files
committed
Refactor type file.
1 parent d8070a7 commit eafc2f3

File tree

4 files changed

+28
-26
lines changed

4 files changed

+28
-26
lines changed

analysis/src/Hover.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let showModuleTopLevel ~docstring ~name
3939
in
4040
Some (doc ^ full)
4141

42-
let rec showModule ~docstring ~(file : SharedTypes.file) ~name
42+
let rec showModule ~docstring ~(file : SharedTypes.File.t) ~name
4343
(declared : SharedTypes.moduleKind SharedTypes.declared option) =
4444
match declared with
4545
| None -> showModuleTopLevel ~docstring ~name file.contents.topLevel

analysis/src/ProcessCmt.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
489489
}
490490
in
491491
let contents = forStructure ~env items in
492-
{uri; moduleName = cmt_modname; stamps = env.stamps; contents}
492+
{File.uri; moduleName = cmt_modname; stamps = env.stamps; contents}
493493
| Partial_interface parts ->
494494
let items =
495495
parts |> Array.to_list
@@ -529,7 +529,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
529529
in
530530
let contents = forSignature ~env signature.sig_items in
531531
{uri; moduleName = cmt_modname; stamps = env.stamps; contents}
532-
| _ -> SharedTypes.emptyFile moduleName uri
532+
| _ -> File.create moduleName uri
533533

534534
let fileForCmt ~moduleName ~uri cmt =
535535
match Shared.tryReadCmt cmt with
@@ -540,7 +540,7 @@ let addLocItem extra loc locType =
540540
if not loc.Warnings.loc_ghost then
541541
extra.locItems <- {loc; locType} :: extra.locItems
542542

543-
let extraForFile ~(file : SharedTypes.file) =
543+
let extraForFile ~(file : File.t) =
544544
let extra = initExtra () in
545545
let addReference stamp loc =
546546
Hashtbl.replace extra.internalReferences stamp
@@ -672,7 +672,7 @@ let fromCompilerPath ~(env : QueryEnv.t) path =
672672
module F (Collector : sig
673673
val extra : extra
674674

675-
val file : file
675+
val file : File.t
676676

677677
val scopeExtent : Location.t list ref
678678
end) =
@@ -1071,7 +1071,7 @@ struct
10711071
| _ -> ()
10721072
end
10731073

1074-
let forItems ~(file : SharedTypes.file) items parts =
1074+
let forItems ~(file : File.t) items parts =
10751075
let extra = extraForFile ~file in
10761076
let extent = itemsExtent items in
10771077
let extent =

analysis/src/References.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ let declaredForTip ~stamps stamp tip =
7373
| Module ->
7474
Hashtbl.find_opt stamps.modules stamp |?>> fun x -> {x with item = ()}
7575

76-
let getField file stamp name =
76+
let getField (file : File.t) stamp name =
7777
match Hashtbl.find_opt file.stamps.types stamp with
7878
| None -> None
7979
| Some {item = {kind}} -> (
8080
match kind with
8181
| Record fields -> fields |> List.find_opt (fun f -> f.fname.txt = name)
8282
| _ -> None)
8383

84-
let getConstructor file stamp name =
84+
let getConstructor (file : File.t) stamp name =
8585
match Hashtbl.find_opt file.stamps.types stamp with
8686
| None -> None
8787
| Some {item = {kind}} -> (
@@ -158,7 +158,7 @@ let declaredForExportedTip ~(stamps : stamps) ~(exported : exported) name tip =
158158
Hashtbl.find_opt exported.modules name |?> fun stamp ->
159159
Hashtbl.find_opt stamps.modules stamp |?>> fun x -> {x with item = ()}
160160

161-
let alternateDeclared ~file ~package declared tip =
161+
let alternateDeclared ~(file : File.t) ~package declared tip =
162162
match Hashtbl.find_opt package.pathsForModule file.moduleName with
163163
| None -> None
164164
| Some paths -> (
@@ -241,7 +241,7 @@ let validateLoc (loc : Location.t) (backup : Location.t) =
241241
else backup
242242
else loc
243243

244-
let resolveModuleDefinition ~file ~package stamp =
244+
let resolveModuleDefinition ~(file : File.t) ~package stamp =
245245
match Hashtbl.find_opt file.stamps.modules stamp with
246246
| None -> None
247247
| Some md -> (

analysis/src/SharedTypes.ml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,25 @@ let initStamps () =
8888

8989
type env = {stamps : stamps; modulePath : visibilityPath; scope : Location.t}
9090

91-
type file = {
92-
uri : Uri2.t;
93-
stamps : stamps;
94-
moduleName : string;
95-
contents : moduleContents;
96-
}
97-
98-
let emptyFile moduleName uri =
99-
{
100-
uri;
101-
stamps = initStamps ();
102-
moduleName;
103-
contents = {docstring = []; exported = initExported (); topLevel = []};
91+
module File = struct
92+
type t = {
93+
uri : Uri2.t;
94+
stamps : stamps;
95+
moduleName : string;
96+
contents : moduleContents;
10497
}
10598

99+
let create moduleName uri =
100+
{
101+
uri;
102+
stamps = initStamps ();
103+
moduleName;
104+
contents = {docstring = []; exported = initExported (); topLevel = []};
105+
}
106+
end
107+
106108
module QueryEnv = struct
107-
type t = {file : file; exported : exported}
109+
type t = {file : File.t; exported : exported}
108110

109111
let fromFile file = {file; exported = file.contents.exported}
110112
end
@@ -213,7 +215,7 @@ type package = {
213215
opens : string list;
214216
}
215217

216-
type full = {extra : extra; file : file; package : package}
218+
type full = {extra : extra; file : File.t; package : package}
217219

218220
let initExtra () =
219221
{
@@ -226,7 +228,7 @@ let initExtra () =
226228
type state = {
227229
packagesByRoot : (string, package) Hashtbl.t;
228230
rootForUri : (Uri2.t, string) Hashtbl.t;
229-
cmtCache : (filePath, float * file) Hashtbl.t;
231+
cmtCache : (filePath, float * File.t) Hashtbl.t;
230232
}
231233

232234
(* There's only one state, so it can as well be global *)

0 commit comments

Comments
 (0)