Skip to content

Commit

Permalink
Offer 'did you mean' suggestions case-insensitively
Browse files Browse the repository at this point in the history
Summary: Don't consider case when trying to find the most similar item in naming suggestions.

Reviewed By: vsiles

Differential Revision: D39328377

fbshipit-source-id: 3b2f21c233cce801c8b35621f41be643e0a37708
  • Loading branch information
Wilfred authored and facebook-github-bot committed Sep 8, 2022
1 parent ed46335 commit 3a3a5a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hphp/hack/src/typing/typing_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,14 @@ let get_static_member is_method env class_ mid =

ce_opt

(* Given a list of things whose name we can extract with `f`, return
the item whose name is closest to `name`. *)
(* Given a list of [possibilities] whose name we can extract with [f], return
the item whose name is closest to [name]. *)
let most_similar (name : string) (possibilities : 'a list) (f : 'a -> string) :
'a option =
(* Compare strings case-insensitively. *)
let name = String.lowercase name in
let f x = String.lowercase (f x) in

let distance upper_bound = String_utils.levenshtein_distance ~upper_bound in
let choose_closest ~best:(best, best_distance) candidate =
let candidate_distance = distance (best_distance + 1) (f candidate) name in
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?hh

enum class E: mixed {
int car = 1;
int CARROT = 42;
}

function takes_label(HH\EnumClass\Label<E, int> $_): void {}

function call_it(): void {
takes_label(#carrot);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
File "class_missing_label_case.php", line 11, characters 15-21:
Enum class `E` does not contain a label named `carrot`. (Typing[4394])
File "class_missing_label_case.php", line 3, characters 12-12:
`E` is defined here
File "class_missing_label_case.php", line 5, characters 7-12:
Did you mean `#CARROT`?
File "class_missing_label_case.php", line 8, characters 41-41:
This is why I expected an enum class label from `E`.

0 comments on commit 3a3a5a5

Please sign in to comment.