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

Add restart custom command #653

Merged
merged 2 commits into from
Jan 5, 2022
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
4 changes: 3 additions & 1 deletion .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
[]
[
{"lib/language_server/providers/execute_command/restart.ex", :no_return}
]
3 changes: 3 additions & 0 deletions apps/language_server/.dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"lib/language_server/providers/execute_command/restart.ex", :no_return}
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand do
Adds a @spec annotation to the document when the user clicks on a code lens.
"""

@callback execute([any], %ElixirLS.LanguageServer.Server{}) ::
{:ok, any} | {:error, atom, String.t()}

def execute(command, args, state) do
handler =
case command do
"spec:" <> _ ->
ElixirLS.LanguageServer.Providers.ExecuteCommand.ApplySpec
alias ElixirLS.LanguageServer.Providers.ExecuteCommand

"expandMacro:" <> _ ->
ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacro
@handlers %{
"spec" => ExecuteCommand.ApplySpec,
"expandMacro" => ExecuteCommand.ExpandMacro,
"manipulatePipes" => ExecuteCommand.ManipulatePipes,
"restart" => ExecuteCommand.Restart
}

"manipulatePipes:" <> _ ->
ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipes

_ ->
nil
end
@callback execute([any], %ElixirLS.LanguageServer.Server{}) ::
{:ok, any} | {:error, atom, String.t()}

if handler do
def execute(command_with_server_id, args, state) do
with [command, _server_id] <- String.split(command_with_server_id, ":"),
handler when not is_nil(handler) <- Map.get(@handlers, command) do
handler.execute(args, state)
else
{:error, :invalid_request, nil}
_ ->
{:error, :invalid_request, nil}
end
end

def get_commands(server_instance_id) do
for {k, _v} <- @handlers do
"#{k}:#{server_instance_id}"
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.Restart do
@behaviour ElixirLS.LanguageServer.Providers.ExecuteCommand

@impl ElixirLS.LanguageServer.Providers.ExecuteCommand
def execute(_args, _state) do
System.halt(0)
end
end
6 changes: 1 addition & 5 deletions apps/language_server/lib/language_server/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,7 @@ defmodule ElixirLS.LanguageServer.Server do
"documentOnTypeFormattingProvider" => %{"firstTriggerCharacter" => "\n"},
"codeLensProvider" => %{"resolveProvider" => false},
"executeCommandProvider" => %{
"commands" => [
"spec:#{server_instance_id}",
"expandMacro:#{server_instance_id}",
"manipulatePipes:#{server_instance_id}"
]
"commands" => ExecuteCommand.get_commands(server_instance_id)
},
"workspace" => %{
"workspaceFolders" => %{"supported" => false, "changeNotifications" => false}
Expand Down