Skip to content

Commit 0375a22

Browse files
committed
refactor completion type
1 parent 7a8c72a commit 0375a22

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

analysis/src/NewCompletions.ml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -555,25 +555,30 @@ let isCapitalized name =
555555
let c = name.[0] in
556556
match c with 'A' .. 'Z' -> true | _ -> false
557557

558-
let determineCompletion parts =
559-
let rec loop parts =
560-
match parts with
558+
type completion =
559+
| AbsAttribute of path
560+
| Attribute of string list * string
561+
| Normal of path
562+
563+
let determineCompletion dotpath =
564+
let rec loop dotpath =
565+
match dotpath with
561566
| [] -> assert false
562-
| [one] -> `Normal (Tip one)
563-
| [one; two] when not (isCapitalized one) -> `Attribute ([one], two)
564-
| [one; two] -> `Normal (Nested (one, Tip two))
567+
| [one] -> Normal (Tip one)
568+
| [one; two] when not (isCapitalized one) -> Attribute ([one], two)
569+
| [one; two] -> Normal (Nested (one, Tip two))
565570
| one :: rest -> (
566571
if isCapitalized one then
567572
match loop rest with
568-
| `Normal path -> `Normal (Nested (one, path))
573+
| Normal path -> Normal (Nested (one, path))
569574
| x -> x
570575
else
571576
match loop rest with
572-
| `Normal path -> `AbsAttribute path
573-
| `Attribute (path, suffix) -> `Attribute (one :: path, suffix)
577+
| Normal path -> AbsAttribute path
578+
| Attribute (path, suffix) -> Attribute (one :: path, suffix)
574579
| x -> x)
575580
in
576-
loop parts
581+
loop dotpath
577582

578583
(* Note: This is a hack. It will be wrong some times if you have a local thing
579584
that overrides an open.
@@ -804,17 +809,17 @@ let getItems ~full ~rawOpens ~allFiles ~pos ~dotpath =
804809
else None)
805810
in
806811
locallyDefinedValues @ valuesFromOpens @ localModuleNames
807-
| multiple -> (
808-
Log.log ("Completing for " ^ String.concat "<.>" multiple);
809-
match determineCompletion multiple with
810-
| `Normal path -> (
812+
| _ -> (
813+
Log.log ("Completing for " ^ String.concat "<.>" dotpath);
814+
match determineCompletion dotpath with
815+
| Normal path -> (
811816
Log.log ("normal " ^ pathToString path);
812817
match getEnvWithOpens ~pos ~env ~package ~opens path with
813818
| Some (env, suffix) ->
814819
Log.log "Got the env";
815820
valueCompletions ~env suffix
816821
| None -> [])
817-
| `Attribute (target, suffix) -> (
822+
| Attribute (target, suffix) -> (
818823
Log.log ("suffix :" ^ suffix);
819824
match target with
820825
| [] -> []
@@ -854,7 +859,7 @@ let getItems ~full ~rawOpens ~allFiles ~pos ~dotpath =
854859
item = Field (f, typ);
855860
}
856861
else None)))))
857-
| `AbsAttribute path -> (
862+
| AbsAttribute path -> (
858863
match getEnvWithOpens ~pos ~env ~package ~opens path with
859864
| None -> []
860865
| Some (env, suffix) ->
@@ -1212,10 +1217,10 @@ let computeCompletions ~completable ~full ~pos ~rawOpens =
12121217
let package = full.package in
12131218
let allFiles = FileSet.union package.projectFiles package.dependenciesFiles in
12141219
let processDotPath ~exact dotpath =
1215-
let items = getItems ~full ~rawOpens ~allFiles ~pos ~dotpath in
1220+
let declareds = getItems ~full ~rawOpens ~allFiles ~pos ~dotpath in
12161221
match dotpath |> List.rev with
12171222
| last :: _ when exact ->
1218-
items |> List.filter (fun {SharedTypes.name = {txt}} -> txt = last)
1219-
| _ -> items
1223+
declareds |> List.filter (fun {SharedTypes.name = {txt}} -> txt = last)
1224+
| _ -> declareds
12201225
in
12211226
completable |> processCompletable ~processDotPath ~full ~package ~rawOpens

0 commit comments

Comments
 (0)