justincjohnson

justincjohnson

I am trying to add rename support to the wonderful Elixir Language Server project in https://github.com/JakeBecker/elixir-ls/issues/22. I’m at a very early stage in this work, making sure I understand the Language Server Protocol spec as well as the capabilities within Elixir itself, and creating a list of all the work I believe will be involved. That said I’ve been able to implement a proof of concept that, within certain constraints, does rename function definitions and references.

I’m facing a challenge currently and am posting here in the hopes that someone can save me some time and point me in the right direction in the Elixir code base.

When I need to rename a function, I first find the function definition and all references to the function throughout the project’s code base. The granularity of this information (in part coming from Mix.Tasks.Xref) currently only includes files and line numbers. I don’t know the function name start and end character numbers on the given line, how many times the function is referenced on that line, or exactly what names are used for those references, be they fully qualified modules and function names, partially qualified modules relying on aliases, module names that rely on aliases with renamed modules via the :as keyword, or just function names via import. This makes it challenging to know what portion of text on the given line needs to be renamed.

It seems to me that I need to tap into the Elixir runtime in order to know exactly what valid ways exist to reference a given function on a given line of a file. Without tapping into the runtime it seems that I would have to reimplement a bunch of logic that would have already been implemented in Elixir itself.

Does that make sense? So what I’m hoping for is a function I can call where I can pass in an MFA tuple, a file path and a line number and get back a list of references to that function on that line along with metadata about those references so I can determine the exact start and end characters that need to be renamed.

From my initial research I’m assuming this at least doesn’t exist today in a public function, but perhaps there are internals I can use, and if so perhaps this is worth a proposal for a new public function to help with Elixir tooling.

Thanks in advance for any tips you can provide.

Showing Posts 1 to 4

msaraiva

msaraiva

Broadway Core Team

Hi @justincjohnson!

If you set up ElixirLS to use this branch of ElixirSense, you’ll have everything you need. You can use ElixirSense.references/3 to retrieve the list of all references including function calls from aliased/imported modules. You’ll also get the exact ranges you need to replace in each file. Here’s an example:

iex> ElixirSense.references(code, line, column) |> Enum.take(2)
  [
    %{
      uri: "test/support/modules_with_references.ex",
      range: %{
        start: %{line: 26, column: 60},
        end: %{line: 26, column: 64}
      }
    },
    %{
      uri: "test/support/modules_with_references.ex",
      range: %{
        start: %{line: 42, column: 16},
        end: %{line: 42, column: 20}
      }
    }
  ]
justincjohnson

justincjohnson OP

Wonderful! I’ll give it a try over the weekend and let you know if I have any feedback.

justincjohnson

justincjohnson OP

Forgive me for the delay @msaraiva. I’ve run into some trouble with the code but haven’t had time to formulate a simplified reproduction to ensure it doesn’t have to do with anything specific to my ElixirLS changes. I’ll keep you posted.

msaraiva

msaraiva

Broadway Core Team

Hey @justincjohnson, no worries. The branch mentioned has already been merged so it’s probably a good idea to start using master for your tests.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews