next-ls icon indicating copy to clipboard operation
next-ls copied to clipboard

Renaming a module leaves the old information in the database

Open crbelaus opened this issue 1 year ago • 0 comments

Let's say we have the following module:

defmodule MyModule do
  @moduledoc false
  def greet, do: "Hello"
end

The symbols table contains this:

sqlite> select * from symbols where module like 'MyModule%';
id     module    file                                                       type       name      line  column  source  inserted_at
-----  --------  ---------------------------------------------------------  ---------  --------  ----  ------  ------  -------------------
16064  MyModule  /Users/crbelaus/Developer/next-ls/lib/next_ls/mymodule.ex  defmodule  MyModule  1     1       user    2023-10-25 17:36:01
16065  MyModule  /Users/crbelaus/Developer/next-ls/lib/next_ls/mymodule.ex  def        greet     3     7       user    2023-10-25 17:36:01

Then I rename MyModule to MyModuleRenamed. Now the database contains this:

sqlite> select * from symbols where module like 'MyModule%';
id     module           file                                                       type       name             line  column  source  inserted_at
-----  ---------------  ---------------------------------------------------------  ---------  ---------------  ----  ------  ------  -------------------
16064  MyModule         /Users/crbelaus/Developer/next-ls/lib/next_ls/mymodule.ex  defmodule  MyModule         1     1       user    2023-10-25 17:36:01
16065  MyModule         /Users/crbelaus/Developer/next-ls/lib/next_ls/mymodule.ex  def        greet            3     7       user    2023-10-25 17:36:01
16066  MyModuleRenamed  /Users/crbelaus/Developer/next-ls/lib/next_ls/mymodule.ex  defmodule  MyModuleRenamed  1     1       user    2023-10-25 17:36:33
16067  MyModuleRenamed  /Users/crbelaus/Developer/next-ls/lib/next_ls/mymodule.ex  def        greet            3     7       user    2023-10-25 17:36:33

As you can see the old module information is still present in the database, even though the module does not exist. When we query the information, for example for finding references, we get the old module rows as they appear first in the table.

Instead, the old module information should be removed from the table as it does not exist anymore.

crbelaus avatar Oct 25 '23 17:10 crbelaus