Skip to content

Commit 9c6f7d7

Browse files
authored
fix: make manipulate pipes compatible with LSP std (#520)
* fix: make manipulate pipes compatible with lsp std * test: change tests for new interface
1 parent eb969ef commit 9c6f7d7

File tree

3 files changed

+29
-74
lines changed

3 files changed

+29
-74
lines changed

apps/language_server/lib/language_server/providers/execute_command.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand do
99
def execute(command, args, state) do
1010
handler =
1111
case command do
12-
"spec:" <> _ -> ElixirLS.LanguageServer.Providers.ExecuteCommand.ApplySpec
13-
"expandMacro:" <> _ -> ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacro
14-
_ -> nil
12+
"spec:" <> _ ->
13+
ElixirLS.LanguageServer.Providers.ExecuteCommand.ApplySpec
14+
15+
"expandMacro:" <> _ ->
16+
ElixirLS.LanguageServer.Providers.ExecuteCommand.ExpandMacro
17+
18+
"manipulatePipes:" <> _ ->
19+
ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipes
20+
21+
_ ->
22+
nil
1523
end
1624

1725
if handler do

apps/language_server/lib/language_server/providers/execute_command/manipulate_pipes.ex

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,25 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipes do
1616
@newlines ["\r\n", "\n", "\r"]
1717

1818
@impl ElixirLS.LanguageServer.Providers.ExecuteCommand
19-
def execute(
20-
%{"uri" => uri, "cursor_line" => line, "cursor_column" => col, "operation" => operation},
21-
state
22-
)
19+
def execute([operation, uri, line, col], state)
2320
when is_integer(line) and is_integer(col) and is_binary(uri) and
24-
operation in ["to_pipe", "from_pipe"] do
21+
operation in ["toPipe", "fromPipe"] do
2522
# line and col are assumed to be 0-indexed
2623
source_file = Server.get_source_file(state, uri)
2724

2825
{:ok, %{edited_text: edited_text, edit_range: edit_range}} =
2926
case operation do
30-
"to_pipe" ->
27+
"toPipe" ->
3128
to_pipe_at_cursor(source_file.text, line, col)
3229

33-
"from_pipe" ->
30+
"fromPipe" ->
3431
from_pipe_at_cursor(source_file.text, line, col)
3532
end
3633

3734
label =
3835
case operation do
39-
"to_pipe" -> "Convert function call to pipe operator"
40-
"from_pipe" -> "Convert pipe operator to function call"
36+
"toPipe" -> "Convert function call to pipe operator"
37+
"fromPipe" -> "Convert pipe operator to function call"
4138
end
4239

4340
edit_result =

apps/language_server/test/providers/execute_command/manipulate_pipes_test.exs

Lines changed: 12 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
2828
end
2929
end
3030

31-
describe "execute/2 to_pipe" do
31+
describe "execute/2 toPipe" do
3232
test "can pipe remote calls in single lines" do
3333
{:ok, _} =
3434
JsonRpcMock.start_link(success_reply: {:ok, %{"applied" => true}}, test_pid: self())
@@ -49,12 +49,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
4949

5050
assert {:ok, nil} =
5151
ManipulatePipes.execute(
52-
%{
53-
"uri" => uri,
54-
"cursor_line" => 2,
55-
"cursor_column" => 13,
56-
"operation" => "to_pipe"
57-
},
52+
["toPipe", uri, 2, 13],
5853
%Server{
5954
source_files: %{
6055
uri => %SourceFile{
@@ -129,12 +124,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
129124

130125
assert {:ok, nil} =
131126
ManipulatePipes.execute(
132-
%{
133-
"uri" => uri,
134-
"cursor_line" => 2,
135-
"cursor_column" => 12,
136-
"operation" => "to_pipe"
137-
},
127+
["toPipe", uri, 2, 12],
138128
%Server{
139129
source_files: %{
140130
uri => %SourceFile{
@@ -207,12 +197,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
207197

208198
assert {:ok, nil} =
209199
ManipulatePipes.execute(
210-
%{
211-
"uri" => uri,
212-
"cursor_line" => 2,
213-
"cursor_column" => 2,
214-
"operation" => "to_pipe"
215-
},
200+
["toPipe", uri, 2, 2],
216201
%Server{
217202
source_files: %{
218203
uri => %SourceFile{
@@ -288,12 +273,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
288273

289274
assert {:ok, nil} =
290275
ManipulatePipes.execute(
291-
%{
292-
"uri" => uri,
293-
"cursor_line" => 2,
294-
"cursor_column" => 12,
295-
"operation" => "to_pipe"
296-
},
276+
["toPipe", uri, 2, 12],
297277
%Server{
298278
source_files: %{
299279
uri => %SourceFile{
@@ -364,12 +344,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
364344

365345
assert {:ok, nil} =
366346
ManipulatePipes.execute(
367-
%{
368-
"uri" => uri,
369-
"cursor_line" => 2,
370-
"cursor_column" => 14,
371-
"operation" => "to_pipe"
372-
},
347+
["toPipe", uri, 2, 14],
373348
%Server{
374349
source_files: %{
375350
uri => %SourceFile{
@@ -420,7 +395,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
420395
end
421396
end
422397

423-
describe "execute/2 from_pipe" do
398+
describe "execute/2 fromPipe" do
424399
test "can unpipe remote calls in single lines" do
425400
{:ok, _} =
426401
JsonRpcMock.start_link(success_reply: {:ok, %{"applied" => true}}, test_pid: self())
@@ -441,12 +416,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
441416

442417
assert {:ok, nil} =
443418
ManipulatePipes.execute(
444-
%{
445-
"uri" => uri,
446-
"cursor_line" => 2,
447-
"cursor_column" => 8,
448-
"operation" => "from_pipe"
449-
},
419+
["fromPipe", uri, 2, 8],
450420
%Server{
451421
source_files: %{
452422
uri => %SourceFile{
@@ -521,12 +491,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
521491

522492
assert {:ok, nil} =
523493
ManipulatePipes.execute(
524-
%{
525-
"uri" => uri,
526-
"cursor_line" => 3,
527-
"cursor_column" => 5,
528-
"operation" => "from_pipe"
529-
},
494+
["fromPipe", uri, 3, 5],
530495
%Server{
531496
source_files: %{
532497
uri => %SourceFile{
@@ -599,12 +564,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
599564

600565
assert {:ok, nil} =
601566
ManipulatePipes.execute(
602-
%{
603-
"uri" => uri,
604-
"cursor_line" => 2,
605-
"cursor_column" => 11,
606-
"operation" => "from_pipe"
607-
},
567+
["fromPipe", uri, 2, 11],
608568
%Server{
609569
source_files: %{
610570
uri => %SourceFile{
@@ -678,12 +638,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
678638

679639
assert {:ok, nil} =
680640
ManipulatePipes.execute(
681-
%{
682-
"uri" => uri,
683-
"cursor_line" => 3,
684-
"cursor_column" => 4,
685-
"operation" => "from_pipe"
686-
},
641+
["fromPipe", uri, 3, 4],
687642
%Server{
688643
source_files: %{
689644
uri => %SourceFile{
@@ -755,12 +710,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.ManipulatePipesTest d
755710

756711
assert {:ok, nil} =
757712
ManipulatePipes.execute(
758-
%{
759-
"uri" => uri,
760-
"cursor_line" => 3,
761-
"cursor_column" => 5,
762-
"operation" => "from_pipe"
763-
},
713+
["fromPipe", uri, 3, 5],
764714
%Server{
765715
source_files: %{
766716
uri => %SourceFile{

0 commit comments

Comments
 (0)