Skip to content

Commit

Permalink
refactor: get rid of DB.symbols/1
Browse files Browse the repository at this point in the history
  • Loading branch information
dvic committed Aug 14, 2023
1 parent 5ea9bac commit 5ddfac7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
26 changes: 25 additions & 1 deletion lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,33 @@ defmodule NextLS do
end
end

symbols = fn pid ->
rows =
DB.query(
pid,
~Q"""
SELECT *
FROM symbols
WHERE source = 'user';
""",
[]
)

for [_pk, module, file, type, name, line, column | _] <- rows do
%{
module: module,
file: file,
type: type,
name: name,
line: line,
column: column
}
end
end

symbols =
dispatch(lsp.assigns.registry, :databases, fn entries ->
for {pid, _} <- entries, symbol <- DB.symbols(pid), filter.(symbol.name) do
for {pid, _} <- entries, symbol <- symbols.(pid), filter.(symbol.name) do
name =
if symbol.type != "defstruct" do
"#{symbol.type} #{symbol.name}"
Expand Down
30 changes: 0 additions & 30 deletions lib/next_ls/db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ defmodule NextLS.DB do
@spec query(pid(), query(), list()) :: list()
def query(server, query, args \\ []), do: GenServer.call(server, {:query, query, args}, :infinity)

@spec symbols(pid()) :: list(map())
def symbols(server), do: GenServer.call(server, :symbols, :infinity)

@spec insert_symbol(pid(), map()) :: :ok
def insert_symbol(server, payload), do: GenServer.cast(server, {:insert_symbol, payload})

Expand Down Expand Up @@ -51,33 +48,6 @@ defmodule NextLS.DB do
{:reply, rows, s}
end

def handle_call(:symbols, _from, %{conn: conn} = s) do
rows =
__query__(
{conn, s.logger},
~Q"""
SELECT *
FROM symbols
WHERE source = 'user';
""",
[]
)

symbols =
for [_pk, module, file, type, name, line, column | _] <- rows do
%{
module: module,
file: file,
type: type,
name: name,
line: line,
column: column
}
end

{:reply, symbols, s}
end

def handle_cast({:insert_symbol, symbol}, %{conn: conn} = s) do
{:message_queue_len, count} = Process.info(self(), :message_queue_len)
NextLS.DB.Activity.update(s.activity, count)
Expand Down

0 comments on commit 5ddfac7

Please sign in to comment.