@@ -243,6 +243,7 @@ let kindToDetail name (kind : Completion.kind) =
243
243
^ " )" )
244
244
^ " \n\n " ^ s
245
245
| Snippet s -> s
246
+ | FollowContextPath _ -> " "
246
247
| ExtractedType (extractedType , _ ) ->
247
248
TypeUtils. extractedTypeToString extractedType
248
249
@@ -262,7 +263,7 @@ let findAllCompletions ~(env : QueryEnv.t) ~prefix ~exact ~namesUsed
262
263
completionForExportedFields ~env ~prefix ~exact ~names Used
263
264
@ completionForExportedModules ~env ~prefix ~exact ~names Used
264
265
265
- let processLocalValue name loc ~prefix ~exact ~env
266
+ let processLocalValue name loc contextPath ~prefix ~exact ~env
266
267
~(localTables : LocalTables.t ) =
267
268
if Utils. checkName name ~prefix ~exact then
268
269
match Hashtbl. find_opt localTables.valueTable (name, Loc. start loc) with
@@ -284,10 +285,13 @@ let processLocalValue name loc ~prefix ~exact ~env
284
285
localTables.resultRev < -
285
286
Completion. create name ~env
286
287
~kind:
287
- (Value
288
- (Ctype. newconstr
289
- (Path. Pident (Ident. create " Type Not Known" ))
290
- [] ))
288
+ (match contextPath with
289
+ | Some contextPath -> FollowContextPath contextPath
290
+ | None ->
291
+ Value
292
+ (Ctype. newconstr
293
+ (Path. Pident (Ident. create " Type Not Known" ))
294
+ [] ))
291
295
:: localTables.resultRev
292
296
293
297
let processLocalConstructor name loc ~prefix ~exact ~env
@@ -616,27 +620,47 @@ let completionsGetCompletionType ~full = function
616
620
617
621
type getCompletionsForContextPathMode = Regular | Pipe
618
622
619
- let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
623
+ let rec completionsGetTypeEnv2 (completions : Completion.t list ) ~full ~opens
624
+ ~rawOpens ~allFiles ~pos ~scope =
625
+ match completions with
626
+ | {Completion. kind = Value typ ; env} :: _ -> Some (typ, env)
627
+ | {Completion. kind = ObjLabel typ ; env} :: _ -> Some (typ, env)
628
+ | {Completion. kind = Field ({typ} , _ ); env} :: _ -> Some (typ, env)
629
+ | {Completion. kind = FollowContextPath ctxPath ; env} :: _ ->
630
+ ctxPath
631
+ |> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
632
+ ~exact: true ~scope
633
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
634
+ | _ -> None
635
+
636
+ and getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
620
637
~exact ~scope ?(mode = Regular ) (contextPath : Completable.contextPath ) =
621
638
let package = full.package in
622
639
match contextPath with
623
640
| CPString ->
624
641
[
625
- Completion. create " string " ~env
642
+ Completion. create " dummy " ~env
626
643
~kind:
627
644
(Completion. Value
628
645
(Ctype. newconstr (Path. Pident (Ident. create " string" )) [] ));
629
646
]
647
+ | CPBool ->
648
+ [
649
+ Completion. create " dummy" ~env
650
+ ~kind:
651
+ (Completion. Value
652
+ (Ctype. newconstr (Path. Pident (Ident. create " bool" )) [] ));
653
+ ]
630
654
| CPInt ->
631
655
[
632
- Completion. create " int " ~env
656
+ Completion. create " dummy " ~env
633
657
~kind:
634
658
(Completion. Value
635
659
(Ctype. newconstr (Path. Pident (Ident. create " int" )) [] ));
636
660
]
637
661
| CPFloat ->
638
662
[
639
- Completion. create " float " ~env
663
+ Completion. create " dummy " ~env
640
664
~kind:
641
665
(Completion. Value
642
666
(Ctype. newconstr (Path. Pident (Ident. create " float" )) [] ));
@@ -694,7 +718,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
694
718
cp
695
719
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
696
720
~exact: true ~scope
697
- |> completionsGetTypeEnv
721
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
698
722
with
699
723
| Some (typ , env ) -> (
700
724
let rec reconstructFunctionType args tRet =
@@ -740,7 +764,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
740
764
cp
741
765
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
742
766
~exact: true ~scope
743
- |> completionsGetTypeEnv
767
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
744
768
with
745
769
| Some (typ , env ) -> (
746
770
match typ |> TypeUtils. extractRecordType ~env ~package with
@@ -764,7 +788,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
764
788
cp
765
789
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
766
790
~exact: true ~scope
767
- |> completionsGetTypeEnv
791
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
768
792
with
769
793
| Some (typ , env ) -> (
770
794
match typ |> TypeUtils. extractObjectType ~env ~package with
@@ -791,7 +815,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
791
815
cp
792
816
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
793
817
~exact: true ~scope ~mode: Pipe
794
- |> completionsGetTypeEnv
818
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
795
819
with
796
820
| None -> []
797
821
| Some (typ , envFromCompletionItem ) -> (
@@ -945,7 +969,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
945
969
path
946
970
|> getCompletionsForPath ~completion Context:Value ~exact: true ~package
947
971
~opens ~all Files ~pos ~env ~scope
948
- |> completionsGetTypeEnv
972
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
949
973
in
950
974
let lowercaseComponent =
951
975
match pathToComponent with
@@ -991,7 +1015,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
991
1015
functionContextPath
992
1016
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos
993
1017
~env ~exact: true ~scope
994
- |> completionsGetTypeEnv
1018
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
995
1019
with
996
1020
| Some (typ , env ) -> (typ |> TypeUtils. getArgs ~full ~env , env)
997
1021
| None -> ([] , env)
@@ -1314,7 +1338,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
1314
1338
path
1315
1339
|> getCompletionsForPath ~completion Context:Value ~exact: true ~package
1316
1340
~opens ~all Files ~pos ~env ~scope
1317
- |> completionsGetTypeEnv
1341
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
1318
1342
in
1319
1343
match completable with
1320
1344
| Cnone -> []
@@ -1380,7 +1404,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
1380
1404
cp
1381
1405
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos
1382
1406
~env ~exact: true ~scope
1383
- |> completionsGetTypeEnv
1407
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
1384
1408
with
1385
1409
| Some (typ , _env ) ->
1386
1410
if debug then
@@ -1416,7 +1440,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
1416
1440
contextPath
1417
1441
|> getCompletionsForContextPath ~full ~opens ~raw Opens ~all Files ~pos ~env
1418
1442
~exact: true ~scope
1419
- |> completionsGetTypeEnv
1443
+ |> completionsGetTypeEnv2 ~full ~opens ~raw Opens ~all Files ~pos ~scope
1420
1444
with
1421
1445
| Some (typ , env ) -> (
1422
1446
match
0 commit comments