1
mirror of https://github.com/neovim/neovim.git synced 2024-12-27 14:21:31 -07:00

fix(lsp): send empty "added" list when removing workspace folder

When adding `workspace/didChangeWorkspaceFolders` support to my [language server](https://github.com/elixir-tools/next-ls), I noticed that when neovim removes a workspace, it sends an empty table (which is serialized to an empty JSON array) for the value in the `added` field.

This does not follow the spec; the `added` table should just be empty.

The following error led me to this discovery. Note the payload includes `"added" => [[]]`:

```
22:46:48.476 [error] LSP Exited.

Last message received: handle_notification %{"jsonrpc" => "2.0", "method" => "workspace/didChangeWorkspaceFolders", "params" => %{"event" => %{"added" => [[]], "removed" => [%{"name" => "/Users/mitchell/src/gen_lsp", "uri" => "file:///Users/mitchell/src/gen_lsp"}]}}}

** (MatchError) no match of right hand side value: {:error, %{"params" => %{"event" => %{"added" => [error: "expected a map"]}}}}
    (gen_lsp 0.4.0) lib/gen_lsp.ex:265: anonymous fn/4 in GenLSP.loop/3
    (gen_lsp 0.4.0) lib/gen_lsp.ex:292: GenLSP.attempt/3
    (stdlib 5.0.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
```
This commit is contained in:
Mitchell Hanberg 2023-07-24 12:09:53 -04:00 committed by GitHub
parent add7e106d5
commit a37d568082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -514,7 +514,7 @@ function M.remove_workspace_folder(workspace_folder)
return
end
local params = util.make_workspace_params(
{ {} },
{},
{ { uri = vim.uri_from_fname(workspace_folder), name = workspace_folder } }
)
for _, client in pairs(vim.lsp.get_clients({ bufnr = 0 })) do