diff --git a/lib/next_ls.ex b/lib/next_ls.ex index e695416a..d36cb2e8 100644 --- a/lib/next_ls.ex +++ b/lib/next_ls.ex @@ -558,16 +558,16 @@ defmodule NextLS do {:reply, nil, lsp} _ -> - GenLSP.warning(lsp, "[Next LS] Failed to format the file: #{uri}") + NextLS.Logger.warning(lsp.assigns.logger, "Failed to format the file: #{uri}") {:reply, nil, lsp} end end end) else - GenLSP.warning( - lsp, - "[Next LS] The file #{uri} was not found in the server's process state. Something must have gone wrong when opening, changing, or saving the file." + NextLS.Logger.warning( + lsp.assigns.logger, + "The file #{uri} was not found in the server's process state. Something must have gone wrong when opening, changing, or saving the file." ) [{:reply, nil, lsp}] @@ -717,9 +717,9 @@ defmodule NextLS do {:reply, results, lsp} rescue e -> - GenLSP.warning( - lsp, - "[Next LS] Failed to run completion request: #{Exception.format(:error, e, __STACKTRACE__)}" + NextLS.Logger.warning( + lsp.assigns.logger, + "Failed to run completion request: #{Exception.format(:error, e, __STACKTRACE__)}" ) {:reply, [], lsp} @@ -812,7 +812,7 @@ defmodule NextLS do end def handle_request(%{method: method}, lsp) do - GenLSP.warning(lsp, "[Next LS] Method Not Found: #{method}") + NextLS.Logger.warning(lsp.assigns.logger, "Method Not Found: #{method}") {:reply, %ErrorResponse{ @@ -823,7 +823,8 @@ defmodule NextLS do @impl true def handle_notification(%Initialized{}, lsp) do - GenLSP.log(lsp, "[Next LS] NextLS v#{version()} has initialized!") + NextLS.Logger.log(lsp.assigns.logger, "NextLS v#{version()} has initialized!") + NextLS.Logger.log(lsp.assigns.logger, "Log file located at #{Path.join(File.cwd!(), ".elixir-tools/next-ls.log")}") with opts when is_list(opts) <- lsp.assigns.auto_update do {:ok, _} = @@ -875,7 +876,7 @@ defmodule NextLS do end NextLS.Runtime.BundledElixir.install(lsp.assigns.bundle_base, lsp.assigns.logger) - GenLSP.log(lsp, "[Next LS] Booting runtimes...") + NextLS.Logger.log(lsp.assigns.logger, "Booting runtimes...") parent = self() @@ -917,7 +918,7 @@ defmodule NextLS do on_initialized: fn status -> if status == :ready do Progress.stop(lsp, token, "NextLS runtime for folder #{name} has initialized!") - GenLSP.log(lsp, "[Next LS] Runtime for folder #{name} is ready...") + NextLS.Logger.log(lsp.assigns.logger, "Runtime for folder #{name} is ready...") msg = {:runtime_ready, name, self()} @@ -931,7 +932,7 @@ defmodule NextLS do send(parent, {:runtime_failed, name, status}) - GenLSP.error(lsp, "[Next LS] Runtime for folder #{name} failed to initialize") + NextLS.Logger.error(lsp.assigns.logger, "Runtime for folder #{name} failed to initialize") end end, logger: lsp.assigns.logger @@ -1015,7 +1016,7 @@ defmodule NextLS do names = Enum.map(entries, fn {_, %{name: name}} -> name end) for %{name: name, uri: uri} <- added, name not in names do - GenLSP.log(lsp, "[Next LS] Adding workspace folder #{name}") + NextLS.Logger.log(lsp.assigns.logger, "Adding workspace folder #{name}") token = Progress.token() Progress.start(lsp, token, "Initializing NextLS runtime for folder #{name}...") parent = self() @@ -1039,7 +1040,7 @@ defmodule NextLS do on_initialized: fn status -> if status == :ready do Progress.stop(lsp, token, "NextLS runtime for folder #{name} has initialized!") - GenLSP.log(lsp, "[Next LS] Runtime for folder #{name} is ready...") + NextLS.Logger.log(lsp.assigns.logger, "Runtime for folder #{name} is ready...") msg = {:runtime_ready, name, self()} @@ -1053,7 +1054,7 @@ defmodule NextLS do send(parent, {:runtime_failed, name, status}) - GenLSP.error(lsp, "[Next LS] Runtime for folder #{name} failed to initialize") + NextLS.Logger.error(lsp.assigns.logger, "Runtime for folder #{name} failed to initialize") end end, logger: lsp.assigns.logger @@ -1064,7 +1065,7 @@ defmodule NextLS do names = Enum.map(removed, & &1.name) for {pid, %{name: name}} <- entries, name in names do - GenLSP.log(lsp, "[Next LS] Removing workspace folder #{name}") + NextLS.Logger.log(lsp.assigns.logger, "Removing workspace folder #{name}") NextLS.Runtime.stop(lsp.assigns.dynamic_supervisor, pid) end end) @@ -1224,7 +1225,7 @@ defmodule NextLS do :ok = DynamicSupervisor.terminate_child(lsp.assigns.dynamic_supervisor, pid) - if status == {:error, :deps} do + if status == {:error, :deps} && lsp.assigns.client_capabilities.window.show_message do resp = GenLSP.request( lsp, @@ -1281,6 +1282,10 @@ defmodule NextLS do _ -> NextLS.Logger.info(lsp.assigns.logger, "Not running `mix deps.get`") end + else + unless lsp.assigns.client_capabilities.window.show_message do + NextLS.Logger.info(lsp.assigns.logger, "Client does not support window/showMessageRequest") + end end {:noreply, lsp} @@ -1298,8 +1303,8 @@ defmodule NextLS do end def handle_info(message, lsp) do - GenLSP.log(lsp, "[Next LS] Unhandled message: #{inspect(message)}") - GenLSP.log(lsp, "[Next LS] process assigns=#{inspect(lsp.assigns)}") + NextLS.Logger.log(lsp.assigns.logger, "Unhandled message: #{inspect(message)}") + NextLS.Logger.log(lsp.assigns.logger, "process assigns=#{inspect(lsp.assigns)}") {:noreply, lsp} end diff --git a/lib/next_ls/progress.ex b/lib/next_ls/progress.ex index a7485635..45709f6b 100644 --- a/lib/next_ls/progress.ex +++ b/lib/next_ls/progress.ex @@ -1,11 +1,9 @@ defmodule NextLS.Progress do @moduledoc false - @env Mix.env() + def start(lsp, token, msg) do Task.start(fn -> - # FIXME: gen_lsp should allow stubbing requests so we don't have to - # set this in every test. For now, don't send it in the test env - if @env != :test do + if lsp.assigns.client_capabilities.window.work_done_progress do GenLSP.request(lsp, %GenLSP.Requests.WindowWorkDoneProgressCreate{ id: System.unique_integer([:positive]), params: %GenLSP.Structures.WorkDoneProgressCreateParams{ diff --git a/lib/next_ls/runtime.ex b/lib/next_ls/runtime.ex index 87cc5f1e..e3a101f6 100644 --- a/lib/next_ls/runtime.ex +++ b/lib/next_ls/runtime.ex @@ -130,9 +130,17 @@ defmodule NextLS.Runtime do |> String.to_charlist() bindir = System.get_env("BINDIR") + NextLS.Logger.log(logger, "BINDIR=#{bindir}") path = System.get_env("PATH") - new_path = String.replace(path, bindir <> ":", "") - new_path = elixir_bin_path <> ":" <> new_path + NextLS.Logger.log(logger, "before PATH=#{path}") + path_minus_bindir = String.replace(path, bindir <> ":", "") + NextLS.Logger.log(logger, "after1 PATH=#{path_minus_bindir}") + + path_minus_bindir2 = path_minus_bindir |> String.split(":") |> List.delete(bindir) |> Enum.join(":") + NextLS.Logger.log(logger, "after2 PATH=#{path_minus_bindir2}") + + new_path = elixir_bin_path <> ":" <> path_minus_bindir2 + NextLS.Logger.log(logger, "after3 PATH=#{new_path}") with dir when is_list(dir) <- :code.priv_dir(:next_ls) do exe = diff --git a/test/support/utils.ex b/test/support/utils.ex index c470c3f7..882026ef 100644 --- a/test/support/utils.ex +++ b/test/support/utils.ex @@ -90,6 +90,10 @@ defmodule NextLS.Support.Utils do capabilities: %{ workspace: %{ workspaceFolders: true + }, + window: %{ + work_done_progress: false, + showMessage: %{} } }, workspaceFolders: