Skip to content

Commit

Permalink
fix: check capabilities before registering didChangeWatchedFiles (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Oct 5, 2023
1 parent ef21d40 commit a0af2dc
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 76 deletions.
36 changes: 19 additions & 17 deletions lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -539,24 +539,26 @@ defmodule NextLS do
)
end

nil =
GenLSP.request(lsp, %GenLSP.Requests.ClientRegisterCapability{
id: System.unique_integer([:positive]),
params: %GenLSP.Structures.RegistrationParams{
registrations: [
%GenLSP.Structures.Registration{
id: "file-watching",
method: "workspace/didChangeWatchedFiles",
register_options: %GenLSP.Structures.DidChangeWatchedFilesRegistrationOptions{
watchers:
for ext <- ~W|ex exs leex eex heex sface| do
%GenLSP.Structures.FileSystemWatcher{kind: 7, glob_pattern: "**/*.#{ext}"}
end
with %{dynamic_registration: true} <- lsp.assigns.client_capabilities.workspace.did_change_watched_files do
nil =
GenLSP.request(lsp, %GenLSP.Requests.ClientRegisterCapability{
id: System.unique_integer([:positive]),
params: %GenLSP.Structures.RegistrationParams{
registrations: [
%GenLSP.Structures.Registration{
id: "file-watching",
method: "workspace/didChangeWatchedFiles",
register_options: %GenLSP.Structures.DidChangeWatchedFilesRegistrationOptions{
watchers:
for ext <- ~W|ex exs leex eex heex sface| do
%GenLSP.Structures.FileSystemWatcher{kind: 7, glob_pattern: "**/*.#{ext}"}
end
}
}
}
]
}
})
]
}
})
end

GenLSP.log(lsp, "[NextLS] Booting runtimes...")

Expand Down
18 changes: 6 additions & 12 deletions test/next_ls/definition_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ defmodule NextLS.DefinitionTest do

test "go to local function definition", %{client: client, bar: bar} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}
Expand Down Expand Up @@ -93,7 +92,6 @@ defmodule NextLS.DefinitionTest do

test "go to imported function definition", %{client: client, bar: bar, imported: imported} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}
Expand Down Expand Up @@ -129,7 +127,6 @@ defmodule NextLS.DefinitionTest do

test "go to remote function definition", %{client: client, bar: bar, remote: remote} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_compiled(context, "my_proj")
Expand Down Expand Up @@ -227,7 +224,6 @@ defmodule NextLS.DefinitionTest do

test "go to local macro definition", %{client: client, bar: bar} do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}

Expand Down Expand Up @@ -260,7 +256,6 @@ defmodule NextLS.DefinitionTest do

test "go to imported macro definition", %{client: client, bar: bar, imported: imported} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}
Expand Down Expand Up @@ -296,7 +291,6 @@ defmodule NextLS.DefinitionTest do

test "go to remote macro definition", %{client: client, bar: bar, remote: remote} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}
Expand Down Expand Up @@ -382,7 +376,7 @@ defmodule NextLS.DefinitionTest do

test "go to module definition", %{client: client, bar: bar, peace: peace} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

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

Expand Down Expand Up @@ -413,7 +407,7 @@ defmodule NextLS.DefinitionTest do

test "go to module alias definition", %{client: client, peace: peace, bar: bar, baz: baz} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

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

Expand Down Expand Up @@ -521,7 +515,7 @@ defmodule NextLS.DefinitionTest do

test "go to attribute definition", %{client: client, bar: bar} do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}

uri = uri(bar)
Expand Down Expand Up @@ -555,7 +549,7 @@ defmodule NextLS.DefinitionTest do

test "go to attribute definition in second module", %{client: client, bar: bar} do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}

uri = uri(bar)
Expand Down Expand Up @@ -589,7 +583,7 @@ defmodule NextLS.DefinitionTest do

test "go to attribute definition in inner module", %{client: client, bar: bar} do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}

uri = uri(bar)
Expand Down Expand Up @@ -656,7 +650,7 @@ defmodule NextLS.DefinitionTest do

test "go to local variable definition", %{client: client, bar: bar} do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}

uri = uri(bar)
Expand Down
10 changes: 5 additions & 5 deletions test/next_ls/dependency_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule NextLS.DependencyTest do
%{client: client, foo: foo, bar: bar} = context

assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

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

Expand Down Expand Up @@ -117,7 +117,7 @@ defmodule NextLS.DependencyTest do
test "does not show in workspace symbols", context do
%{client: client, foo: foo, bar: bar} = context
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

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

Expand All @@ -139,7 +139,7 @@ defmodule NextLS.DependencyTest do

test "does not show up in function references", %{client: client, foo: foo} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

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

Expand Down Expand Up @@ -169,7 +169,7 @@ defmodule NextLS.DependencyTest do

test "does not show up in module references", %{client: client, foo: foo} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

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

Expand Down Expand Up @@ -203,7 +203,7 @@ defmodule NextLS.DependencyTest do

test "elixir source files do not show up in references", %{client: client, cache: cache} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")

