Skip to content

Commit

Permalink
fix: compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Mar 9, 2024
1 parent 4abdd29 commit f2bf792
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 23 additions & 4 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ defmodule NextLS do
URI.parse(uri).path,
{position.line + 1, position.character + 1}
) do
{_name, {startl..endl, startc..endc}} ->
{_name, {startl..endl//_, startc..endc//_}} ->
%Location{
uri: "file://#{URI.parse(uri).path}",
range: %Range{
Expand Down Expand Up @@ -316,7 +316,7 @@ defmodule NextLS do
:unknown ->
file
|> NextLS.ASTHelpers.Variables.list_variable_references({line, col})
|> Enum.map(fn {_name, {startl..endl, startc..endc}} ->
|> Enum.map(fn {_name, {startl..endl//_, startc..endc//_}} ->
[file, startl, endl, startc, endc]
end)
end
Expand Down Expand Up @@ -555,6 +555,20 @@ defmodule NextLS do
def handle_request(%TextDocumentCompletion{params: %{text_document: %{uri: uri}, position: position}}, lsp) do
document = lsp.assigns.documents[uri]

env =
document
|> List.update_at(position.line, fn row ->
{front, back} = String.split_at(row, position.character)
String.slice(front, -1..1) <> "__cursor__()" <> back
end)
|> Enum.join("\n")
|> Spitfire.parse(literal_encoder: &{:ok, {:__literal__, &2, [&1]}})
|> then(fn

Check warning on line 566 in lib/next_ls.ex

View workflow job for this annotation

GitHub Actions / dialyzer

unknown_function

Function NextLS.ASTHelpers.Env.build/1 does not exist.
{:ok, ast} -> ast
{:error, ast, _} -> ast
end)
|> NextLS.ASTHelpers.Env.build()

document_slice =
document
|> Enum.take(position.line + 1)
Expand All @@ -571,7 +585,10 @@ defmodule NextLS do
|> dispatch(:runtimes, fn entries ->
[result] =
for {runtime, %{uri: wuri}} <- entries, String.starts_with?(uri, wuri) do
NextLS.Autocomplete.expand(document_slice |> String.to_charlist() |> Enum.reverse(), runtime)
document_slice
|> String.to_charlist()
|> Enum.reverse()

Check warning on line 590 in lib/next_ls.ex

View workflow job for this annotation

GitHub Actions / dialyzer

call_to_missing

Call to missing or private function NextLS.Autocomplete.expand/3.
|> NextLS.Autocomplete.expand(runtime, env)
end

case result do
Expand Down Expand Up @@ -607,12 +624,14 @@ defmodule NextLS do
end)
|> Enum.reverse()

dbg(results)

{:reply, results, lsp}
rescue
e ->
GenLSP.warning(
lsp,
"[Next LS] Failed to run completion request: #{Exception.format_banner(:error, e, __STACKTRACE__)}"
"[Next LS] Failed to run completion request: #{Exception.format(:error, e, __STACKTRACE__)}"
)

{:reply, [], lsp}
Expand Down
4 changes: 2 additions & 2 deletions lib/next_ls/helpers/ast_helpers/variables.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defmodule NextLS.ASTHelpers.Variables do
position =
case symbol do
nil -> position
{_, {line.._, column.._}} -> {line, column}
{_, {line.._//_, column.._//_}} -> {line, column}
end

Enum.reduce(vars, [], fn val, acc ->
Expand Down Expand Up @@ -124,7 +124,7 @@ defmodule NextLS.ASTHelpers.Variables do
{ast, acc}
end

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

0 comments on commit f2bf792

Please sign in to comment.