@@ -31,6 +31,7 @@ type autocomplete_type =
31
31
| Actype
32
32
| Acclass_get
33
33
| Acprop
34
+ | Actrait_only
34
35
35
36
let (argument_global_type: autocomplete_type option ref ) = ref None
36
37
let auto_complete_for_global = ref " "
@@ -118,6 +119,8 @@ let autocomplete_id id env = autocomplete_token Acid (Some env) id
118
119
119
120
let autocomplete_hint = autocomplete_token Actype None
120
121
122
+ let autocomplete_trait_only = autocomplete_token Actrait_only None
123
+
121
124
let autocomplete_new cid env =
122
125
match cid with
123
126
| Nast. CI (sid , _ ) -> autocomplete_token Acnew (Some env) sid
@@ -164,6 +167,7 @@ let should_complete_class completion_type class_kind =
164
167
| Some Acid , Some Ast. Cnormal
165
168
| Some Acid , Some Ast. Cabstract
166
169
| Some Acnew , Some Ast. Cnormal
170
+ | Some Actrait_only , Some Ast. Ctrait
167
171
| Some Actype , Some _ -> true
168
172
| _ -> false
169
173
@@ -529,7 +533,7 @@ let autocomplete_typed_member ~is_static env class_ty cid mid =
529
533
let autocomplete_static_member env (ty , cid ) mid =
530
534
autocomplete_typed_member ~is_static: true env ty (Some cid) mid
531
535
532
- class ['self ] visitor = object (_ : 'self )
536
+ class ['self ] visitor = object (self : 'self )
533
537
inherit [_] Tast_visitor. iter as super
534
538
535
539
method! on_Id env id =
@@ -579,6 +583,18 @@ class ['self] visitor = object (_ : 'self)
579
583
end
580
584
end;
581
585
super#on_Xml env sid attrs el
586
+
587
+ method! on_class_ env cls =
588
+ List. iter cls.Tast. c_uses ~f: begin fun hint ->
589
+ match snd hint with
590
+ | Aast. Happly (sid , params ) ->
591
+ autocomplete_trait_only sid;
592
+ List. iter params (self#on_hint env)
593
+ | _ -> ()
594
+ end;
595
+ (* If we don't clear out c_uses we'll end up overwriting the trait
596
+ completion as soon as we get to on_Happly. *)
597
+ super#on_class_ env {cls with Tast. c_uses = [] }
582
598
end
583
599
584
600
class ['self ] auto_complete_suffix_finder = object (_ : 'self )
@@ -667,21 +683,32 @@ let go
667
683
let completion_type = ! argument_global_type in
668
684
if completion_type = Some Acid ||
669
685
completion_type = Some Acnew ||
670
- completion_type = Some Actype
686
+ completion_type = Some Actype ||
687
+ completion_type = Some Actrait_only
671
688
then compute_complete_global
672
689
~tcopt ~delimit_on_namespaces ~autocomplete_context ~content_funs ~content_classes ;
673
690
if completion_type = Some Acprop then compute_complete_local tast;
674
691
let env = match ! ac_env with
675
692
| Some e -> e
676
693
| None -> Typing_env. empty tcopt Relative_path. default ~droot: None
677
694
in
695
+ let filter_results (result : autocomplete_result ) : bool =
696
+ let kind = match result with
697
+ | Partial res -> res.kind_
698
+ | Complete res -> res.res_kind
699
+ in
700
+ match completion_type, kind with
701
+ | Some Actrait_only , Trait_kind -> true
702
+ | Some Actrait_only , _ -> false
703
+ | _ -> true
704
+ in
678
705
let resolve (result : autocomplete_result ) : complete_autocomplete_result =
679
706
match result with
680
707
| Partial res -> resolve_ty env autocomplete_context res ~delimit_on_namespaces
681
708
| Complete res -> res
682
709
in
683
710
{
684
711
With_complete_flag. is_complete = ! autocomplete_is_complete;
685
- value = ! autocomplete_results |> List. map ~f: resolve;
712
+ value = ! autocomplete_results |> List. filter ~f: filter_results |> List. map ~f: resolve;
686
713
}
687
714
end
0 commit comments