Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly request file watchers from client #35

Merged
merged 3 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/language_server/lib/language_server/json_rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ defmodule ElixirLS.LanguageServer.JsonRpc do
notify("window/logMessage", %{type: message_type_code(type), message: to_string(message)})
end

def register_capability_request(server \\ __MODULE__, method, options) do
send_request(server, "client/registerCapability", %{
"registrations" => [
%{
"id" => :crypto.hash(:sha, method) |> Base.encode16(),
"method" => method,
"registerOptions" => options
}
]
})
end

def show_message_request(server \\ __MODULE__, type, message, actions) do
send_request(server, "window/showMessageRequest", %{
"type" => message_type_code(type),
Expand Down
24 changes: 23 additions & 1 deletion apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ defmodule ElixirLS.LanguageServer.Server do
super(msg, state)
end

def handle_info(:send_file_watchers, state) do
JsonRpc.register_capability_request("workspace/didChangeWatchedFiles", %{
"watchers" => [
%{"globPattern" => "**/*.ex"},
%{"globPattern" => "**/*.exs"}
]
})

{:noreply, state}
end

def handle_info(:default_config, state) do
state =
case state do
Expand Down Expand Up @@ -311,6 +322,16 @@ defmodule ElixirLS.LanguageServer.Server do
# If we don't receive workspace/didChangeConfiguration for 5 seconds, use default settings
Process.send_after(self(), :default_config, 5000)

# Explicitly request file watchers from the client if supported
supports_dynamic = get_in(client_capabilities, [
"textDocument",
"codeAction",
"dynamicRegistration"
])
if supports_dynamic do
Process.send_after(self(), :send_file_watchers, 100)
end

{:ok, %{"capabilities" => server_capabilities()}, state}
end

Expand Down Expand Up @@ -434,7 +455,8 @@ defmodule ElixirLS.LanguageServer.Server do
"documentSymbolProvider" => true,
"documentOnTypeFormattingProvider" => %{"firstTriggerCharacter" => "\n"},
"codeLensProvider" => %{"resolveProvider" => false},
"executeCommandProvider" => %{"commands" => ["spec"]}
"executeCommandProvider" => %{"commands" => ["spec"]},
"workspace" => %{ "workspaceFolders" => %{"supported" => true, "changeNotifications" => true}}
}
end

Expand Down