Skip to content

Commit 9033bcb

Browse files
committed
Refactor declared.
1 parent f79be5a commit 9033bcb

9 files changed

+92
-89
lines changed

analysis/src/Cmt.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let fromUri ~uri =
1010
in
1111
match Hashtbl.find_opt package.pathsForModule moduleName with
1212
| Some paths ->
13-
let cmt = SharedTypes.getCmtPath ~uri paths in
13+
let cmt = getCmtPath ~uri paths in
1414
ProcessCmt.fullForCmt ~moduleName ~package ~uri cmt
1515
| None ->
1616
prerr_endline ("can't find module " ^ moduleName);
@@ -19,7 +19,7 @@ let fromUri ~uri =
1919
let fromModule ~package modname =
2020
if Hashtbl.mem package.pathsForModule modname then
2121
let paths = Hashtbl.find package.pathsForModule modname in
22-
let uri = SharedTypes.getUri paths in
22+
let uri = getUri paths in
2323
fromUri ~uri
2424
else None
2525

analysis/src/Commands.ml

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
open SharedTypes
2+
13
let dumpLocations ~full =
2-
full.SharedTypes.extra.locItems
4+
full.extra.locItems
35
|> List.map (fun locItem ->
4-
let locItemTxt = SharedTypes.locItemToString locItem in
6+
let locItemTxt = locItemToString locItem in
57
let hoverText = Hover.newHover ~full locItem in
68
let hover =
79
match hoverText with None -> "" | Some s -> String.escaped s
@@ -60,7 +62,7 @@ let hover ~path ~line ~col =
6062
| Some locItem -> (
6163
let isModule =
6264
match locItem.locType with
63-
| SharedTypes.LModule _ | TopLevelModule _ -> true
65+
| LModule _ | TopLevelModule _ -> true
6466
| TypeDefinition _ | Typed _ | Constant _ -> false
6567
in
6668
let uriLocOpt = References.definitionForLocItem ~full locItem in
@@ -102,7 +104,7 @@ let definition ~path ~line ~col =
102104
in
103105
let isModule =
104106
match locItem.locType with
105-
| SharedTypes.LModule _ | TopLevelModule _ -> true
107+
| LModule _ | TopLevelModule _ -> true
106108
| TypeDefinition _ | Typed _ | Constant _ -> false
107109
in
108110
let skipLoc =
@@ -176,13 +178,13 @@ let documentSymbol ~path =
176178
let open SharedTypes in
177179
let rec getItems {ModuleKind.topLevel} =
178180
let rec getItem = function
179-
| ModuleKind.Value v -> (v |> SharedTypes.variableKind, [])
180-
| Type (t, _) -> (t.decl |> SharedTypes.declarationKind, [])
181+
| ModuleKind.Value v -> (v |> variableKind, [])
182+
| Type (t, _) -> (t.decl |> declarationKind, [])
181183
| Module (Structure contents) -> (Module, getItems contents)
182184
| Module (Constraint (_, modTypeItem)) -> getItem (Module modTypeItem)
183185
| Module (Ident _) -> (Module, [])
184186
in
185-
let fn {name = {txt}; extentLoc; item} =
187+
let fn {Declared.name = {txt}; extentLoc; item} =
186188
let item, siblings = getItem item in
187189
if extentLoc.loc_ghost then siblings
188190
else (txt, extentLoc, item) :: siblings
@@ -201,7 +203,7 @@ let documentSymbol ~path =
201203
uri = Uri2.toString (Uri2.fromPath path);
202204
range = Utils.cmtLocToRange loc;
203205
};
204-
kind = SharedTypes.symbolKind kind;
206+
kind = symbolKind kind;
205207
})
206208
in
207209
"[\n" ^ (allSymbols |> String.concat ",\n") ^ "\n]"

analysis/src/Hover.ml

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
open SharedTypes
2+
13
let codeBlock code = Printf.sprintf "```rescript\n%s\n```" code
24

