Skip to content

Commit 867f2cd

Browse files
committed
Refactor: include name in Typed locType.
1 parent eaed44b commit 867f2cd

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

analysis/src/Hover.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let newHover ~full:{SharedTypes.file; package} locItem =
101101
| Some file ->
102102
showModule ~docstring:file.contents.docstring ~name:file.moduleName ~file
103103
None)
104-
| Typed (_, Definition (_, (Field _ | Constructor _))) -> None
104+
| Typed (_, _, Definition (_, (Field _ | Constructor _))) -> None
105105
| Constant t ->
106106
Some
107107
(codeBlock
@@ -113,7 +113,7 @@ let newHover ~full:{SharedTypes.file; package} locItem =
113113
| Const_int32 _ -> "int32"
114114
| Const_int64 _ -> "int64"
115115
| Const_nativeint _ -> "int"))
116-
| Typed (t, locKind) ->
116+
| Typed (_, t, locKind) ->
117117
let fromType ~docstring typ =
118118
let typeString = codeBlock (typ |> Shared.typeToString) in
119119
let extraTypeInfo =

analysis/src/ProcessCmt.ml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ let extraForFile ~(file : File.t) =
568568
addReference stamp d.name.loc);
569569
file.stamps.values
570570
|> Hashtbl.iter (fun stamp d ->
571-
addLocItem extra d.name.loc (Typed (d.item, Definition (stamp, Value)));
571+
addLocItem extra d.name.loc
572+
(Typed (d.name.txt, d.item, Definition (stamp, Value)));
572573
addReference stamp d.name.loc);
573574
file.stamps.types
574575
|> Hashtbl.iter (fun stamp d ->
@@ -581,7 +582,8 @@ let extraForFile ~(file : File.t) =
581582
|> List.iter (fun {stamp; fname; typ} ->
582583
addReference stamp fname.loc;
583584
addLocItem extra fname.loc
584-
(Typed (typ, Definition (d.stamp, Field fname.txt))))
585+
(Typed
586+
(d.name.txt, typ, Definition (d.stamp, Field fname.txt))))
585587
| Variant constructos ->
586588
constructos
587589
|> List.iter (fun {stamp; cname} ->
@@ -599,7 +601,10 @@ let extraForFile ~(file : File.t) =
599601
}
600602
in
601603
addLocItem extra cname.loc
602-
(Typed (t, Definition (d.stamp, Constructor cname.txt))))
604+
(Typed
605+
( d.name.txt,
606+
t,
607+
Definition (d.stamp, Constructor cname.txt) )))
603608
| _ -> ());
604609
extra
605610

