Skip to content

Commit c3a19db

Browse files
committed
Refactor away path.
1 parent 0375a22 commit c3a19db

File tree

6 files changed

+30
-36
lines changed

6 files changed

+30
-36
lines changed

analysis/.depend

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ src/Packages.cmx : \
6868
src/FindFiles.cmx \
6969
src/Files.cmx \
7070
src/BuildSystem.cmx
71-
src/PartialParser.cmx : \
72-
src/SharedTypes.cmx
71+
src/PartialParser.cmx :
7372
src/PrepareUtils.cmx :
7473
src/PrintType.cmx : \
7574
src/vendor/res_outcome_printer/res_outcome_printer.cmx \

analysis/src/NewCompletions.ml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ let resolveOpens ~env ~previous opens ~package =
465465
match prev with
466466
| [] -> (
467467
match path with
468-
| Tip _ -> previous
469-
| Nested (name, path) -> (
468+
| [] | [_] -> previous
469+
| name :: path -> (
470470
match ProcessCmt.fileForModule ~package name with
471471
| None ->
472472
Log.log ("Could not get module " ^ name);
@@ -556,22 +556,20 @@ let isCapitalized name =
556556
match c with 'A' .. 'Z' -> true | _ -> false
557557

558558
type completion =
559-
| AbsAttribute of path
559+
| AbsAttribute of string list
560560
| Attribute of string list * string
561-
| Normal of path
561+
| Normal of string list
562562

563563
let determineCompletion dotpath =
564564
let rec loop dotpath =
565565
match dotpath with
566566
| [] -> assert false
567-
| [one] -> Normal (Tip one)
567+
| [one] -> Normal [one]
568568
| [one; two] when not (isCapitalized one) -> Attribute ([one], two)
569-
| [one; two] -> Normal (Nested (one, Tip two))
569+
| [one; two] -> Normal [one; two]
570570
| one :: rest -> (
571571
if isCapitalized one then
572-
match loop rest with
573-
| Normal path -> Normal (Nested (one, path))
574-
| x -> x
572+
match loop rest with Normal path -> Normal (one :: path) | x -> x
575573
else
576574
match loop rest with
577575
| Normal path -> AbsAttribute path
@@ -600,8 +598,8 @@ let getEnvWithOpens ~pos ~(env : QueryEnv.t) ~package ~(opens : QueryEnv.t list)
600598
| None -> loop rest)
601599
| [] -> (
602600
match path with
603-
| Tip _ -> None
604-
| Nested (top, path) -> (
601+
| [] | [_] -> None
602+
| top :: path -> (
605603
Log.log ("Getting module " ^ top);
606604
match ProcessCmt.fileForModule ~package top with
607605
| None -> None
@@ -1050,8 +1048,8 @@ let processCompletable ~processDotPath ~full ~package ~rawOpens
10501048
in
10511049
let rec removeRawOpen rawOpen modulePath =
10521050
match (rawOpen, modulePath) with
1053-
| Tip _, _ -> Some modulePath
1054-
| Nested (s, inner), first :: restPath when s = first ->
1051+
| [_], _ -> Some modulePath
1052+
| s :: inner, first :: restPath when s = first ->
10551053
removeRawOpen inner restPath
10561054
| _ -> None
10571055
in

analysis/src/PartialParser.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ let findOpens text offset =
292292
let pathOfModuleOpen o =
293293
let rec loop items =
294294
match items with
295-
| [] -> SharedTypes.Tip "place holder"
296-
| one :: rest -> Nested (one, loop rest)
295+
| [] -> ["place holder"]
296+
| one :: rest -> one :: loop rest
297297
in
298298
loop (o |> Str.split (Str.regexp_string "."))
299299
in

analysis/src/ProcessCmt.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,19 +639,20 @@ let rec joinPaths modulePath path =
639639
match modulePath with
640640
| Path.Pident ident -> (ident.stamp, ident.name, path)
641641
| Papply (fnPath, _argPath) -> joinPaths fnPath path
642-
| Pdot (inner, name, _) -> joinPaths inner (Nested (name, path))
642+
| Pdot (inner, name, _) -> joinPaths inner (name :: path)
643643

644644
let rec makePath modulePath =
645645
match modulePath with
646646
| Path.Pident ident when ident.stamp == 0 -> `GlobalMod ident.name
647647
| Pident ident -> `Stamp ident.stamp
648648
| Papply (fnPath, _argPath) -> makePath fnPath
649-
| Pdot (inner, name, _) -> `Path (joinPaths inner (Tip name))
649+
| Pdot (inner, name, _) -> `Path (joinPaths inner [name])
650650

651651
let rec resolvePathInner ~(env : QueryEnv.t) ~path =
652652
match path with
653-
| Tip name -> Some (`Local (env, name))
654-
| Nested (subName, subPath) -> (
653+
| [] -> None
654+
| [name] -> Some (`Local (env, name))
655+
| subName :: subPath -> (
655656
match Hashtbl.find_opt env.exported.modules subName with
656657
| None -> None
657658
| Some stamp -> (
@@ -1313,8 +1314,9 @@ let findInScope pos name stamps =
13131314

13141315
let resolveFromStamps ~(env : QueryEnv.t) ~path ~package ~pos =
13151316
match path with
1316-
| Tip name -> Some (env, name)
1317-
| Nested (name, inner) -> (
1317+
| [] -> None
1318+
| [name] -> Some (env, name)
1319+
| name :: inner -> (
13181320
(* Log.log("Finding from stamps " ++ name); *)
13191321
match findInScope pos name env.file.stamps.modules with
13201322
| None -> None

analysis/src/References.ml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ let getLocItem ~full ~line ~col =
5656
Some li3
5757
| [
5858
({locType = Typed (_, _, LocalReference _)} as li1);
59-
({
60-
locType =
61-
Typed (_, _, GlobalReference ("Js_OO", Tip "unsafe_downgrade", _));
62-
} as li2);
59+
({locType = Typed (_, _, GlobalReference ("Js_OO", ["unsafe_downgrade"], _))}
60+
as li2);
6361
li3;
6462
]
6563
(* For older compiler 9.0 or earlier *)
@@ -409,12 +407,11 @@ let rec pathFromVisibility visibilityPath current =
409407
match visibilityPath with
410408
| File _ -> Some current
411409
| IncludedModule (_, inner) -> pathFromVisibility inner current
412-
| ExportedModule (name, inner) ->
413-
pathFromVisibility inner (Nested (name, current))
410+
| ExportedModule (name, inner) -> pathFromVisibility inner (name :: current)
414411
| NotVisible -> None
415412

416413
let pathFromVisibility visibilityPath tipName =
417-
pathFromVisibility visibilityPath (Tip tipName)
414+
pathFromVisibility visibilityPath [tipName]
418415

419416
type references = {
420417
uri : Uri2.t;

analysis/src/SharedTypes.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,11 @@ let tipToString tip =
179179

180180
type path = Tip of string | Nested of string * path
181181

182-
let rec pathToString path =
183-
match path with
184-
| Tip name -> name
185-
| Nested (name, inner) -> name ^ "." ^ pathToString inner
182+
let pathToString path = path |> String.concat "."
186183

187184
type locKind =
188185
| LocalReference of int * tip
189-
| GlobalReference of string * path * tip
186+
| GlobalReference of string * string list * tip
190187
| NotFound
191188
| Definition of int * tip
192189

@@ -216,7 +213,8 @@ end)
216213

217214
type extra = {
218215
internalReferences : (int, Location.t list) Hashtbl.t;
219-
externalReferences : (string, (path * tip * Location.t) list) Hashtbl.t;
216+
externalReferences :
217+
(string, (string list * tip * Location.t) list) Hashtbl.t;
220218
fileReferences : (string, LocationSet.t) Hashtbl.t;
221219
mutable locItems : locItem list;
222220
(* This is the "open location", like the location...

0 commit comments

Comments
 (0)