assert_notification "$/progress", %{
Expand Down
1 change: 0 additions & 1 deletion test/next_ls/diagnostics_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ defmodule NextLS.DiagnosticsTest do

test "publishes diagnostics once the client has initialized", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_notification "window/logMessage", %{
"message" => "[NextLS] NextLS v" <> _,
Expand Down
2 changes: 1 addition & 1 deletion test/next_ls/extensions/credo_extension_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule NextLS.CredoExtensionTest do

test "publishes credo diagnostics", %{client: client, foo: foo} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
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!"}}
Expand Down
1 change: 0 additions & 1 deletion test/next_ls/hover_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ defmodule NextLS.HoverTest do

setup context do
assert :ok == notify(context.client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(context.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!"}}
Expand Down
8 changes: 4 additions & 4 deletions test/next_ls/references_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule NextLS.ReferencesTest do

test "list function references", %{client: client, bar: bar, peace: peace} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
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!"}}
Expand Down Expand Up @@ -94,7 +94,7 @@ defmodule NextLS.ReferencesTest do

test "list module references", %{client: client, bar: bar, peace: peace} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
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!"}}
Expand Down Expand Up @@ -133,7 +133,7 @@ defmodule NextLS.ReferencesTest do

test "list attribute references", %{client: client, bar: bar} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
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!"}}
Expand Down Expand Up @@ -174,7 +174,7 @@ defmodule NextLS.ReferencesTest do

test "list variable references", %{client: client, bar: bar} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
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!"}}
Expand Down
48 changes: 22 additions & 26 deletions test/next_ls/workspaces_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ defmodule NextLS.WorkspacesTest do
@tag root_paths: ["proj_one"]
test "starts a new runtime when you add a workspace folder", %{client: client, cwd: cwd} = context 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_compiled(context, "proj_one")

Expand All @@ -70,7 +69,6 @@ defmodule NextLS.WorkspacesTest do
@tag root_paths: ["proj_one", "proj_two"]
test "stops the runtime when you remove a workspace folder", %{client: client, cwd: cwd} = context 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_is_ready(context, "proj_two")

Expand Down Expand Up @@ -101,28 +99,28 @@ defmodule NextLS.WorkspacesTest do
test "can register for workspace/didChangedWatchedFiles", %{client: client} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})

assert_request(client, "client/registerCapability", fn params ->
assert params == %{
"registrations" => [
%{
"id" => "file-watching",
"method" => "workspace/didChangeWatchedFiles",
"registerOptions" => %{
"watchers" => [
%{"kind" => 7, "globPattern" => "**/*.ex"},
%{"kind" => 7, "globPattern" => "**/*.exs"},
%{"kind" => 7, "globPattern" => "**/*.leex"},
%{"kind" => 7, "globPattern" => "**/*.eex"},
%{"kind" => 7, "globPattern" => "**/*.heex"},
%{"kind" => 7, "globPattern" => "**/*.sface"}
]
}
}
]
}

nil
end)
# assert_request(client, "client/registerCapability", fn params ->
# assert params == %{
# "registrations" => [
# %{
# "id" => "file-watching",
# "method" => "workspace/didChangeWatchedFiles",
# "registerOptions" => %{
# "watchers" => [
# %{"kind" => 7, "globPattern" => "**/*.ex"},
# %{"kind" => 7, "globPattern" => "**/*.exs"},
# %{"kind" => 7, "globPattern" => "**/*.leex"},
# %{"kind" => 7, "globPattern" => "**/*.eex"},
# %{"kind" => 7, "globPattern" => "**/*.heex"},
# %{"kind" => 7, "globPattern" => "**/*.sface"}
# ]
# }
# }
# ]
# }

# nil
# end)

assert_is_ready(context, "proj_one")
assert_compiled(context, "proj_one")
Expand All @@ -132,8 +130,6 @@ defmodule NextLS.WorkspacesTest do
test "can receive workspace/didChangeWatchedFiles notification", %{client: client, cwd: cwd} = context 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_compiled(context, "proj_one")

Expand Down
9 changes: 0 additions & 9 deletions test/next_ls_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ defmodule NextLSTest do

test "responds correctly to a shutdown request", %{client: client} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")

Expand All @@ -75,7 +74,6 @@ defmodule NextLSTest do
id = System.unique_integer([:positive])

assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert :ok ==
request(client, %{
Expand Down Expand Up @@ -113,7 +111,6 @@ defmodule NextLSTest do

test "formats", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

notify client, %{
method: "textDocument/didOpen",
Expand Down Expand Up @@ -188,7 +185,6 @@ defmodule NextLSTest do

test "formatting gracefully handles files with syntax errors", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

notify client, %{
method: "textDocument/didOpen",
Expand Down Expand Up @@ -233,7 +229,6 @@ defmodule NextLSTest do

test "workspace symbols", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}
Expand Down Expand Up @@ -324,7 +319,6 @@ defmodule NextLSTest do

test "workspace symbols with query", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}
Expand Down Expand Up @@ -357,7 +351,6 @@ defmodule NextLSTest do

test "workspace symbols with query fuzzy search", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}
Expand Down Expand Up @@ -390,7 +383,6 @@ defmodule NextLSTest do

test "workspace symbols with query case sensitive fuzzy search", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_is_ready(context, "my_proj")
assert_notification "$/progress", %{"value" => %{"kind" => "end", "message" => "Finished indexing!"}}
Expand Down Expand Up @@ -434,7 +426,6 @@ defmodule NextLSTest do

test "deletes symbols when a file is deleted", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

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

0 comments on commit a0af2dc

Please sign in to comment.