Skip to content

Commit

Permalink
chore: add source column to symbols table (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Aug 13, 2023
1 parent 13670a5 commit d53d8e4
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 19 deletions.
8 changes: 4 additions & 4 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ defmodule NextLS do
dispatch(lsp.assigns.registry, :runtimes, fn entries ->
for {pid, %{name: name, uri: wuri, db: db}} <- entries, String.starts_with?(uri, wuri), into: %{} do
token = Progress.token()
Progress.start(lsp, token, "Compiling...")
Progress.start(lsp, token, "Compiling #{name}...")

task =
Task.Supervisor.async_nolink(lsp.assigns.task_supervisor, fn ->
Expand All @@ -436,7 +436,7 @@ defmodule NextLS do
{name, Runtime.compile(pid)}
end)

{task.ref, {token, "Compiled!"}}
{task.ref, {token, "Compiled #{name}!"}}
end
end)

Expand Down Expand Up @@ -593,7 +593,7 @@ defmodule NextLS do

def handle_info({:runtime_ready, name, runtime_pid}, lsp) do
token = Progress.token()
Progress.start(lsp, token, "Compiling...")
Progress.start(lsp, token, "Compiling #{name}...")

task =
Task.Supervisor.async_nolink(lsp.assigns.task_supervisor, fn ->
Expand All @@ -605,7 +605,7 @@ defmodule NextLS do
{name, Runtime.compile(runtime_pid, force: mode == :reindex)}
end)

refresh_refs = Map.put(lsp.assigns.refresh_refs, task.ref, {token, "Compiled!"})
refresh_refs = Map.put(lsp.assigns.refresh_refs, task.ref, {token, "Compiled #{name}!"})

{:noreply, assign(lsp, ready: true, refresh_refs: refresh_refs)}
end
Expand Down
3 changes: 2 additions & 1 deletion lib/next_ls/db/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule NextLS.DB.Schema do

alias NextLS.DB

@version 2
@version 3

def init(conn) do
# FIXME: this is odd tech debt. not a big deal but is confusing
Expand Down Expand Up @@ -74,6 +74,7 @@ defmodule NextLS.DB.Schema do
name text NOT NULL,
line integer NOT NULL,
column integer NOT NULL,
source text NOT NULL DEFAULT 'user',
inserted_at text NOT NULL DEFAULT CURRENT_TIMESTAMP
);
""",
Expand Down
3 changes: 1 addition & 2 deletions lib/next_ls/runtime.ex
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,12 @@ defmodule NextLS.Runtime do
|> tap(fn
{:badrpc, error} ->
NextLS.Logger.error(logger, "Bad RPC call to node #{node}: #{inspect(error)}")
send(me, {:cancel, error})

_ ->
:ok
end)

:rpc.call(node, Code, :put_compiler_option, [:parser_options, [columns: true, token_metadata: true]])

send(me, {:node, node})
else
error ->
Expand Down
1 change: 1 addition & 0 deletions priv/monkey/_next_ls_private_compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ defmodule :_next_ls_private_compiler do
def compile do
# keep stdout on this node
Process.group_leader(self(), Process.whereis(:user))
Code.put_compiler_option(:parser_options, columns: true, token_metadata: true)

Mix.Task.clear()

Expand Down
1 change: 1 addition & 0 deletions test/next_ls/definition_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ defmodule NextLS.DefinitionTest do
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_compiled(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}

uri = uri(bar)
Expand Down
9 changes: 1 addition & 8 deletions test/next_ls/diagnostics_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,7 @@ defmodule NextLS.DiagnosticsTest do
}
}

assert_notification "$/progress", %{"value" => %{"kind" => "begin", "title" => "Compiling..."}}

assert_notification "$/progress", %{
"value" => %{
"kind" => "end",
"message" => "Compiled!"
}
}
assert_compiled(context, "my_proj")

for file <- ["bar.ex"] do
uri =
Expand Down
9 changes: 5 additions & 4 deletions test/next_ls/workspaces_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule NextLS.WorkspacesTest do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)
assert_is_ready(context, "proj_one")
assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"}
assert_compiled(context, "proj_one")

notify(client, %{
method: "workspace/didChangeWorkspaceFolders",
Expand All @@ -64,7 +64,7 @@ defmodule NextLS.WorkspacesTest do
})

assert_is_ready(context, "proj_two")
assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"}
assert_compiled(context, "proj_two")
end

@tag root_paths: ["proj_one", "proj_two"]
Expand All @@ -73,8 +73,9 @@ defmodule NextLS.WorkspacesTest do
assert_request(client, "client/registerCapability", fn _params -> nil end)
assert_is_ready(context, "proj_one")
assert_is_ready(context, "proj_two")
assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"}
assert_notification "window/logMessage", %{"message" => "[NextLS] Compiled!"}

assert_compiled(context, "proj_one")
assert_compiled(context, "proj_two")

notify(client, %{
method: "workspace/didChangeWorkspaceFolders",
Expand Down
19 changes: 19 additions & 0 deletions test/support/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ defmodule NextLS.Support.Utils do
end
end

defmacro assert_compiled(
context,
name,
timeout \\ Application.get_env(:ex_unit, :assert_receive_timeout)
) do
quote do
message = "Compiled #{unquote(context).module}-#{unquote(name)}!"

assert_notification "$/progress",
%{
"value" => %{
"kind" => "end",
"message" => ^message
}
},
unquote(timeout)
end
end

def uri(path) when is_binary(path) do
URI.to_string(%URI{
scheme: "file",
Expand Down

0 comments on commit d53d8e4

Please sign in to comment.