Skip to content

Commit

Permalink
add restart custom command
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Dec 25, 2021
1 parent 88b53a9 commit 7211589
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
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, as: C

"expandMacro:" <> _ ->
ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacro
@handlers %{
"spec" => C.ApplySpec,
"expandMacro" => C.ExpandMacro,
"manipulatePipes" => C.ManipulatePipes,
"restart" => C.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

0 comments on commit 7211589

Please sign in to comment.