Permalink
Browse files

Don't autocomplete identifiers after a user attribute

Summary:
Typing `<<__Override>>` currently pops up an autocomplete box with every
symbol currently available. This is particularly annoying as the most common
thing to do after typing `<<__Override>>` is to hit enter immediately.

refs #8241

Reviewed By: pittsw

Differential Revision: D8884496

fbshipit-source-id: 757b9459b27a75e8bceddfb3b4a2d72ce88af0f2
  • Loading branch information...
fredemmott committed Jul 18, 2018
1 parent ff979c9 commit 7726f1da0aa37796dc35be45f98d20e8e5d1193f
@@ -246,6 +246,9 @@ let compute_complete_global
| Some (pos, _) -> Pos.length pos > suffix_len in
if autocomplete_context.is_after_single_colon && not have_user_prefix then
()
else if autocomplete_context.is_after_double_right_angle_bracket then
(* <<__Override>>AUTO332 *)
()
else begin
let does_fully_qualified_name_match_prefix name =
@@ -72,4 +72,5 @@ type legacy_autocomplete_context = {
is_xhp_classname : bool;
is_instance_member : bool;
is_after_single_colon : bool;
is_after_double_right_angle_bracket : bool;
}
@@ -80,4 +80,5 @@ type legacy_autocomplete_context = {
is_xhp_classname : bool;
is_instance_member : bool;
is_after_single_colon : bool;
is_after_double_right_angle_bracket : bool;
}
@@ -45,6 +45,8 @@ let context_xhp_classname_regex = Str.regexp ".*<[a-zA-Z_0-9:]*$"
let context_xhp_member_regex = Str.regexp ".*->[a-zA-Z_0-9:]*$"
(* For identifying case statements from text context *)
let context_after_single_colon_regex = Str.regexp ".*[a-zA-Z_0-9\"']:$"
(* For identifying user attributes *)
let context_after_double_right_angle_bracket_regex = Str.regexp ".*[a-zA-z_0-9\"' ,)]>>$"
let get_autocomplete_context
(content:string)
@@ -57,16 +59,17 @@ let get_autocomplete_context
is_xhp_classname = false;
is_instance_member = false;
is_after_single_colon = false;
is_after_double_right_angle_bracket = false;
} else
let pos_start = { pos with File_content.column = 1; } in
let (offset_start, offset) = File_content.get_offsets content (pos_start, pos) in
let text = String.sub content offset_start (offset - offset_start) in
(* text is the text from the start of the line up to the caret position *)
let is_xhp_classname = Str.string_match context_xhp_classname_regex text 0 in
let is_instance_member = Str.string_match context_xhp_member_regex text 0 in
let is_after_single_colon = Str.string_match context_after_single_colon_regex text 0
in
{ AutocompleteTypes.is_xhp_classname; is_instance_member; is_after_single_colon; }
let is_after_single_colon = Str.string_match context_after_single_colon_regex text 0 in
let is_after_double_right_angle_bracket = Str.string_match context_after_double_right_angle_bracket_regex text 0 in
{ AutocompleteTypes.is_xhp_classname; is_instance_member; is_after_single_colon; is_after_double_right_angle_bracket }
let auto_complete_at_position
@@ -49,6 +49,7 @@ let handle : type a. genv -> env -> is_stale:bool -> a t -> env * a =
is_xhp_classname = false;
is_instance_member = false;
is_after_single_colon = false;
is_after_double_right_angle_bracket = false;
} in (* feature not implemented here; it only works for LSP *)
ServerAutoComplete.auto_complete
~tcopt:env.tcopt ~delimit_on_namespaces:false ~autocomplete_context content
@@ -0,0 +1,7 @@
<?hh
class Foo {}
class Bar extends Foo {
<<__Override>>AUTO332
}

0 comments on commit 7726f1d

Please sign in to comment.