@@ -757,7 +762,7 @@ struct
757762
| None -> NotFound)
758763
| `GlobalMod _ -> NotFound
759764
in
760-
addLocItem extra loc (Typed (typ, locType))
765+
addLocItem extra loc (Typed (identName, typ, locType))
761766

762767
let addForPathParent path loc =
763768
let locType =
@@ -834,7 +839,7 @@ struct
834839
GlobalReference (moduleName, path, Field name)
835840
| _ -> NotFound
836841
in
837-
addLocItem extra nameLoc (Typed (lbl_res, locType))
842+
addLocItem extra nameLoc (Typed (name, lbl_res, locType))
838843
| _ -> ()
839844

840845
let addForRecord recordType items =
@@ -862,13 +867,12 @@ struct
862867
GlobalReference (moduleName, path, Field name)
863868
| _ -> NotFound
864869
in
865-
addLocItem extra nameLoc (Typed (lbl_res, locType)))
870+
addLocItem extra nameLoc (Typed (name, lbl_res, locType)))
866871
| _ -> ()
867872

868873
let addForConstructor constructorType {Asttypes.txt; loc} {Types.cstr_name} =
869874
match (Shared.dig constructorType).desc with
870875
| Tconstr (path, _args, _memo) ->
871-
(* let name = Longident.last(txt); *)
872876
let name, typeLident = handleConstructor path txt in
873877
maybeAddUse path typeLident loc (Constructor name);
874878
let nameLoc = Utils.endOfLocation loc (String.length name) in
@@ -888,7 +892,7 @@ struct
888892
GlobalReference (moduleName, path, Constructor name)
889893
| _ -> NotFound
890894
in
891-
addLocItem extra nameLoc (Typed (constructorType, locType))
895+
addLocItem extra nameLoc (Typed (name, constructorType, locType))
892896
| _ -> ()
893897

894898
let currentScopeExtent () =
@@ -999,7 +1003,7 @@ struct
9991003
Hashtbl.add Collector.file.stamps.values stamp declared;
10001004
addReference stamp name.loc;
10011005
addLocItem extra name.loc
1002-
(Typed (val_desc.ctyp_type, Definition (stamp, Value))))
1006+
(Typed (name.txt, val_desc.ctyp_type, Definition (stamp, Value))))
10031007
| _ -> ()
10041008

10051009
let enter_core_type {ctyp_type; ctyp_desc} =
@@ -1024,7 +1028,8 @@ struct
10241028
in
10251029
Hashtbl.add Collector.file.stamps.values stamp declared;
10261030
addReference stamp name.loc;
1027-
addLocItem extra name.loc (Typed (pat_type, Definition (stamp, Value))))
1031+
addLocItem extra name.loc
1032+
(Typed (name.txt, pat_type, Definition (stamp, Value))))
10281033
in
10291034
(* Log.log("Entering pattern " ++ Utils.showLocation(pat_loc)); *)
10301035
match pat_desc with

analysis/src/References.ml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ let locItemForPos ~full pos =
2727
| _ :: _ :: _ :: l :: _ when full.file.uri |> Uri2.isInterface ->
2828
(* heuristic for makeProps in interface files *)
2929
Some l
30-
| [({locType = Typed (_, LocalReference _)} as li1); li3]
30+
| [({locType = Typed (_, _, LocalReference _)} as li1); li3]
3131
when li1.loc = li3.loc ->
3232
(* JSX and compiler combined:
3333
~x becomes Props#x
3434
heuristic for: [Props, x], give loc of `x` *)
3535
Some li3
3636
| [
37-
({locType = Typed (_, LocalReference _)} as li1);
38-
({locType = Typed (_, GlobalReference ("Js_OO", Tip "unsafe_downgrade", _))}
39-
as li2);
37+
({locType = Typed (_, _, LocalReference _)} as li1);
38+
({
39+
locType =
40+
Typed (_, _, GlobalReference ("Js_OO", Tip "unsafe_downgrade", _));
41+
} as li2);
4042
li3;
4143
]
4244
(* For older compiler 9.0 or earlier *)
@@ -46,8 +48,8 @@ let locItemForPos ~full pos =
4648
heuristic for: [Props, unsafe_downgrade, x], give loc of `x` *)
4749
Some li3
4850
| [
49-
{locType = Typed (_, LocalReference (_, Value))};
50-
({locType = Typed (_, Definition (_, Value))} as li2);
51+
{locType = Typed (_, _, LocalReference (_, Value))};
52+
({locType = Typed (_, _, Definition (_, Value))} as li2);
5153
] ->
5254
(* JSX on type-annotated labeled (~arg:t):
5355
(~arg:t) becomes Props#arg
@@ -297,7 +299,7 @@ let orLog message v =
297299

298300
let definitionForLocItem ~full:{file; package} locItem =
299301
match locItem.locType with
300-
| Typed (_, Definition (stamp, tip)) -> (
302+
| Typed (_, _, Definition (stamp, tip)) -> (
301303
maybeLog "Trying to find a defintion for a definition";
302304
match declaredForTip ~stamps:file.stamps stamp tip with
303305
| None -> None
@@ -311,7 +313,7 @@ let definitionForLocItem ~full:{file; package} locItem =
311313
let loc = validateLoc declared.name.loc declared.extentLoc in
312314
Some (file.uri, loc))
313315
else None)
314-
| Typed (_, NotFound)
316+
| Typed (_, _, NotFound)
315317
| LModule (NotFound | Definition (_, _))
316318
| TypeDefinition (_, _, _)
317319
| Constant _ ->
@@ -326,11 +328,11 @@ let definitionForLocItem ~full:{file; package} locItem =
326328
| None -> None
327329
| Some src -> Some (Uri2.fromPath src, Utils.topLoc src))
328330
| LModule (LocalReference (stamp, tip))
329-
| Typed (_, LocalReference (stamp, tip)) ->
331+
| Typed (_, _, LocalReference (stamp, tip)) ->
330332
maybeLog ("Local defn " ^ tipToString tip);
331333
definition ~file ~package stamp tip
332334
| LModule (GlobalReference (moduleName, path, tip))
333-
| Typed (_, GlobalReference (moduleName, path, tip)) -> (
335+
| Typed (_, _, GlobalReference (moduleName, path, tip)) -> (
334336
maybeLog
335337
("Global defn " ^ moduleName ^ " " ^ pathToString path ^ " : "
336338
^ tipToString tip);
@@ -450,16 +452,17 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
450452

451453
let allReferencesForLocItem ~full:({file; package} as full) locItem =
452454
match locItem.locType with
453-
| Typed (_, NotFound) | LModule NotFound | TopLevelModule _ | Constant _ -> []
455+
| Typed (_, _, NotFound) | LModule NotFound | TopLevelModule _ | Constant _ ->
456+
[]
454457
| TypeDefinition (_, _, stamp) -> forLocalStamp ~full stamp Type
455-
| Typed (_, (LocalReference (stamp, tip) | Definition (stamp, tip)))
458+
| Typed (_, _, (LocalReference (stamp, tip) | Definition (stamp, tip)))
456459
| LModule (LocalReference (stamp, tip) | Definition (stamp, tip)) ->
457460
maybeLog
458461
("Finding references for " ^ Uri2.toString file.uri ^ " and stamp "
459462
^ string_of_int stamp ^ " and tip " ^ tipToString tip);
460463
forLocalStamp ~full stamp tip
461464
| LModule (GlobalReference (moduleName, path, tip))
462-
| Typed (_, GlobalReference (moduleName, path, tip)) -> (
465+
| Typed (_, _, GlobalReference (moduleName, path, tip)) -> (
463466
match ProcessCmt.fileForModule ~package moduleName with
464467
| None -> []
465468
| Some file -> (

analysis/src/SharedTypes.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ type locKind =
175175
| Definition of int * tip
176176

177177
type locType =
178-
| Typed of Types.type_expr * locKind
178+
| Typed of string * Types.type_expr * locKind
179179
| Constant of Asttypes.constant
180180
| LModule of locKind
181181
| TopLevelModule of string
@@ -245,8 +245,8 @@ let locKindToString = function
245245
| Definition (_, tip) -> "(Definition " ^ tipToString tip ^ ")"
246246

247247
let locTypeToString = function
248-
| Typed (e, locKind) ->
249-
"Typed " ^ Shared.typeToString e ^ " " ^ locKindToString locKind
248+
| Typed (name, e, locKind) ->
249+
"Typed " ^ name ^ " " ^ Shared.typeToString e ^ " " ^ locKindToString locKind
250250
| Constant _ -> "Constant"
251251
| LModule locKind -> "LModule " ^ locKindToString locKind
252252
| TopLevelModule _ -> "TopLevelModule"

0 commit comments

Comments
 (0)