@@ -496,6 +496,23 @@ let resolveOpens ~env ~previous opens ~package =
496
496
(* loop(previous) *)
497
497
previous opens
498
498
499
+ type kind =
500
+ | Module of moduleKind
501
+ | Value of Types .type_expr
502
+ | Type of Type .t
503
+ | Constructor of constructor * Type .t declared
504
+ | Field of field * Type .t declared
505
+ | FileModule of string
506
+
507
+ let kindToInt kind =
508
+ match kind with
509
+ | Module _ -> 9
510
+ | FileModule _ -> 9
511
+ | Constructor (_ , _ ) -> 4
512
+ | Field (_ , _ ) -> 5
513
+ | Type _ -> 22
514
+ | Value _ -> 12
515
+
499
516
let completionForDeclareds ~pos declareds prefix transformContents =
500
517
(* Log.log("completion for declares " ++ prefix); *)
501
518
Hashtbl. fold
@@ -521,33 +538,47 @@ let completionForExporteds exporteds
521
538
else results)
522
539
exporteds []
523
540
524
- let completionForConstructors exportedTypes
525
- (stamps : (int, SharedTypes.Type.t SharedTypes.declared) Hashtbl.t ) prefix =
541
+ let completionForExportedsModules ~env ~suffix =
542
+ completionForExporteds env.QueryEnv. exported.modules env.file.stamps.modules
543
+ suffix (fun m -> Module m)
544
+
545
+ let completionForExportedsValues ~env ~suffix =
546
+ completionForExporteds env.QueryEnv. exported.values env.file.stamps.values
547
+ suffix (fun v -> Value v)
548
+
549
+ let completionForExportedsTypes ~env ~suffix =
550
+ completionForExporteds env.QueryEnv. exported.types env.file.stamps.types
551
+ suffix (fun t -> Type t)
552
+
553
+ let completionForConstructors ~(env : QueryEnv.t ) ~suffix =
526
554
Hashtbl. fold
527
555
(fun _name stamp results ->
528
- let t = Hashtbl. find stamps stamp in
556
+ let t = Hashtbl. find env.file. stamps.types stamp in
529
557
match t.item.kind with
530
558
| SharedTypes.Type. Variant constructors ->
531
559
(constructors
532
- |> List. filter (fun c -> Utils. startsWith c.cname.txt prefix )
560
+ |> List. filter (fun c -> Utils. startsWith c.cname.txt suffix )
533
561
|> List. map (fun c -> (c, t)))
534
562
@ results
535
563
| _ -> results)
536
- exportedTypes []
564
+ env.exported.types []
565
+ |> List. map (fun (c , t ) ->
566
+ {(emptyDeclared c.cname.txt) with item = Constructor (c, t)})
537
567
538
- let completionForFields exportedTypes
539
- (stamps : (int, SharedTypes.Type.t SharedTypes.declared) Hashtbl.t ) prefix =
568
+ let completionForFields ~(env : QueryEnv.t ) ~suffix =
540
569
Hashtbl. fold
541
570
(fun _name stamp results ->
542
- let t = Hashtbl. find stamps stamp in
571
+ let t = Hashtbl. find env.file. stamps.types stamp in
543
572
match t.item.kind with
544
573
| Record fields ->
545
574
(fields
546
- |> List. filter (fun f -> Utils. startsWith f.fname.txt prefix )
575
+ |> List. filter (fun f -> Utils. startsWith f.fname.txt suffix )
547
576
|> List. map (fun f -> (f, t)))
548
577
@ results
549
578
| _ -> results)
550
- exportedTypes []
579
+ env.exported.types []
580
+ |> List. map (fun (f , t ) ->
581
+ {(emptyDeclared f.fname.txt) with item = Field (f, t)})
551
582
552
583
let isCapitalized name =
553
584
if name = " " then false
@@ -626,23 +657,6 @@ let getEnvWithOpens ~pos ~(env : QueryEnv.t) ~package ~(opens : QueryEnv.t list)
626
657
in
627
658
loop opens
628
659
629
- type kind =
630
- | Module of moduleKind
631
- | Value of Types .type_expr
632
- | Type of Type .t
633
- | Constructor of constructor * Type .t declared
634
- | Field of field * Type .t declared
635
- | FileModule of string
636
-
637
- let kindToInt kind =
638
- match kind with
639
- | Module _ -> 9
640
- | FileModule _ -> 9
641
- | Constructor (_ , _ ) -> 4
642
- | Field (_ , _ ) -> 5
643
- | Type _ -> 22
644
- | Value _ -> 12
645
-
646
660
let detail name contents =
647
661
match contents with
648
662
| Type {decl} -> decl |> Shared. declToString name
@@ -657,19 +671,18 @@ let detail name contents =
657
671
| Constructor (c , t ) ->
658
672
showConstructor c ^ " \n\n " ^ (t.item.decl |> Shared. declToString t.name.txt)
659
673
674
+ let completionForDeclaredsModules ~pos ~env ~suffix =
675
+ completionForDeclareds ~pos env.QueryEnv. file.stamps.modules suffix (fun m ->
676
+ Module m)
677
+
660
678
let localValueCompletions ~pos ~(env : QueryEnv.t ) suffix =
661
679
let results = [] in
662
680
Log. log " ---------------- LOCAL VAL" ;
663
681
let results =
664
682
if suffix = " " || isCapitalized suffix then
665
683
results
666
- @ completionForDeclareds ~pos env.file.stamps.modules suffix (fun m ->
667
- Module m)
668
- @ (completionForConstructors env.exported.types env.file.stamps.types
669
- (* TODO declared thingsz *)
670
- suffix
671
- |> List. map (fun (c , t ) ->
672
- {(emptyDeclared c.cname.txt) with item = Constructor (c, t)}))
684
+ @ completionForDeclaredsModules ~pos ~env ~suffix
685
+ @ completionForConstructors ~env ~suffix
673
686
else results
674
687
in
675
688
let results =
@@ -679,9 +692,7 @@ let localValueCompletions ~pos ~(env : QueryEnv.t) suffix =
679
692
Value v)
680
693
@ completionForDeclareds ~pos env.file.stamps.types suffix (fun t ->
681
694
Type t)
682
- @ (completionForFields env.exported.types env.file.stamps.types suffix
683
- |> List. map (fun (f , t ) ->
684
- {(emptyDeclared f.fname.txt) with item = Field (f, t)}))
695
+ @ completionForFields ~env ~suffix
685
696
else results
686
697
in
687
698
results |> List. map (fun r -> (r, env))
@@ -695,31 +706,18 @@ let valueCompletions ~(env : QueryEnv.t) suffix =
695
706
env.exported.modules
696
707
|> Hashtbl. filter_map_inplace (fun name key ->
697
708
if isCapitalized name then Some key else None );
698
- let moduleCompletions =
699
- completionForExporteds env.exported.modules env.file.stamps.modules
700
- suffix (fun m -> Module m)
701
- in
702
- (* Log.log(" -- capitalized " ++ string_of_int(Hashtbl.length(env.exported.types)) ++ " exported types"); *)
703
- (* env.exported.types |> Hashtbl.iter((name, _) => Log.log(" > " ++ name)); *)
704
- results @ moduleCompletions
705
- @ ((* TODO declared thingsz *)
706
- completionForConstructors env.exported.types env.file.stamps.types
707
- suffix
708
- |> List. map (fun (c , t ) ->
709
- {(emptyDeclared c.cname.txt) with item = Constructor (c, t)})))
709
+ results
710
+ @ completionForExportedsModules ~env ~suffix
711
+ @ completionForConstructors ~env ~suffix )
710
712
else results
711
713
in
712
714
let results =
713
715
if suffix = " " || not (isCapitalized suffix) then (
714
716
Log. log " -- not capitalized" ;
715
717
results
716
- @ completionForExporteds env.exported.values env.file.stamps.values suffix
717
- (fun v -> Value v)
718
- @ completionForExporteds env.exported.types env.file.stamps.types suffix
719
- (fun t -> Type t)
720
- @ (completionForFields env.exported.types env.file.stamps.types suffix
721
- |> List. map (fun (f , t ) ->
722
- {(emptyDeclared f.fname.txt) with item = Field (f, t)})))
718
+ @ completionForExportedsValues ~env ~suffix
719
+ @ completionForExportedsTypes ~env ~suffix
720
+ @ completionForFields ~env ~suffix )
723
721
else results
724
722
in
725
723
results |> List. map (fun r -> (r, env))
@@ -728,20 +726,14 @@ let attributeCompletions ~(env : QueryEnv.t) ~suffix =
728
726
let results = [] in
729
727
let results =
730
728
if suffix = " " || isCapitalized suffix then
731
- results
732
- @ completionForExporteds env.exported.modules env.file.stamps.modules
733
- suffix (fun m -> Module m)
729
+ results @ completionForExportedsModules ~env ~suffix
734
730
else results
735
731
in
736
732
let results =
737
733
if suffix = " " || not (isCapitalized suffix) then
738
734
results
739
- @ completionForExporteds env.exported.values env.file.stamps.values suffix
740
- (fun v -> Value v)
741
- (* completionForExporteds(env.exported.types, env.file.stamps.types, suffix, t => Type(t)) @ *)
742
- @ (completionForFields env.exported.types env.file.stamps.types suffix
743
- |> List. map (fun (f , t ) ->
744
- {(emptyDeclared f.fname.txt) with item = Field (f, t)}))
735
+ @ completionForExportedsValues ~env ~suffix
736
+ @ completionForFields ~env ~suffix
745
737
else results
746
738
in
747
739
results |> List. map (fun r -> (r, env))
0 commit comments