From b1ed7736faecd347b6bc0a2b816b94f17cb5c07b Mon Sep 17 00:00:00 2001 From: crbelaus Date: Wed, 25 Oct 2023 19:23:00 +0200 Subject: [PATCH 1/6] Add start_column and end_column to symbols table --- lib/next_ls/db/schema.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/next_ls/db/schema.ex b/lib/next_ls/db/schema.ex index d66c4047..e31c4ef6 100644 --- a/lib/next_ls/db/schema.ex +++ b/lib/next_ls/db/schema.ex @@ -23,7 +23,7 @@ defmodule NextLS.DB.Schema do alias NextLS.DB - @version 5 + @version 6 def init(conn) do # FIXME: this is odd tech debt. not a big deal but is confusing @@ -73,7 +73,8 @@ defmodule NextLS.DB.Schema do type text NOT NULL, name text NOT NULL, line integer NOT NULL, - column integer NOT NULL, + start_column integer NOT NULL, + end_column integer NOT NULL, source text NOT NULL DEFAULT 'user', inserted_at text NOT NULL DEFAULT CURRENT_TIMESTAMP ); From 0c494e5846954d63c53da1bcb6c69258cdf8f441 Mon Sep 17 00:00:00 2001 From: crbelaus Date: Wed, 25 Oct 2023 19:23:35 +0200 Subject: [PATCH 2/6] Record start and end column when saving symbols --- lib/next_ls/db.ex | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/next_ls/db.ex b/lib/next_ls/db.ex index 90ab1132..d32ec958 100644 --- a/lib/next_ls/db.ex +++ b/lib/next_ls/db.ex @@ -93,10 +93,10 @@ defmodule NextLS.DB do __query__( {conn, s.logger}, ~Q""" - INSERT INTO symbols (module, file, type, name, line, 'column', source) - VALUES (?, ?, ?, ?, ?, ?, ?); + INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) + VALUES (?, ?, ?, ?, ?, ?, ?, ?); """, - [mod, file, "defmodule", mod, module_line, 1, source] + [mod, file, "defmodule", mod, module_line, 1, 1, source] ) if struct do @@ -105,21 +105,25 @@ defmodule NextLS.DB do __query__( {conn, s.logger}, ~Q""" - INSERT INTO symbols (module, file, type, name, line, 'column', source) - VALUES (?, ?, ?, ?, ?, ?, ?); + INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) + VALUES (?, ?, ?, ?, ?, ?, ?, ?); """, - [mod, file, "defstruct", "%#{Macro.to_string(mod)}{}", meta[:line], 1, source] + [mod, file, "defstruct", "%#{Macro.to_string(mod)}{}", meta[:line], 1, 1, source] ) end for {name, {:v1, type, _meta, clauses}} <- defs, {meta, _, _, _} <- clauses do + # Elixir versions older than 1.16 did not provide column metadata + column_start = meta[:column] || 1 + name = to_string(name) + __query__( {conn, s.logger}, ~Q""" - INSERT INTO symbols (module, file, type, name, line, 'column', source) - VALUES (?, ?, ?, ?, ?, ?, ?); + INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) + VALUES (?, ?, ?, ?, ?, ?, ?, ?); """, - [mod, file, type, name, meta[:line], meta[:column] || 1, source] + [mod, file, type, name, meta[:line], column_start, column_start + String.length(name), source] ) end @@ -127,10 +131,10 @@ defmodule NextLS.DB do __query__( {conn, s.logger}, ~Q""" - INSERT INTO symbols (module, file, type, name, line, 'column', source) - VALUES (?, ?, ?, ?, ?, ?, ?); + INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) + VALUES (?, ?, ?, ?, ?, ?, ?, ?); """, - [mod, file, type, name, line, column, source] + [mod, file, type, name, line, column, column + String.length(name), source] ) end From 75737b0d787257e3370491a1e3ca3955584e178a Mon Sep 17 00:00:00 2001 From: crbelaus Date: Wed, 25 Oct 2023 19:24:27 +0200 Subject: [PATCH 3/6] Use start and end column when querying symbols --- lib/next_ls.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/next_ls.ex b/lib/next_ls.ex index 2d901b8a..4bee7736 100644 --- a/lib/next_ls.ex +++ b/lib/next_ls.ex @@ -946,6 +946,7 @@ defmodule NextLS do FROM "symbols" sym WHERE sym.file = ? AND sym.line = ? + AND (sym.type in ('defstruct', 'defmodule') OR ? BETWEEN sym.start_column AND sym.end_column) ORDER BY sym.id ASC LIMIT 1 """ @@ -960,7 +961,7 @@ defmodule NextLS do LIMIT 1 """ - case DB.query(database, definition_query, [file, line]) do + case dbg(DB.query(database, definition_query, dbg([file, line, col]))) do [[module, "defmodule", _]] -> {:module, module} From cc660fd76b59cb751df3e2b497216912d2216fbd Mon Sep 17 00:00:00 2001 From: crbelaus Date: Wed, 25 Oct 2023 19:27:58 +0200 Subject: [PATCH 4/6] Remove unwanted 'dbg' call --- lib/next_ls.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/next_ls.ex b/lib/next_ls.ex index 4bee7736..1cc53314 100644 --- a/lib/next_ls.ex +++ b/lib/next_ls.ex @@ -961,7 +961,7 @@ defmodule NextLS do LIMIT 1 """ - case dbg(DB.query(database, definition_query, dbg([file, line, col]))) do + case DB.query(database, definition_query, [file, line, col]) do [[module, "defmodule", _]] -> {:module, module} From f5fbd4943cde71dc52d4b0cb50af8c076a9b6218 Mon Sep 17 00:00:00 2001 From: crbelaus Date: Fri, 27 Oct 2023 19:31:55 +0200 Subject: [PATCH 5/6] Try to infer defmodule/defstruct columns from references --- lib/next_ls/db.ex | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/next_ls/db.ex b/lib/next_ls/db.ex index d32ec958..53a1b6a9 100644 --- a/lib/next_ls/db.ex +++ b/lib/next_ls/db.ex @@ -90,25 +90,31 @@ defmodule NextLS.DB do [mod] ) + {start_column, end_column} = + infer_columns_from_references(conn, s.logger, file, module_line, "defmodule") + __query__( {conn, s.logger}, ~Q""" INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) VALUES (?, ?, ?, ?, ?, ?, ?, ?); """, - [mod, file, "defmodule", mod, module_line, 1, 1, source] + [mod, file, "defmodule", mod, module_line, start_column, end_column, source] ) if struct do {_, _, meta, _} = defs[:__struct__] + {start_column, end_column} = + infer_columns_from_references(conn, s.logger, file, meta[:line], "defstruct") + __query__( {conn, s.logger}, ~Q""" INSERT INTO symbols (module, file, type, name, line, start_column, end_column, source) VALUES (?, ?, ?, ?, ?, ?, ?, ?); """, - [mod, file, "defstruct", "%#{Macro.to_string(mod)}{}", meta[:line], 1, 1, source] + [mod, file, "defstruct", "%#{Macro.to_string(mod)}{}", meta[:line], start_column, end_column, source] ) end @@ -222,4 +228,22 @@ defmodule NextLS.DB do arg end end + + defp infer_columns_from_references(conn, logger, file, line, identifier) do + result = + __query__( + {conn, logger}, + ~Q""" + SELECT start_column, end_column + FROM "references" + WHERE file = ? AND start_line = ? AND end_line = ? AND identifier = ? + """, + [file, line, line, identifier] + ) + + case result do + [[start_column, end_column]] -> {start_column, end_column} + _unknown -> {1, 1} + end + end end From d6085f4047aa24e345261b0326eadffe513065d6 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Tue, 31 Oct 2023 07:37:43 -0400 Subject: [PATCH 6/6] ci: add 1.16.0-rc.0 --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 06e57647..b424f105 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -12,7 +12,7 @@ jobs: strategy: matrix: otp: [26.0.2] - elixir: [1.15.4] + elixir: [1.15.4, 1.16.0-rc.0] steps: - uses: actions/checkout@v2