From d53d8e434b530a08356a5d37f2a9ba3bb770cc51 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 13 Aug 2023 16:56:57 -0400 Subject: [PATCH] chore: add source column to symbols table (#181) --- lib/next_ls.ex | 8 ++++---- lib/next_ls/db/schema.ex | 3 ++- lib/next_ls/runtime.ex | 3 +-- priv/monkey/_next_ls_private_compiler.ex | 1 + test/next_ls/definition_test.exs | 1 + test/next_ls/diagnostics_test.exs | 9 +-------- test/next_ls/workspaces_test.exs | 9 +++++---- test/support/utils.ex | 19 +++++++++++++++++++ 8 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lib/next_ls.ex b/lib/next_ls.ex index 7bbeaf2c..65a51cf9 100644 --- a/lib/next_ls.ex +++ b/lib/next_ls.ex @@ -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 -> @@ -436,7 +436,7 @@ defmodule NextLS do {name, Runtime.compile(pid)} end) - {task.ref, {token, "Compiled!"}} + {task.ref, {token, "Compiled #{name}!"}} end end) @@ -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 -> @@ -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 diff --git a/lib/next_ls/db/schema.ex b/lib/next_ls/db/schema.ex index 4acd07e8..718da6a2 100644 --- a/lib/next_ls/db/schema.ex +++ b/lib/next_ls/db/schema.ex @@ -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 @@ -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 ); """, diff --git a/lib/next_ls/runtime.ex b/lib/next_ls/runtime.ex index 1c974f8e..88f8b8a1 100644 --- a/lib/next_ls/runtime.ex +++ b/lib/next_ls/runtime.ex @@ -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 -> diff --git a/priv/monkey/_next_ls_private_compiler.ex b/priv/monkey/_next_ls_private_compiler.ex index 2a1cdfbb..306dea3a 100644 --- a/priv/monkey/_next_ls_private_compiler.ex +++ b/priv/monkey/_next_ls_private_compiler.ex @@ -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() diff --git a/test/next_ls/definition_test.exs b/test/next_ls/definition_test.exs index 546a3b47..53d860e7 100644 --- a/test/next_ls/definition_test.exs +++ b/test/next_ls/definition_test.exs @@ -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) diff --git a/test/next_ls/diagnostics_test.exs b/test/next_ls/diagnostics_test.exs index 271c5903..8b2a9643 100644 --- a/test/next_ls/diagnostics_test.exs +++ b/test/next_ls/diagnostics_test.exs @@ -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 = diff --git a/test/next_ls/workspaces_test.exs b/test/next_ls/workspaces_test.exs index dcc96894..7401f59c 100644 --- a/test/next_ls/workspaces_test.exs +++ b/test/next_ls/workspaces_test.exs @@ -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", @@ -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"] @@ -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", diff --git a/test/support/utils.ex b/test/support/utils.ex index 2f97db99..bdc76520 100644 --- a/test/support/utils.ex +++ b/test/support/utils.ex @@ -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",