35
let showModuleTopLevel ~docstring ~name
4-
(topLevel : SharedTypes.ModuleKind.moduleItem SharedTypes.declared list) =
6+
(topLevel : ModuleKind.moduleItem Declared.t list) =
57
let contents =
68
topLevel
79
|> List.map (fun item ->
8-
match item.SharedTypes.item with
10+
match item.Declared.item with
911
(* TODO pretty print module contents *)
10-
| SharedTypes.ModuleKind.Type ({decl}, recStatus) ->
12+
| ModuleKind.Type ({decl}, recStatus) ->
1113
" " ^ (decl |> Shared.declToString ~recStatus item.name.txt)
1214
| Module _ -> " module " ^ item.name.txt
1315
| Value typ ->
@@ -23,8 +25,8 @@ let showModuleTopLevel ~docstring ~name
2325
in
2426
Some (doc ^ full)
2527

26-
let rec showModule ~docstring ~(file : SharedTypes.File.t) ~name
27-
(declared : SharedTypes.ModuleKind.t SharedTypes.declared option) =
28+
let rec showModule ~docstring ~(file : File.t) ~name
29+
(declared : ModuleKind.t Declared.t option) =
2830
match declared with
2931
| None -> showModuleTopLevel ~docstring ~name file.contents.topLevel
3032
| Some {item = Structure {topLevel}} ->
@@ -36,9 +38,9 @@ let rec showModule ~docstring ~(file : SharedTypes.File.t) ~name
3638
| Some {item = Ident path} ->
3739
Some ("Unable to resolve module reference " ^ Path.name path)
3840

39-
let newHover ~full:{SharedTypes.file; package} locItem =
40-
match locItem.SharedTypes.locType with
41-
| SharedTypes.TypeDefinition (name, decl, _stamp) ->
41+
let newHover ~full:{file; package} locItem =
42+
match locItem.locType with
43+
| TypeDefinition (name, decl, _stamp) ->
4244
let typeDef = Shared.declToString name decl in
4345
Some (codeBlock typeDef)
4446
| LModule (Definition (stamp, _tip)) | LModule (LocalReference (stamp, _tip))
@@ -59,7 +61,7 @@ let newHover ~full:{SharedTypes.file; package} locItem =
5961
match ProcessCmt.fileForModule ~package moduleName with
6062
| None -> None
6163
| Some file -> (
62-
let env = SharedTypes.QueryEnv.fromFile file in
64+
let env = QueryEnv.fromFile file in
6365
match ProcessCmt.resolvePath ~env ~path ~package with
6466
| None -> None
6567
| Some (env, name) -> (
@@ -101,7 +103,7 @@ let newHover ~full:{SharedTypes.file; package} locItem =
101103
let fromType ~docstring typ =
102104
let typeString = codeBlock (typ |> Shared.typeToString) in
103105
let extraTypeInfo =
104-
let env = SharedTypes.QueryEnv.fromFile file in
106+
let env = QueryEnv.fromFile file in
105107
match typ |> Shared.digConstructor with
106108
| None -> None
107109
| Some path -> (

analysis/src/NewCompletions.ml

+20-21
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ let resolveOpens ~env ~previous opens ~package =
499499
let completionForDeclareds ~pos declareds prefix transformContents =
500500
(* Log.log("completion for declares " ++ prefix); *)
501501
Hashtbl.fold
502-
(fun _stamp declared results ->
502+
(fun _stamp (declared : _ Declared.t) results ->
503503
if
504504
Utils.startsWith declared.name.txt prefix
505505
&& Utils.locationContainsFuzzy declared.scopeLoc pos
@@ -522,8 +522,8 @@ let completionForDeclaredTypes ~pos ~env ~suffix =
522522
Kind.Type m)
523523

524524
let completionForExporteds exporteds
525-
(stamps : (int, 'a SharedTypes.declared) Hashtbl.t) prefix transformContents
526-
=
525+
(stamps : (int, _ Declared.t) Hashtbl.t) prefix
526+
transformContents =
527527
Hashtbl.fold
528528
(fun name stamp results ->
529529
(* Log.log("checking exported: " ++ name); *)
@@ -550,7 +550,7 @@ let completionForConstructors ~(env : QueryEnv.t) ~suffix =
550550
(fun _name stamp results ->
551551
let t = Hashtbl.find env.file.stamps.types stamp in
552552
match t.item.kind with
553-
| SharedTypes.Type.Variant constructors ->
553+
| Type.Variant constructors ->
554554
(constructors
555555
|> List.filter (fun c ->
556556
Utils.startsWith c.Constructor.cname.txt suffix)
@@ -560,7 +560,7 @@ let completionForConstructors ~(env : QueryEnv.t) ~suffix =
560560
env.exported.types []
561561
|> List.map (fun (c, t) ->
562562
{
563-
(emptyDeclared c.Constructor.cname.txt) with
563+
(Declared.empty c.Constructor.cname.txt) with
564564
item = Kind.Constructor (c, t);
565565
})
566566

@@ -577,7 +577,7 @@ let completionForFields ~(env : QueryEnv.t) ~suffix =
577577
| _ -> results)
578578
env.exported.types []
579579
|> List.map (fun (f, t) ->
580-
{(emptyDeclared f.fname.txt) with item = Kind.Field (f, t)})
580+
{(Declared.empty f.fname.txt) with item = Kind.Field (f, t)})
581581

582582
let isCapitalized name =
583583
if name = "" then false
@@ -799,7 +799,7 @@ let getItems ~full ~rawOpens ~allFiles ~pos ~dotpath =
799799
(fun results env ->
800800
let completionsFromThisOpen = valueCompletions ~env suffix in
801801
List.filter
802-
(fun (declared, _env) ->
802+
(fun ((declared : Kind.t Declared.t), _env) ->
803803
if Hashtbl.mem alreadyUsedIdentifiers declared.name.txt then
804804
false
805805
else (
@@ -816,7 +816,7 @@ let getItems ~full ~rawOpens ~allFiles ~pos ~dotpath =
816816
if Utils.startsWith name suffix && not (String.contains name '-')
817817
then
818818
Some
819-
({(emptyDeclared name) with item = Kind.FileModule name}, env)
819+
({(Declared.empty name) with item = Kind.FileModule name}, env)
820820
else None)
821821
in
822822
locallyDefinedValues @ valuesFromOpens @ localModuleNames
@@ -833,7 +833,7 @@ let getItems ~full ~rawOpens ~allFiles ~pos ~dotpath =
833833
| RecordAccess (valuePath, middleFields, lastField) -> (
834834
Log.log ("lastField :" ^ lastField);
835835
Log.log
836-
("-------------- Looking for " ^ (valuePath |> SharedTypes.pathToString));
836+
("-------------- Looking for " ^ (valuePath |> pathToString));
837837
match getEnvWithOpens ~pos ~env ~package ~opens valuePath with
838838
| Some (env, name) -> (
839839
match ProcessCmt.findInScope pos name env.file.stamps.values with
@@ -866,7 +866,7 @@ let getItems ~full ~rawOpens ~allFiles ~pos ~dotpath =
866866
if Utils.startsWith field.fname.txt lastField then
867867
Some
868868
( {
869-
(emptyDeclared field.fname.txt) with
869+
(Declared.empty field.fname.txt) with
870870
item = Kind.Field (field, typ);
871871
},
872872
env )
@@ -922,7 +922,7 @@ let processCompletable ~processDotPath ~full ~package ~rawOpens
922922
let declareds = processDotPath ~exact:true (componentPath @ ["make"]) in
923923
let labels =
924924
match declareds with
925-
| ({SharedTypes.item = Kind.Value typ}, _env) :: _ ->
925+
| ({Declared.item = Kind.Value typ}, _env) :: _ ->
926926
let rec getFields (texp : Types.type_expr) =
927927
match texp.desc with
928928
| Tfield (name, _, t1, t2) ->
@@ -982,8 +982,7 @@ let processCompletable ~processDotPath ~full ~package ~rawOpens
982982
(* TODO(#107): figure out why we're getting duplicates. *)
983983
declareds |> Utils.dedup
984984
|> List.map
985-
(fun
986-
({SharedTypes.name = {txt = name}; deprecated; docstring; item}, _env)
985+
(fun ({Declared.name = {txt = name}; deprecated; docstring; item}, _env)
987986
->
988987
mkItem ~name ~kind:(Kind.toInt item) ~deprecated
989988
~detail:(detail name item) ~docstring)
@@ -1028,7 +1027,7 @@ let processCompletable ~processDotPath ~full ~package ~rawOpens
10281027
match
10291028
fields
10301029
|> List.find_opt (fun field ->
1031-
field.SharedTypes.fname.txt = fieldName)
1030+
field.fname.txt = fieldName)
10321031
with
10331032
| None -> None
10341033
| Some field -> Some (field.typ, env1))
@@ -1044,7 +1043,7 @@ let processCompletable ~processDotPath ~full ~package ~rawOpens
10441043
match String.split_on_char '.' pipeId with
10451044
| x :: fieldNames -> (
10461045
match [x] |> processDotPath ~exact:true with
1047-
| ({SharedTypes.item = Value typ}, env) :: _ -> (
1046+
| ({Declared.item = Value typ}, env) :: _ -> (
10481047
match getFields ~env ~typ fieldNames with
10491048
| None -> None
10501049
| Some (typ1, _env1) -> fromType typ1)
@@ -1095,11 +1094,11 @@ let processCompletable ~processDotPath ~full ~package ~rawOpens
10951094
let dotpath = modulePath @ [partialName] in
10961095
let declareds = dotpath |> processDotPath ~exact:false in
10971096
declareds
1098-
|> List.filter (fun ({item}, _env) ->
1097+
|> List.filter (fun ({Declared.item}, _env) ->
10991098
match item with Kind.Value _ -> true | _ -> false)
11001099
|> List.map
11011100
(fun
1102-
( {SharedTypes.name = {txt = name}; deprecated; docstring; item},
1101+
( {Declared.name = {txt = name}; deprecated; docstring; item},
11031102
_env )
11041103
->
11051104
mkItem ~name:(completionName name) ~kind:(Kind.toInt item)
@@ -1153,7 +1152,7 @@ let processCompletable ~processDotPath ~full ~package ~rawOpens
11531152
| Clabel (funPath, prefix, identsSeen) ->
11541153
let labels =
11551154
match funPath |> processDotPath ~exact:true with
1156-
| ({SharedTypes.item = Value typ}, _env) :: _ ->
1155+
| ({Declared.item = Value typ}, _env) :: _ ->
11571156
let rec getLabels (t : Types.type_expr) =
11581157
match t.desc with
11591158
| Tlink t1 | Tsubst t1 -> getLabels t1
@@ -1202,7 +1201,7 @@ let processCompletable ~processDotPath ~full ~package ~rawOpens
12021201
let env0 = QueryEnv.fromFile full.file in
12031202
let env, fields =
12041203
match lhs |> processDotPath ~exact:true with
1205-
| ({SharedTypes.item = Value typ}, env) :: _ -> getObjectFields ~env typ
1204+
| ({Declared.item = Value typ}, env) :: _ -> getObjectFields ~env typ
12061205
| _ -> (env0, [])
12071206
in
12081207
let labels = resolvePath ~env fields path in
@@ -1243,7 +1242,7 @@ let computeCompletions ~completable ~full ~pos ~rawOpens =
12431242
let rec prioritize decls =
12441243
match decls with
12451244
| (d1, e1) :: (d2, e2) :: rest ->
1246-
let pos2 = d2.extentLoc.loc_start |> Utils.tupleOfLexing in
1245+
let pos2 = d2.Declared.extentLoc.loc_start |> Utils.tupleOfLexing in
12471246
if pos2 >= pos then prioritize ((d1, e1) :: rest)
12481247
else
12491248
let pos1 = d1.extentLoc.loc_start |> Utils.tupleOfLexing in
@@ -1252,7 +1251,7 @@ let computeCompletions ~completable ~full ~pos ~rawOpens =
12521251
| [] | [_] -> decls
12531252
in
12541253
declareds
1255-
|> List.filter (fun ({SharedTypes.name = {txt}}, _env) -> txt = last)
1254+
|> List.filter (fun ({Declared.name = {txt}}, _env) -> txt = last)
12561255
|> prioritize
12571256
| _ -> declareds
12581257
in

analysis/src/Packages.ml

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
open Infix
2+
open SharedTypes
23

34
(* Creates the `pathsForModule` hashtbl, which maps a `moduleName` to it's `paths` (the ml/re, mli/rei, cmt, and cmti files) *)
45
let makePathsForModule ~projectFilesAndPaths ~dependenciesFilesAndPaths =
@@ -37,8 +38,7 @@ let newBsPackage ~rootPath =
3738
~sourceDirectories ~libBs
3839
in
3940
projectFilesAndPaths
40-
|> List.iter (fun (_name, paths) ->
41-
Log.log (SharedTypes.showPaths paths));
41+
|> List.iter (fun (_name, paths) -> Log.log (showPaths paths));
4242
let pathsForModule =
4343
makePathsForModule ~projectFilesAndPaths ~dependenciesFilesAndPaths
4444
in
@@ -75,13 +75,11 @@ let newBsPackage ~rootPath =
7575
in
7676
Log.log ("Opens from bsconfig: " ^ (opens |> String.concat " "));
7777
{
78-
SharedTypes.rootPath;
78+
rootPath;
7979
projectFiles =
80-
projectFilesAndPaths |> List.map fst
81-
|> SharedTypes.FileSet.of_list;
80+
projectFilesAndPaths |> List.map fst |> FileSet.of_list;
8281
dependenciesFiles =
83-
dependenciesFilesAndPaths |> List.map fst
84-
|> SharedTypes.FileSet.of_list;
82+
dependenciesFilesAndPaths |> List.map fst |> FileSet.of_list;
8583
pathsForModule;
8684
opens;
8785
namespace;

analysis/src/ProcessAttributes.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let rec findDeprecatedAttribute attributes =
3737
let newDeclared ~item ~scope ~extent ~name ~stamp ~modulePath isExported
3838
attributes =
3939
{
40-
name;
40+
Declared.name;
4141
stamp;
4242
extentLoc = extent;
4343
scopeLoc = scope;

analysis/src/ProcessCmt.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let addItem ~name ~extent ~stamp ~(env : Env.t) ~item attributes exported stamps
4040
Hashtbl.add stamps stamp declared;
4141
declared
4242

43-
let rec forTypeSignatureItem ~env ~(exported : SharedTypes.Exported.t)
43+
let rec forTypeSignatureItem ~env ~(exported : Exported.t)
4444
(item : Types.signature_item) =
4545
match item with
4646
| Sig_value (ident, {val_type; val_attributes; val_loc = loc}) ->
@@ -559,16 +559,16 @@ let extraForFile ~(file : File.t) =
559559
else []))
560560
in
561561
file.stamps.modules
562-
|> Hashtbl.iter (fun stamp d ->
562+
|> Hashtbl.iter (fun stamp (d : ModuleKind.t Declared.t) ->
563563
addLocItem extra d.name.loc (LModule (Definition (stamp, Module)));
564564
addReference stamp d.name.loc);
565565
file.stamps.values
566-
|> Hashtbl.iter (fun stamp d ->
566+
|> Hashtbl.iter (fun stamp (d : Types.type_expr Declared.t) ->
567567
addLocItem extra d.name.loc
568568
(Typed (d.name.txt, d.item, Definition (stamp, Value)));
569569
addReference stamp d.name.loc);
570570
file.stamps.types
571-
|> Hashtbl.iter (fun stamp d ->
571+
|> Hashtbl.iter (fun stamp (d : Type.t Declared.t) ->
572572
addLocItem extra d.name.loc
573573
(TypeDefinition (d.name.txt, d.item.Type.decl, stamp));
574574
addReference stamp d.name.loc;
@@ -1183,9 +1183,9 @@ let fileForModule modname ~package =
11831183
if Hashtbl.mem package.pathsForModule modname then (
11841184
let paths = Hashtbl.find package.pathsForModule modname in
11851185
(* TODO: do better *)
1186-
let uri = SharedTypes.getUri paths in
1187-
let cmt = SharedTypes.getCmtPath ~uri paths in
1188-
Log.log ("fileForModule " ^ SharedTypes.showPaths paths);
1186+
let uri = getUri paths in
1187+
let cmt = getCmtPath ~uri paths in
1188+
Log.log ("fileForModule " ^ showPaths paths);
11891189
match fileForCmt ~moduleName:modname ~cmt ~uri state with
11901190
| None -> None
11911191
| Some docs -> Some docs)
@@ -1217,7 +1217,7 @@ let locationIsBefore {Location.loc_start} pos = tupleOfLexing loc_start <= pos
12171217
let findInScope pos name stamps =
12181218
(* Log.log("Find " ++ name ++ " with " ++ string_of_int(Hashtbl.length(stamps)) ++ " stamps"); *)
12191219
Hashtbl.fold
1220-
(fun _stamp declared result ->
1220+
(fun _stamp (declared : _ Declared.t) result ->
12211221
if declared.name.txt = name then
12221222
(* Log.log("a stamp " ++ Utils.showLocation(declared.scopeLoc) ++ " " ++ string_of_int(l) ++ "," ++ string_of_int(c)); *)
12231223
if locationIsBefore declared.scopeLoc pos then

0 commit comments

Comments
 (0)