Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(definition): remote function definition #80

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion test/next_ls/symbol_table_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ defmodule NextLS.SymbolTableTest do

setup %{tmp_dir: dir} do
File.mkdir_p!(dir)
pid = start_supervised!({SymbolTable, [path: dir]})

# this fails with `{:error, incompatible_arguments}` on CI a lot, and I have no idea why
pid =
try do
start_supervised!({SymbolTable, [path: dir]})
rescue
_ ->
Process.sleep(250)
start_supervised!({SymbolTable, [path: dir]})
end

Process.link(pid)
[pid: pid, dir: dir]
Expand Down
61 changes: 56 additions & 5 deletions test/next_ls_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ defmodule NextLSTest do

describe "two" do
setup %{cwd: cwd} do
remote = Path.join(cwd, "lib/remote.ex")

File.write!(remote, """
defmodule Remote do
def bang!() do
"‼️"
end
end
""")

imported = Path.join(cwd, "lib/imported.ex")

File.write!(imported, """
Expand All @@ -484,6 +494,7 @@ defmodule NextLSTest do
defmodule Foo do
import Imported
def run() do
Remote.bang!()
process()
end
Expand All @@ -494,7 +505,7 @@ defmodule NextLSTest do
end
""")

[bar: bar, imported: imported]
[bar: bar, imported: imported, remote: remote]
end

setup :with_lsp
Expand All @@ -517,19 +528,19 @@ defmodule NextLSTest do
id: 4,
jsonrpc: "2.0",
params: %{
position: %{line: 3, character: 6},
position: %{line: 4, character: 6},
textDocument: %{uri: uri}
}
})

assert_result 4, %{
"range" => %{
"start" => %{
"line" => 6,
"line" => 7,
"character" => 0
},
"end" => %{
"line" => 6,
"line" => 7,
"character" => 0
}
},
Expand All @@ -555,7 +566,7 @@ defmodule NextLSTest do
id: 4,
jsonrpc: "2.0",
params: %{
position: %{line: 7, character: 5},
position: %{line: 8, character: 5},
textDocument: %{uri: uri}
}
})
Expand All @@ -576,6 +587,46 @@ defmodule NextLSTest do
"uri" => ^uri
}
end

test "go to remote function definition", %{client: client, bar: bar, remote: remote} do
assert :ok ==
notify(client, %{
method: "initialized",
jsonrpc: "2.0",
params: %{}
})

assert_notification "window/logMessage", %{"message" => "[NextLS] Runtime ready..."}
assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"}

uri = uri(bar)

request(client, %{
method: "textDocument/definition",
id: 4,
jsonrpc: "2.0",
params: %{
position: %{line: 3, character: 12},
textDocument: %{uri: uri}
}
})

uri = uri(remote)

assert_result 4, %{
"range" => %{
"start" => %{
"line" => 1,
"character" => 0
},
"end" => %{
"line" => 1,
"character" => 0
}
},
"uri" => ^uri
}
end
end

defp with_lsp(%{tmp_dir: tmp_dir}) do
Expand Down
Loading