elixir-tools / next-ls

The language server for Elixir that just works. Ready for early adopters!
https://www.elixir-tools.dev/next-ls
MIT License
674 stars 40 forks source link

workspace command: inline a private function to an anonymous one #437

Open NJichev opened 4 months ago

NJichev commented 4 months ago

A workspace command that inlines a private function

Example:

defmodule Example do
  def run(list) do
    Enum.map(list, &square/1)
  end

  defp square(x) do
    x * x
  end
end

Hovering square in the run function should and using the workspace command should result in:

defmodule Example do
  def run(list) do
    square = fn x -> x * x end
    Enum.map(list, square)
  end
end

Consider the following scenarios:

mhanberg commented 4 months ago

@NJichev i think that my expectation for this sort of refactor would be to actually inline the function with a lambda at the call sites.

so you example of

defmodule Example do
  def run(list) do
    Enum.map(list, &square/1)
  end

  defp square(x) do
    x * x
  end
end

would refactor to

defmodule Example do
  def run(list) do
    Enum.map(list, fn x -> x * x end)
  end
end