Skip to content

Commit 1774440

Browse files
committed
Revert "feat: find references (#139)"
This reverts commit 5a3b530.
1 parent 7b8418a commit 1774440

File tree

2 files changed

+0
-207
lines changed

2 files changed

+0
-207
lines changed

Diff for: lib/next_ls.ex

-109
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ defmodule NextLS do
1919
alias GenLSP.Requests.TextDocumentDefinition
2020
alias GenLSP.Requests.TextDocumentDocumentSymbol
2121
alias GenLSP.Requests.TextDocumentFormatting
22-
alias GenLSP.Requests.TextDocumentReferences
2322
alias GenLSP.Requests.WorkspaceSymbol
2423
alias GenLSP.Structures.DidChangeWatchedFilesParams
2524
alias GenLSP.Structures.DidChangeWorkspaceFoldersParams
@@ -109,7 +108,6 @@ defmodule NextLS do
109108
document_formatting_provider: true,
110109
workspace_symbol_provider: true,
111110
document_symbol_provider: true,
112-
references_provider: true,
113111
definition_provider: true,
114112
workspace: %{
115113
workspace_folders: %GenLSP.Structures.WorkspaceFoldersServerCapabilities{
@@ -173,62 +171,6 @@ defmodule NextLS do
173171
{:reply, symbols, lsp}
174172
end
175173

176-
# TODO handle `context: %{includeDeclaration: true}` to include the current symbol definition among
177-
# the results.
178-
def handle_request(%TextDocumentReferences{params: %{position: position, text_document: %{uri: uri}}}, lsp) do
179-
file = URI.parse(uri).path
180-
line = position.line + 1
181-
col = position.character + 1
182-
183-
locations =
184-
dispatch(lsp.assigns.registry, :databases, fn databases ->
185-
Enum.flat_map(databases, fn {database, _} ->
186-
references =
187-
case symbol_info(file, line, col, database) do
188-
{:function, module, function} ->
189-
DB.query(
190-
database,
191-
~Q"""
192-
SELECT file, start_line, end_line, start_column, end_column
193-
FROM "references" as refs
194-
WHERE refs.identifier = ?
195-
AND refs.type = ?
196-
AND refs.module = ?
197-
""",
198-
[function, "function", module]
199-
)
200-
201-
{:module, module} ->
202-
DB.query(
203-
database,
204-
~Q"""
205-
SELECT file, start_line, end_line, start_column, end_column
206-
FROM "references" as refs
207-
WHERE refs.module = ?
208-
and refs.type = ?
209-
""",
210-
[module, "alias"]
211-
)
212-
213-
:unknown ->
214-
[]
215-
end
216-
217-
for [file, start_line, end_line, start_column, end_column] <- references do
218-
%Location{
219-
uri: "file://#{file}",
220-
range: %Range{
221-
start: %Position{line: start_line - 1, character: start_column - 1},
222-
end: %Position{line: end_line - 1, character: end_column - 1}
223-
}
224-
}
225-
end
226-
end)
227-
end)
228-
229-
{:reply, locations, lsp}
230-
end
231-
232174
def handle_request(%WorkspaceSymbol{params: %{query: query}}, lsp) do
233175
filter = fn sym ->
234176
if query == "" do
@@ -661,55 +603,4 @@ defmodule NextLS do
661603
{^ref, result} -> result
662604
end
663605
end
664-
665-
defp symbol_info(file, line, col, database) do
666-
definition_query =
667-
~Q"""
668-
SELECT module, type, name
669-
FROM "symbols" sym
670-
WHERE sym.file = ?
671-
AND sym.line = ?
672-
ORDER BY sym.id ASC
673-
LIMIT 1
674-
"""
675-
676-
reference_query = ~Q"""
677-
SELECT identifier, type, module
678-
FROM "references" refs
679-
WHERE refs.file = ?
680-
AND refs.start_line <= ? AND refs.end_line >= ?
681-
AND refs.start_column <= ? AND refs.end_column >= ?
682-
ORDER BY refs.id ASC
683-
LIMIT 1
684-
"""
685-
686-
case DB.query(database, definition_query, [file, line]) do
687-
[[module, "defmodule", _]] ->
688-
{:module, module}
689-
690-
[[module, "defstruct", _]] ->
691-
{:module, module}
692-
693-
[[module, "def", function]] ->
694-
{:function, module, function}
695-
696-
[[module, "defp", function]] ->
697-
{:function, module, function}
698-
699-
[[module, "defmacro", function]] ->
700-
{:function, module, function}
701-
702-
_unknown_definition ->
703-
case DB.query(database, reference_query, [file, line, line, col, col]) do
704-
[[function, "function", module]] ->
705-
{:function, module, function}
706-
707-
[[_alias, "alias", module]] ->
708-
{:module, module}
709-
710-
_unknown_reference ->
711-
:unknown
712-
end
713-
end
714-
end
715606
end

Diff for: test/next_ls_test.exs

-98
Original file line numberDiff line numberDiff line change
@@ -888,104 +888,6 @@ defmodule NextLSTest do
888888
end
889889
end
890890

891-
describe "find references" do
892-
@describetag root_paths: ["my_proj"]
893-
setup %{tmp_dir: tmp_dir} do
894-
File.mkdir_p!(Path.join(tmp_dir, "my_proj/lib"))
895-
File.write!(Path.join(tmp_dir, "my_proj/mix.exs"), mix_exs())
896-
[cwd: tmp_dir]
897-
end
898-
899-
setup %{cwd: cwd} do
900-
peace = Path.join(cwd, "my_proj/lib/peace.ex")
901-
902-
File.write!(peace, """
903-
defmodule MyApp.Peace do
904-
def and_love() do
905-
"✌️"
906-
end
907-
end
908-
""")
909-
910-
bar = Path.join(cwd, "my_proj/lib/bar.ex")
911-
912-
File.write!(bar, """
913-
defmodule Bar do
914-
alias MyApp.Peace
915-
def run() do
916-
Peace.and_love()
917-
end
918-
end
919-
""")
920-
921-
[bar: bar, peace: peace]
922-
end
923-
924-
setup :with_lsp
925-
926-
test "list function references", %{client: client, bar: bar, peace: peace} do
927-
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
928-
assert_request(client, "client/registerCapability", fn _params -> nil end)
929-
assert_notification "window/logMessage", %{"message" => "[NextLS] Runtime for folder my_proj is ready..."}
930-
assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"}
931-
932-
request(client, %{
933-
method: "textDocument/references",
934-
id: 4,
935-
jsonrpc: "2.0",
936-
params: %{
937-
position: %{line: 1, character: 6},
938-
textDocument: %{uri: uri(peace)},
939-
context: %{includeDeclaration: true}
940-
}
941-
})
942-
943-
uri = uri(bar)
944-
945-
assert_result 4,
946-
[
947-
%{
948-
"uri" => ^uri,
949-
"range" => %{
950-
"start" => %{"line" => 3, "character" => 10},
951-
"end" => %{"line" => 3, "character" => 18}
952-
}
953-
}
954-
]
955-
end
956-
957-
test "list module references", %{client: client, bar: bar, peace: peace} do
958-
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
959-
assert_request(client, "client/registerCapability", fn _params -> nil end)
960-
assert_notification "window/logMessage", %{"message" => "[NextLS] Runtime for folder my_proj is ready..."}
961-
assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"}
962-
963-
request(client, %{
964-
method: "textDocument/references",
965-
id: 4,
966-
jsonrpc: "2.0",
967-
params: %{
968-
position: %{line: 0, character: 10},
969-
textDocument: %{uri: uri(peace)},
970-
context: %{includeDeclaration: true}
971-
}
972-
})
973-
974-
uri = uri(bar)
975-
976-
assert_result 4,
977-
[
978-
%{
979-
"uri" => ^uri,
980-
"range" => %{
981-
"start" => %{"line" => 3, "character" => 4},
982-
"end" => %{"line" => 3, "character" => 9}
983-
}
984-
}
985-
]
986-
end
987-
end
988-
989891
describe "workspaces" do
990892
setup %{tmp_dir: tmp_dir} do
991893
[cwd: tmp_dir]

0 commit comments

Comments
 (0)