@@ -126,53 +126,50 @@ defmodule ElixirLS.LanguageServer.ServerTest do
126
126
assert % { received_shutdown?: true } = :sys . get_state ( server )
127
127
end
128
128
129
- # TODO: Fix this test for the incremental formatter
130
- @ tag :pending
131
- test "formatter" , % { server: server } do
129
+ test "incremental formatter" , % { server: server } do
132
130
in_fixture ( __DIR__ , "formatter" , fn ->
133
131
uri = Path . join ( [ root_uri ( ) , "file.ex" ] )
134
- code = ~S(
132
+
133
+ code = """
135
134
defmodule MyModule do
136
- def my_fn do
137
- foo "This should be split into two lines if reading options from .formatter.exs"
135
+ def my_fn do
136
+ foo("This should be split into two lines if reading options from .formatter.exs")
137
+ end
138
138
end
139
- end
140
- )
139
+ """
141
140
142
141
initialize ( server )
143
142
Server . receive_packet ( server , did_open ( uri , "elixir" , 1 , code ) )
144
- Server . receive_packet ( server , formatting_req ( 1 , uri , % { } ) )
143
+ Server . receive_packet ( server , formatting_req ( 2 , uri , % { } ) )
145
144
146
145
resp = assert_receive ( % { "id" => 2 } , 1000 )
147
146
148
- assert response ( 1 , [
147
+ assert response ( 2 , [
148
+ % {
149
+ "newText" => "\n " ,
150
+ "range" => % {
151
+ "end" => % { "character" => 84 , "line" => 2 } ,
152
+ "start" => % { "character" => 84 , "line" => 2 }
153
+ }
154
+ } ,
149
155
% {
150
- "newText" =>
151
- "defmodule MyModule do\n def my_fn do\n foo(\n \" This should be split into two lines if reading options from .formatter.exs\" \n )\n end\n end\n " ,
156
+ "newText" => "\n " ,
152
157
"range" => % {
153
- "end" => % { "character" => 6 , "line" => 6 } ,
154
- "start" => % { "character" => 0 , "line" => 0 }
158
+ "end" => % { "character" => 8 , "line" => 2 } ,
159
+ "start" => % { "character" => 8 , "line" => 2 }
155
160
}
156
161
}
157
- ] ) = resp
162
+ ] ) == resp
158
163
159
- # Now try it in a subdirectory with its own .formatter.exs file.
164
+ # Now try it in a subdirectory with its own .formatter.exs file that does not define a max line length .
160
165
subdir_uri = Path . join ( [ root_uri ( ) , "lib/file.ex" ] )
161
166
Server . receive_packet ( server , did_open ( subdir_uri , "elixir" , 1 , code ) )
162
- Server . receive_packet ( server , formatting_req ( 2 , subdir_uri , % { } ) )
167
+ Server . receive_packet ( server , formatting_req ( 3 , subdir_uri , % { } ) )
163
168
164
- resp = assert_receive ( % { "id" => 2 } , 1000 )
169
+ resp = assert_receive ( % { "id" => 3 } , 1000 )
165
170
166
- assert response ( 2 , [
167
- % {
168
- "newText" =>
169
- "defmodule MyModule do\n def my_fn do\n foo \" This should be split into two lines if reading options from .formatter.exs\" \n end\n end\n " ,
170
- "range" => % {
171
- "end" => % { "character" => 6 , "line" => 6 } ,
172
- "start" => % { "character" => 0 , "line" => 0 }
173
- }
174
- }
175
- ] ) = resp
171
+ # File is already formatted
172
+ assert response ( 3 , [ ] ) == resp
176
173
end )
177
174
end
178
175
0 commit comments