Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzy function name matching #466

Closed
princemaple opened this issue Feb 1, 2021 · 7 comments · Fixed by #543
Closed

Fuzzy function name matching #466

princemaple opened this issue Feb 1, 2021 · 7 comments · Fixed by #543
Labels
enhancement New feature or request

Comments

@princemaple
Copy link
Contributor

Typing Enum.chub I'd like to see Enum.chunk_by being suggested instead of terminating the auto completion

@axelson axelson added the enhancement New feature or request label Feb 1, 2021
@princemaple
Copy link
Contributor Author

Note to myself or anyone who may want to take this one:
https://github.com/elixir-lsp/elixir_sense/blob/master/lib/elixir_sense/providers/suggestion/complete.ex#L594
Probably just change starts_with? to a proper fuzzy matching function.

@princemaple
Copy link
Contributor Author

princemaple commented Feb 5, 2021

It seems easy enough to make it work.
Not sure how much noise this would cause. If only applied to module functions, I guess it should be fine.

defmodule SuggetionMatch do
  @moduledoc """
  Documentation for `SuggetionMatch`.
  """

  @doc """
  Fuzzy match string

  ## Examples

      iex> SuggetionMatch.match("map", "map")
      true

      iex> SuggetionMatch.match("map", "m")
      true

      iex> SuggetionMatch.match("map", "ma")
      true

      iex> SuggetionMatch.match("map", "mp")
      true

      iex> SuggetionMatch.match("chunk_by", "chub")
      true

      iex> SuggetionMatch.match("chunk_by", "chug")
      false
  """
  @spec match(name :: String.t(), hint :: String.t()) :: boolean()
  def match(<<head::utf8, name_rest::binary>>, <<head::utf8, hint_rest::binary>>) do
    match(name_rest, hint_rest)
  end

  def match(<<_head::utf8, name_rest::binary>>, <<_not_head::utf8, _hint_rest::binary>> = hint) do
    match(name_rest, hint)
  end

  def match(_name_rest, <<>>) do
    true
  end

  def match(<<>>, <<>>) do
    true
  end

  def match(<<>>, _) do
    false
  end
end

@lukaszsamson
Copy link
Collaborator

Note to myself or anyone who may want to take this one:
https://github.com/elixir-lsp/elixir_sense/blob/master/lib/elixir_sense/providers/suggestion/complete.ex#L594
Probably just change starts_with? to a proper fuzzy matching function.

That's not the only place in elixir_sense that uses hint matching with String.starts_with

@princemaple
Copy link
Contributor Author

princemaple commented Feb 5, 2021

Yup. I did notice other occurrences in the same module, and repeated implementation in other modules as well.

@princemaple
Copy link
Contributor Author

So, the list of files where this could help, in ElixirSense:

  • lib/elixir_sense/plugins/option.ex
  • lib/elixir_sense/providers/suggestion/reducers/type_specs.ex
  • lib/elixir_sense/providers/suggestion/reducers/callbacks.ex
  • lib/elixir_sense/providers/suggestion/reducers/struct.ex
  • lib/elixir_sense/providers/suggestion/reducers/params.ex
  • lib/elixir_sense/providers/suggestion/reducers/overridable.ex
  • lib/elixir_sense/providers/suggestion/reducers/protocol.ex
  • lib/elixir_sense/providers/suggestion/reducers/docs_snippets.ex
  • lib/elixir_sense/providers/suggestion/complete.ex
  • lib/elixir_sense/plugins/ecto/schema.ex

@axelson
Copy link
Member

axelson commented Feb 27, 2021

Associated PR: #491

@lukaszsamson
Copy link
Collaborator

While fuzzy matching on function names has been merged there are other cases where it may be useful - see elixir-lsp/elixir_sense#122. Besides those I think we need to change matching algorithm in WorskpaceSymbolsProvider.

lukaszsamson added a commit to lukaszsamson/elixir-ls-1 that referenced this issue May 22, 2021
axelson pushed a commit that referenced this issue May 23, 2021
* Bump elixir_sense

Fixes #242
Fixes #541
Fixes #466

* fix test
vanjabucic pushed a commit to vanjabucic/elixir-ls that referenced this issue Jul 5, 2021
* Bump elixir_sense

Fixes elixir-lsp#242
Fixes elixir-lsp#541
Fixes elixir-lsp#466

* fix test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants