Skip to content

Commit

Permalink
fix: coalesce nil start line to 1
Browse files Browse the repository at this point in the history
Fixes #160
  • Loading branch information
dvic committed Aug 14, 2023
1 parent d53d8e4 commit c98fec1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/next_ls/db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ defmodule NextLS.DB do
module: module
} = reference

line = meta[:line] || 0
col = meta[:column] || 0

{{start_line, start_column}, {end_line, end_column}} =
{{meta[:line], col},
{meta[:line], col + String.length(identifier |> to_string() |> String.replace("Elixir.", ""))}}
{start_line, start_column} = {line, col}
{end_line, end_column} = {line, line + String.length(identifier |> to_string() |> String.replace("Elixir.", ""))}

__query__(
{conn, s.logger},
Expand Down
9 changes: 9 additions & 0 deletions lib/next_ls/runtime/sidecar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ defmodule NextLS.Runtime.Sidecar do
end

def handle_info({:tracer, payload}, state) do
payload = replace_nil(payload, :start_line, 1)
DB.insert_symbol(state.db, payload)

{:noreply, state}
end

def handle_info({{:tracer, :reference}, payload}, state) do
payload = replace_nil(payload, :start_line, 1)
DB.insert_reference(state.db, payload)

{:noreply, state}
end

defp replace_nil(data, field, replacement) do
case data do
%{^field => nil} -> %{data | field => replacement}
%{} -> data
end
end
end

0 comments on commit c98fec1

Please sign in to comment.