Skip to content

Commit

Permalink
feat(definition): remote function definition
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Jul 3, 2023
1 parent 444a502 commit ddce5bb
Showing 1 changed file with 56 additions and 5 deletions.
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 ddce5bb

Please sign in to comment.