|
| 1 | +defmodule NextLS.SignatureHelpTest do |
| 2 | + use ExUnit.Case, async: true |
| 3 | + |
| 4 | + import GenLSP.Test |
| 5 | + import NextLS.Support.Utils |
| 6 | + |
| 7 | + @moduletag :tmp_dir |
| 8 | + |
| 9 | + describe "function" do |
| 10 | + @describetag root_paths: ["my_proj"] |
| 11 | + setup %{tmp_dir: tmp_dir} do |
| 12 | + File.mkdir_p!(Path.join(tmp_dir, "my_proj/lib")) |
| 13 | + File.write!(Path.join(tmp_dir, "my_proj/mix.exs"), mix_exs()) |
| 14 | + [cwd: tmp_dir] |
| 15 | + end |
| 16 | + |
| 17 | + setup %{cwd: cwd} do |
| 18 | + remote = Path.join(cwd, "my_proj/lib/remote.ex") |
| 19 | + |
| 20 | + File.write!(remote, """ |
| 21 | + defmodule Remote do |
| 22 | + def bang!(bang) do |
| 23 | + bang |
| 24 | + end |
| 25 | + end |
| 26 | + """) |
| 27 | + |
| 28 | + imported = Path.join(cwd, "my_proj/lib/imported.ex") |
| 29 | + |
| 30 | + File.write!(imported, """ |
| 31 | + defmodule Imported do |
| 32 | + def boom(boom1, _boom2) do |
| 33 | + boom1 |
| 34 | + end |
| 35 | + end |
| 36 | + """) |
| 37 | + |
| 38 | + bar = Path.join(cwd, "my_proj/lib/bar.ex") |
| 39 | + |
| 40 | + File.write!(bar, """ |
| 41 | + defmodule Bar do |
| 42 | + def run() do |
| 43 | + Remote.bang!() |
| 44 | + end |
| 45 | + end |
| 46 | + """) |
| 47 | + |
| 48 | + [bar: bar, imported: imported, remote: remote] |
| 49 | + end |
| 50 | + |
| 51 | + setup :with_lsp |
| 52 | + |
| 53 | + test "get signature help", %{client: client, bar: bar} = context do |
| 54 | + assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}}) |
| 55 | + |
| 56 | + assert_is_ready(context, "my_proj") |
| 57 | + assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}} |
| 58 | + |
| 59 | + uri = uri(bar) |
| 60 | + |
| 61 | + request(client, %{ |
| 62 | + method: "textDocument/signatureHelp", |
| 63 | + id: 4, |
| 64 | + jsonrpc: "2.0", |
| 65 | + params: %{ |
| 66 | + position: %{line: 3, character: 16}, |
| 67 | + textDocument: %{uri: uri} |
| 68 | + } |
| 69 | + }) |
| 70 | + |
| 71 | + assert_result 4, %{ |
| 72 | + "activeParameter" => 0, |
| 73 | + "activeSignature" => 0, |
| 74 | + "signatures" => [ |
| 75 | + %{ |
| 76 | + "activeParameter" => 0, |
| 77 | + "parameters" => [ |
| 78 | + %{"label" => "bang"} |
| 79 | + ], |
| 80 | + "documentation" => "need help", |
| 81 | + "label" => "bang!" |
| 82 | + } |
| 83 | + ] |
| 84 | + } |
| 85 | + end |
| 86 | + |
| 87 | + test "get signature help 2", %{client: client, bar: bar} = context do |
| 88 | + assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}}) |
| 89 | + |
| 90 | + assert_is_ready(context, "my_proj") |
| 91 | + assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}} |
| 92 | + |
| 93 | + uri = uri(bar) |
| 94 | + |
| 95 | + request(client, %{ |
| 96 | + method: "textDocument/signatureHelp", |
| 97 | + id: 4, |
| 98 | + jsonrpc: "2.0", |
| 99 | + params: %{ |
| 100 | + position: %{line: 8, character: 10}, |
| 101 | + textDocument: %{uri: uri} |
| 102 | + } |
| 103 | + }) |
| 104 | + |
| 105 | + assert_result 4, %{ |
| 106 | + "activeParameter" => 0, |
| 107 | + "activeSignature" => 0, |
| 108 | + "signatures" => [ |
| 109 | + %{ |
| 110 | + "activeParameter" => 0, |
| 111 | + "parameters" => [ |
| 112 | + %{"label" => "bang"} |
| 113 | + ], |
| 114 | + "documentation" => "need help", |
| 115 | + "label" => "bang!" |
| 116 | + } |
| 117 | + ] |
| 118 | + } |
| 119 | + end |
| 120 | + end |
| 121 | +end |
0 commit comments