lexical-lsp / lexical

Lexical is a next-generation elixir language server
874 stars 80 forks source link

Is there any options to remove certain completions? e.g. `div(dividend, divisor)` #688

Open pejrich opened 5 months ago

pejrich commented 5 months ago

This isn't a bug, but rather a question, or maybe feature request.

I'm using the setup for nvim, and I had a similar issue in VSCode which is that Lexical likes to suggest div(dividend, divisor)~ Function for autocomplete, which seems to always be at the top of the list(when i've typed div), however from years of muscle memory, div is always <div>|</div>, so it drives me nuts every time I get div(|dividend, divisor) since it's a function I use so rarely. VSCode seemed to have no way to turn off specific suggestions. I'm curious if there are any options for neovim I can pass to Lexical in the lsp_config.setup({...}) call that would turn off specific suggestions?

skbolton commented 5 months ago

All of the neovim lsp callbacks are customizable. So could override the the completion request and swallow ones matching that pattern.

scohen commented 5 months ago

Currently, lexical doesn't support any configuration. I've been considering adding project-level configuration, but we haven't had the need for configuration yet.

scohen commented 5 months ago

Another take on this would be to refine completions based on their context. For example, you should not get a completion in heex unless you're inside of an elixir block.

pejrich commented 5 months ago

Another take on this would be to refine completions based on their context. For example, you should not get a completion in heex unless you're inside of an elixir block.

This would be amazing. As much as there are a lot of things I like about the new Phoenix stuff since LiveView, the comingling of HTML and Elixir can at times be cumbersome. Either the HTML doesn't format, or intellisense gives me Elixir completions inside of HTML, or equally as bad, SomeModu<tab> in Elixir code gives me <SomeModu></SomeModu>, because in order to get <div>|</div> completion inside a .ex component file, I have to tell the editor(in this case VSCode, for example) that .ex files are html, which means some React HTML completion extension thinks SomeModu might be a React component. (These aren't Lexical specific issues, just general things i've come across)

I guess it's different for everyone in terms of what code assistance they find nice to have, and which things they find hard to live without. Having function completion in Elixir is very nice, but for me having to type out a function is typically less cumbersome(since it generally flows in a single direction), than having to type out HTML tags by hand, because you're either jumping around to the beginning and end of everything, or you're trying to figure out what block is missing a closing tag.

One complexity is that you have Elixir within HTML within Elixir. I'm not sure how much of a challenge that it from the code context side of things

defmodule SomeComponent do

  def some_function(assigns) do
    # ELIXIR HERE
    ~H"""
       HTML HERE
       <div class={ELIXIR HERE}>HTML HERE <%= ELIXIR HERE %></div>
     """
  end
end
pejrich commented 5 months ago

All of the neovim lsp callbacks are customizable. So could override the the completion request and swallow ones matching that pattern.

This is very helpful, thank you. I'm still in the long, (sometimes painful) process of switching to Neovim, and while I'm sure everything I want is possible, I have to sometimes block my time, "Ok, I'll only spend 1 hour trying to find the relevant docs/solution to this", otherwise Neovim can at times feel like 90% of your time is coding your editor, and only 10% is coding your code, haha. But this link gets me going in the right direction.

scohen commented 5 months ago

that .ex files are html

You should be able to get more granular than that. Emacs has something called multi-mode-mode or polymode which allows you to tell it that certain parts of a file are in one language, and the others are in another. Perhaps vscode has similar functionality?

One complexity is that you have Elixir within HTML within Elixir. I'm not sure how much of a challenge that it from the code context side of things

We can detect the ~H sigils in the AST pretty easily, though that's a feature for the 0.7. Would you mind drafting an issue for that? It seems the best way forward.