Skip to content

Commit f2bf792

Browse files
committed
fix: compiler warnings
1 parent 4abdd29 commit f2bf792

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

lib/next_ls.ex

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ defmodule NextLS do
198198
URI.parse(uri).path,
199199
{position.line + 1, position.character + 1}
200200
) do
201-
{_name, {startl..endl, startc..endc}} ->
201+
{_name, {startl..endl//_, startc..endc//_}} ->
202202
%Location{
203203
uri: "file://#{URI.parse(uri).path}",
204204
range: %Range{
@@ -316,7 +316,7 @@ defmodule NextLS do
316316
:unknown ->
317317
file
318318
|> NextLS.ASTHelpers.Variables.list_variable_references({line, col})
319-
|> Enum.map(fn {_name, {startl..endl, startc..endc}} ->
319+
|> Enum.map(fn {_name, {startl..endl//_, startc..endc//_}} ->
320320
[file, startl, endl, startc, endc]
321321
end)
322322
end
@@ -555,6 +555,20 @@ defmodule NextLS do
555555
def handle_request(%TextDocumentCompletion{params: %{text_document: %{uri: uri}, position: position}}, lsp) do
556556
document = lsp.assigns.documents[uri]
557557

558+
env =
559+
document
560+
|> List.update_at(position.line, fn row ->
561+
{front, back} = String.split_at(row, position.character)
562+
String.slice(front, -1..1) <> "__cursor__()" <> back
563+
end)
564+
|> Enum.join("\n")
565+
|> Spitfire.parse(literal_encoder: &{:ok, {:__literal__, &2, [&1]}})
566+
|> then(fn
567+
{:ok, ast} -> ast
568+
{:error, ast, _} -> ast
569+
end)
570+
|> NextLS.ASTHelpers.Env.build()
571+
558572
document_slice =
559573
document
560574
|> Enum.take(position.line + 1)
@@ -571,7 +585,10 @@ defmodule NextLS do
571585
|> dispatch(:runtimes, fn entries ->
572586
[result] =
573587
for {runtime, %{uri: wuri}} <- entries, String.starts_with?(uri, wuri) do
574-
NextLS.Autocomplete.expand(document_slice |> String.to_charlist() |> Enum.reverse(), runtime)
588+
document_slice
589+
|> String.to_charlist()
590+
|> Enum.reverse()
591+
|> NextLS.Autocomplete.expand(runtime, env)
575592
end
576593

577594
case result do
@@ -607,12 +624,14 @@ defmodule NextLS do
607624
end)
608625
|> Enum.reverse()
609626

627+
dbg(results)
628+
610629
{:reply, results, lsp}
611630
rescue
612631
e ->
613632
GenLSP.warning(
614633
lsp,
615-
"[Next LS] Failed to run completion request: #{Exception.format_banner(:error, e, __STACKTRACE__)}"
634+
"[Next LS] Failed to run completion request: #{Exception.format(:error, e, __STACKTRACE__)}"
616635
)
617636

618637
{:reply, [], lsp}

lib/next_ls/helpers/ast_helpers/variables.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ defmodule NextLS.ASTHelpers.Variables do
6464
position =
6565
case symbol do
6666
nil -> position
67-
{_, {line.._, column.._}} -> {line, column}
67+
{_, {line.._//_, column.._//_}} -> {line, column}
6868
end
6969

7070
Enum.reduce(vars, [], fn val, acc ->
@@ -124,7 +124,7 @@ defmodule NextLS.ASTHelpers.Variables do
124124
{ast, acc}
125125
end
126126

127-
# search symbols inside left side of a match or <- and fix processig sequence
127+
# search symbols inside left side of a match or <- and fix processing sequence
128128
defp prewalk({operation, meta, [left, right]}, acc) when operation in [:=, :<-, :destructure] do
129129
acc = find_symbols(left, acc)
130130
{{operation, meta, [right, left]}, acc}

0 commit comments

Comments
 (0)