Skip to content

Commit

Permalink
feat(definition): remote function definition (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Jul 3, 2023
1 parent afe2990 commit adbf009
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
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

0 comments on commit adbf009

Please sign in to comment.