From 9406ac7e15be653622ed88d479a421d29f945c73 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Tue, 8 Aug 2023 15:27:39 -0400 Subject: [PATCH 1/4] Revert "chore: format sql" This reverts commit b25688af97e901fa3c410ae030c4080ceff36af1. --- 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 0b95e77d..60e62588 100644 --- a/lib/next_ls.ex +++ b/lib/next_ls.ex @@ -206,7 +206,7 @@ defmodule NextLS do SELECT file, start_line, end_line, start_column, end_column FROM "references" as refs WHERE refs.module = ? - AND refs.type = ? + and refs.type = ? AND NOT like('/home/runner/work/elixir/%', refs.file) """, [module, "alias"] From 3a74a42291263f724ed026c00a493cfb3a0ec618 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Tue, 8 Aug 2023 15:27:46 -0400 Subject: [PATCH 2/4] Revert "fix(references): ignore references to elixir source code" This reverts commit 6ff4c17d631ad37be4903297873ca6ee7a70a38d. --- lib/next_ls.ex | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/next_ls.ex b/lib/next_ls.ex index 60e62588..3cbe674c 100644 --- a/lib/next_ls.ex +++ b/lib/next_ls.ex @@ -194,7 +194,6 @@ defmodule NextLS do WHERE refs.identifier = ? AND refs.type = ? AND refs.module = ? - AND NOT like('/home/runner/work/elixir/%', refs.file) """, [function, "function", module] ) @@ -207,7 +206,6 @@ defmodule NextLS do FROM "references" as refs WHERE refs.module = ? and refs.type = ? - AND NOT like('/home/runner/work/elixir/%', refs.file) """, [module, "alias"] ) @@ -714,6 +712,5 @@ defmodule NextLS do end end end - defp clamp(line), do: max(line, 0) end From 7b8418a477b8c4be0eaf70db377472f5e3aa10f2 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Tue, 8 Aug 2023 15:27:48 -0400 Subject: [PATCH 3/4] Revert "fix(references): clamp line and column numbers" This reverts commit 55ead79adbfdf62c8e59b8163beeb5c324c56126. --- lib/next_ls.ex | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/next_ls.ex b/lib/next_ls.ex index 3cbe674c..64d256db 100644 --- a/lib/next_ls.ex +++ b/lib/next_ls.ex @@ -218,8 +218,8 @@ defmodule NextLS do %Location{ uri: "file://#{file}", range: %Range{ - start: %Position{line: clamp(start_line - 1), character: clamp(start_column - 1)}, - end: %Position{line: clamp(end_line - 1), character: clamp(end_column - 1)} + start: %Position{line: start_line - 1, character: start_column - 1}, + end: %Position{line: end_line - 1, character: end_column - 1} } } end @@ -712,5 +712,4 @@ defmodule NextLS do end end end - defp clamp(line), do: max(line, 0) end From 1774440d68dcd9d6a3dc74234d1f0a6a3960b071 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Tue, 8 Aug 2023 15:27:51 -0400 Subject: [PATCH 4/4] Revert "feat: find references (#139)" This reverts commit 5a3b530a7d283014f8fadcaf0feb0765dac68a1c. --- lib/next_ls.ex | 109 ------------------------------------------ test/next_ls_test.exs | 98 ------------------------------------- 2 files changed, 207 deletions(-) diff --git a/lib/next_ls.ex b/lib/next_ls.ex index 64d256db..ed30b3fb 100644 --- a/lib/next_ls.ex +++ b/lib/next_ls.ex @@ -19,7 +19,6 @@ defmodule NextLS do alias GenLSP.Requests.TextDocumentDefinition alias GenLSP.Requests.TextDocumentDocumentSymbol alias GenLSP.Requests.TextDocumentFormatting - alias GenLSP.Requests.TextDocumentReferences alias GenLSP.Requests.WorkspaceSymbol alias GenLSP.Structures.DidChangeWatchedFilesParams alias GenLSP.Structures.DidChangeWorkspaceFoldersParams @@ -109,7 +108,6 @@ defmodule NextLS do document_formatting_provider: true, workspace_symbol_provider: true, document_symbol_provider: true, - references_provider: true, definition_provider: true, workspace: %{ workspace_folders: %GenLSP.Structures.WorkspaceFoldersServerCapabilities{ @@ -173,62 +171,6 @@ defmodule NextLS do {:reply, symbols, lsp} end - # TODO handle `context: %{includeDeclaration: true}` to include the current symbol definition among - # the results. - def handle_request(%TextDocumentReferences{params: %{position: position, text_document: %{uri: uri}}}, lsp) do - file = URI.parse(uri).path - line = position.line + 1 - col = position.character + 1 - - locations = - dispatch(lsp.assigns.registry, :databases, fn databases -> - Enum.flat_map(databases, fn {database, _} -> - references = - case symbol_info(file, line, col, database) do - {:function, module, function} -> - DB.query( - database, - ~Q""" - SELECT file, start_line, end_line, start_column, end_column - FROM "references" as refs - WHERE refs.identifier = ? - AND refs.type = ? - AND refs.module = ? - """, - [function, "function", module] - ) - - {:module, module} -> - DB.query( - database, - ~Q""" - SELECT file, start_line, end_line, start_column, end_column - FROM "references" as refs - WHERE refs.module = ? - and refs.type = ? - """, - [module, "alias"] - ) - - :unknown -> - [] - end - - for [file, start_line, end_line, start_column, end_column] <- references do - %Location{ - uri: "file://#{file}", - range: %Range{ - start: %Position{line: start_line - 1, character: start_column - 1}, - end: %Position{line: end_line - 1, character: end_column - 1} - } - } - end - end) - end) - - {:reply, locations, lsp} - end - def handle_request(%WorkspaceSymbol{params: %{query: query}}, lsp) do filter = fn sym -> if query == "" do @@ -661,55 +603,4 @@ defmodule NextLS do {^ref, result} -> result end end - - defp symbol_info(file, line, col, database) do - definition_query = - ~Q""" - SELECT module, type, name - FROM "symbols" sym - WHERE sym.file = ? - AND sym.line = ? - ORDER BY sym.id ASC - LIMIT 1 - """ - - reference_query = ~Q""" - SELECT identifier, type, module - FROM "references" refs - WHERE refs.file = ? - AND refs.start_line <= ? AND refs.end_line >= ? - AND refs.start_column <= ? AND refs.end_column >= ? - ORDER BY refs.id ASC - LIMIT 1 - """ - - case DB.query(database, definition_query, [file, line]) do - [[module, "defmodule", _]] -> - {:module, module} - - [[module, "defstruct", _]] -> - {:module, module} - - [[module, "def", function]] -> - {:function, module, function} - - [[module, "defp", function]] -> - {:function, module, function} - - [[module, "defmacro", function]] -> - {:function, module, function} - - _unknown_definition -> - case DB.query(database, reference_query, [file, line, line, col, col]) do - [[function, "function", module]] -> - {:function, module, function} - - [[_alias, "alias", module]] -> - {:module, module} - - _unknown_reference -> - :unknown - end - end - end end diff --git a/test/next_ls_test.exs b/test/next_ls_test.exs index 99e2f6f6..f0a56c54 100644 --- a/test/next_ls_test.exs +++ b/test/next_ls_test.exs @@ -888,104 +888,6 @@ defmodule NextLSTest do end end - describe "find references" do - @describetag root_paths: ["my_proj"] - setup %{tmp_dir: tmp_dir} do - File.mkdir_p!(Path.join(tmp_dir, "my_proj/lib")) - File.write!(Path.join(tmp_dir, "my_proj/mix.exs"), mix_exs()) - [cwd: tmp_dir] - end - - setup %{cwd: cwd} do - peace = Path.join(cwd, "my_proj/lib/peace.ex") - - File.write!(peace, """ - defmodule MyApp.Peace do - def and_love() do - "✌️" - end - end - """) - - bar = Path.join(cwd, "my_proj/lib/bar.ex") - - File.write!(bar, """ - defmodule Bar do - alias MyApp.Peace - def run() do - Peace.and_love() - end - end - """) - - [bar: bar, peace: peace] - end - - setup :with_lsp - - test "list function references", %{client: client, bar: bar, peace: peace} do - assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}}) - assert_request(client, "client/registerCapability", fn _params -> nil end) - assert_notification "window/logMessage", %{"message" => "[NextLS] Runtime for folder my_proj is ready..."} - assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"} - - request(client, %{ - method: "textDocument/references", - id: 4, - jsonrpc: "2.0", - params: %{ - position: %{line: 1, character: 6}, - textDocument: %{uri: uri(peace)}, - context: %{includeDeclaration: true} - } - }) - - uri = uri(bar) - - assert_result 4, - [ - %{ - "uri" => ^uri, - "range" => %{ - "start" => %{"line" => 3, "character" => 10}, - "end" => %{"line" => 3, "character" => 18} - } - } - ] - end - - test "list module references", %{client: client, bar: bar, peace: peace} do - assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}}) - assert_request(client, "client/registerCapability", fn _params -> nil end) - assert_notification "window/logMessage", %{"message" => "[NextLS] Runtime for folder my_proj is ready..."} - assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"} - - request(client, %{ - method: "textDocument/references", - id: 4, - jsonrpc: "2.0", - params: %{ - position: %{line: 0, character: 10}, - textDocument: %{uri: uri(peace)}, - context: %{includeDeclaration: true} - } - }) - - uri = uri(bar) - - assert_result 4, - [ - %{ - "uri" => ^uri, - "range" => %{ - "start" => %{"line" => 3, "character" => 4}, - "end" => %{"line" => 3, "character" => 9} - } - } - ] - end - end - describe "workspaces" do setup %{tmp_dir: tmp_dir} do [cwd: tmp_dir]