Skip to content

Commit 535d0ee

Browse files
authored
fix: respect client capabilities (#469)
fix: use unified logger in more places
1 parent 30c8e0c commit 535d0ee

File tree

4 files changed

+40
-25
lines changed

4 files changed

+40
-25
lines changed

lib/next_ls.ex

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,16 @@ defmodule NextLS do
558558
{:reply, nil, lsp}
559559

560560
_ ->
561-
GenLSP.warning(lsp, "[Next LS] Failed to format the file: #{uri}")
561+
NextLS.Logger.warning(lsp.assigns.logger, "Failed to format the file: #{uri}")
562562

563563
{:reply, nil, lsp}
564564
end
565565
end
566566
end)
567567
else
568-
GenLSP.warning(
569-
lsp,
570-
"[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."
568+
NextLS.Logger.warning(
569+
lsp.assigns.logger,
570+
"The file #{uri} was not found in the server's process state. Something must have gone wrong when opening, changing, or saving the file."
571571
)
572572

573573
[{:reply, nil, lsp}]
@@ -717,9 +717,9 @@ defmodule NextLS do
717717
{:reply, results, lsp}
718718
rescue
719719
e ->
720-
GenLSP.warning(
721-
lsp,
722-
"[Next LS] Failed to run completion request: #{Exception.format(:error, e, __STACKTRACE__)}"
720+
NextLS.Logger.warning(
721+
lsp.assigns.logger,
722+
"Failed to run completion request: #{Exception.format(:error, e, __STACKTRACE__)}"
723723
)
724724

725725
{:reply, [], lsp}
@@ -812,7 +812,7 @@ defmodule NextLS do
812812
end
813813

814814
def handle_request(%{method: method}, lsp) do
815-
GenLSP.warning(lsp, "[Next LS] Method Not Found: #{method}")
815+
NextLS.Logger.warning(lsp.assigns.logger, "Method Not Found: #{method}")
816816

817817
{:reply,
818818
%ErrorResponse{
@@ -823,7 +823,8 @@ defmodule NextLS do
823823

824824
@impl true
825825
def handle_notification(%Initialized{}, lsp) do
826-
GenLSP.log(lsp, "[Next LS] NextLS v#{version()} has initialized!")
826+
NextLS.Logger.log(lsp.assigns.logger, "NextLS v#{version()} has initialized!")
827+
NextLS.Logger.log(lsp.assigns.logger, "Log file located at #{Path.join(File.cwd!(), ".elixir-tools/next-ls.log")}")
827828

828829
with opts when is_list(opts) <- lsp.assigns.auto_update do
829830
{:ok, _} =
@@ -875,7 +876,7 @@ defmodule NextLS do
875876
end
876877

877878
NextLS.Runtime.BundledElixir.install(lsp.assigns.bundle_base, lsp.assigns.logger)
878-
GenLSP.log(lsp, "[Next LS] Booting runtimes...")
879+
NextLS.Logger.log(lsp.assigns.logger, "Booting runtimes...")
879880

880881
parent = self()
881882

@@ -917,7 +918,7 @@ defmodule NextLS do
917918
on_initialized: fn status ->
918919
if status == :ready do
919920
Progress.stop(lsp, token, "NextLS runtime for folder #{name} has initialized!")
920-
GenLSP.log(lsp, "[Next LS] Runtime for folder #{name} is ready...")
921+
NextLS.Logger.log(lsp.assigns.logger, "Runtime for folder #{name} is ready...")
921922

922923
msg = {:runtime_ready, name, self()}
923924

@@ -931,7 +932,7 @@ defmodule NextLS do
931932

932933
send(parent, {:runtime_failed, name, status})
933934

934-
GenLSP.error(lsp, "[Next LS] Runtime for folder #{name} failed to initialize")
935+
NextLS.Logger.error(lsp.assigns.logger, "Runtime for folder #{name} failed to initialize")
935936
end
936937
end,
937938
logger: lsp.assigns.logger
@@ -1015,7 +1016,7 @@ defmodule NextLS do
10151016
names = Enum.map(entries, fn {_, %{name: name}} -> name end)
10161017

10171018
for %{name: name, uri: uri} <- added, name not in names do
1018-
GenLSP.log(lsp, "[Next LS] Adding workspace folder #{name}")
1019+
NextLS.Logger.log(lsp.assigns.logger, "Adding workspace folder #{name}")
10191020
token = Progress.token()
10201021
Progress.start(lsp, token, "Initializing NextLS runtime for folder #{name}...")
10211022
parent = self()
@@ -1039,7 +1040,7 @@ defmodule NextLS do
10391040
on_initialized: fn status ->
10401041
if status == :ready do
10411042
Progress.stop(lsp, token, "NextLS runtime for folder #{name} has initialized!")
1042-
GenLSP.log(lsp, "[Next LS] Runtime for folder #{name} is ready...")
1043+
NextLS.Logger.log(lsp.assigns.logger, "Runtime for folder #{name} is ready...")
10431044

10441045
msg = {:runtime_ready, name, self()}
10451046

@@ -1053,7 +1054,7 @@ defmodule NextLS do
10531054

10541055
send(parent, {:runtime_failed, name, status})
10551056

1056-
GenLSP.error(lsp, "[Next LS] Runtime for folder #{name} failed to initialize")
1057+
NextLS.Logger.error(lsp.assigns.logger, "Runtime for folder #{name} failed to initialize")
10571058
end
10581059
end,
10591060
logger: lsp.assigns.logger
@@ -1064,7 +1065,7 @@ defmodule NextLS do
10641065
names = Enum.map(removed, & &1.name)
10651066

10661067
for {pid, %{name: name}} <- entries, name in names do
1067-
GenLSP.log(lsp, "[Next LS] Removing workspace folder #{name}")
1068+
NextLS.Logger.log(lsp.assigns.logger, "Removing workspace folder #{name}")
10681069
NextLS.Runtime.stop(lsp.assigns.dynamic_supervisor, pid)
10691070
end
10701071
end)
@@ -1224,7 +1225,7 @@ defmodule NextLS do
12241225

12251226
:ok = DynamicSupervisor.terminate_child(lsp.assigns.dynamic_supervisor, pid)
12261227

1227-
if status == {:error, :deps} do
1228+
if status == {:error, :deps} && lsp.assigns.client_capabilities.window.show_message do
12281229
resp =
12291230
GenLSP.request(
12301231
lsp,
@@ -1281,6 +1282,10 @@ defmodule NextLS do
12811282
_ ->
12821283
NextLS.Logger.info(lsp.assigns.logger, "Not running `mix deps.get`")
12831284
end
1285+
else
1286+
unless lsp.assigns.client_capabilities.window.show_message do
1287+
NextLS.Logger.info(lsp.assigns.logger, "Client does not support window/showMessageRequest")
1288+
end
12841289
end
12851290

12861291
{:noreply, lsp}
@@ -1298,8 +1303,8 @@ defmodule NextLS do
12981303
end
12991304

13001305
def handle_info(message, lsp) do
1301-
GenLSP.log(lsp, "[Next LS] Unhandled message: #{inspect(message)}")
1302-
GenLSP.log(lsp, "[Next LS] process assigns=#{inspect(lsp.assigns)}")
1306+
NextLS.Logger.log(lsp.assigns.logger, "Unhandled message: #{inspect(message)}")
1307+
NextLS.Logger.log(lsp.assigns.logger, "process assigns=#{inspect(lsp.assigns)}")
13031308
{:noreply, lsp}
13041309
end
13051310

lib/next_ls/progress.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
defmodule NextLS.Progress do
22
@moduledoc false
3-
@env Mix.env()
3+
44
def start(lsp, token, msg) do
55
Task.start(fn ->
6-
# FIXME: gen_lsp should allow stubbing requests so we don't have to
7-
# set this in every test. For now, don't send it in the test env
8-
if @env != :test do
6+
if lsp.assigns.client_capabilities.window.work_done_progress do
97
GenLSP.request(lsp, %GenLSP.Requests.WindowWorkDoneProgressCreate{
108
id: System.unique_integer([:positive]),
119
params: %GenLSP.Structures.WorkDoneProgressCreateParams{

lib/next_ls/runtime.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,17 @@ defmodule NextLS.Runtime do
130130
|> String.to_charlist()
131131

132132
bindir = System.get_env("BINDIR")
133+
NextLS.Logger.log(logger, "BINDIR=#{bindir}")
133134
path = System.get_env("PATH")
134-
new_path = String.replace(path, bindir <> ":", "")
135-
new_path = elixir_bin_path <> ":" <> new_path
135+
NextLS.Logger.log(logger, "before PATH=#{path}")
136+
path_minus_bindir = String.replace(path, bindir <> ":", "")
137+
NextLS.Logger.log(logger, "after1 PATH=#{path_minus_bindir}")
138+
139+
path_minus_bindir2 = path_minus_bindir |> String.split(":") |> List.delete(bindir) |> Enum.join(":")
140+
NextLS.Logger.log(logger, "after2 PATH=#{path_minus_bindir2}")
141+
142+
new_path = elixir_bin_path <> ":" <> path_minus_bindir2
143+
NextLS.Logger.log(logger, "after3 PATH=#{new_path}")
136144

137145
with dir when is_list(dir) <- :code.priv_dir(:next_ls) do
138146
exe =

test/support/utils.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ defmodule NextLS.Support.Utils do
9090
capabilities: %{
9191
workspace: %{
9292
workspaceFolders: true
93+
},
94+
window: %{
95+
work_done_progress: false,
96+
showMessage: %{}
9397
}
9498
},
9599
workspaceFolders:

0 commit comments

Comments
 (0)