Skip to content

Commit 042435d

Browse files
committed
fix: use lsp.assings.documents
1 parent 5c270e0 commit 042435d

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

lib/next_ls.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,10 @@ defmodule NextLS do
828828
%TextDocumentSignatureHelp{params: %SignatureHelpParams{text_document: %{uri: uri}, position: position}},
829829
lsp
830830
) do
831+
text = Enum.join(lsp.assigns.documents[uri], "\n")
832+
831833
signature_help =
832-
case SignatureHelp.fetch_mod_and_name(uri, {position.line + 1, position.character + 1}) do
834+
case SignatureHelp.fetch_mod_and_name(text, {position.line + 1, position.character + 1}) do
833835
{:ok, {mod, name}} ->
834836
docs =
835837
dispatch(lsp.assigns.registry, :runtimes, fn entries ->

lib/next_ls/signature_help.ex

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ defmodule NextLS.SignatureHelp do
88
alias GenLSP.Structures.SignatureInformation
99
alias NextLS.ASTHelpers
1010

11-
def fetch_mod_and_name(uri, position) do
12-
with {:ok, text} <- File.read(URI.parse(uri).path),
13-
ast =
14-
text
15-
|> Spitfire.parse(literal_encoder: &{:ok, {:__literal__, &2, [&1]}})
16-
|> then(fn
17-
{:ok, ast} -> ast
18-
{:error, ast, _} -> ast
19-
end),
20-
{:ok, result} <- ASTHelpers.Function.find_remote_function_call_within(ast, position) do
11+
def fetch_mod_and_name(text, position) do
12+
ast =
13+
text
14+
|> Spitfire.parse(literal_encoder: &{:ok, {:__literal__, &2, [&1]}})
15+
|> then(fn
16+
{:ok, ast} -> ast
17+
{:error, ast, _} -> ast
18+
end)
19+
20+
with {:ok, result} <- ASTHelpers.Function.find_remote_function_call_within(ast, position) do
2121
case result do
2222
{{:., _, [{:__aliases__, _, modules}, name]}, _, _} -> {:ok, {Module.concat(modules), name}}
2323
end

test/next_ls/signature_help_test.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ defmodule NextLS.SignatureHelpTest do
101101
test "get signature help", %{client: client, bar: bar} do
102102
uri = uri(bar)
103103

104+
did_open(client, bar, File.read!(bar))
105+
did_change(client, uri)
106+
104107
request(client, %{
105108
method: "textDocument/signatureHelp",
106109
id: 4,
@@ -130,6 +133,9 @@ defmodule NextLS.SignatureHelpTest do
130133
test "get signature help with multiple params", %{client: client, bar: bar} do
131134
uri = uri(bar)
132135

136+
did_open(client, bar, File.read!(bar))
137+
did_change(client, uri)
138+
133139
request(client, %{
134140
method: "textDocument/signatureHelp",
135141
id: 4,
@@ -156,6 +162,9 @@ defmodule NextLS.SignatureHelpTest do
156162
test "get signature help with parameters on multiple lines", %{client: client, bar: bar} do
157163
uri = uri(bar)
158164

165+
did_open(client, bar, File.read!(bar))
166+
did_change(client, uri)
167+
159168
request(client, %{
160169
method: "textDocument/signatureHelp",
161170
id: 4,

test/support/utils.ex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,21 @@ defmodule NextLS.Support.Utils do
172172
})
173173
end
174174
end
175+
176+
defmacro did_change(client, uri) do
177+
quote do
178+
assert :ok == notify(unquote(client), %{
179+
method: "workspace/didChangeWatchedFiles",
180+
jsonrpc: "2.0",
181+
params: %{
182+
changes: [
183+
%{
184+
type: GenLSP.Enumerations.FileChangeType.changed(),
185+
uri: unquote(uri)
186+
}
187+
]
188+
}
189+
})
190+
end
191+
end
175192
end

0 commit comments

Comments
 (0)