1
1
defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbolsTest do
2
- use ExUnit.Case , async: false
3
2
alias ElixirLS.LanguageServer.Providers.WorkspaceSymbols
3
+ alias ElixirLS.LanguageServer . { Server , Protocol , Tracer , MixProjectCache }
4
+ use ElixirLS.Utils.MixTest.Case , async: false
5
+ import ElixirLS.LanguageServer.Test.ServerTestHelpers
6
+ use Protocol
4
7
5
8
setup do
6
- alias ElixirLS.Utils.PacketCapture
7
- packet_capture = start_supervised! ( { PacketCapture , self ( ) } )
8
- { :ok , pid } = start_supervised ( { WorkspaceSymbols , name: nil } )
9
- Process . group_leader ( pid , packet_capture )
10
-
11
- state = :sys . get_state ( pid )
12
-
13
- fixture_uri =
14
- ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols . module_info ( :compile ) [ :source ]
15
- |> List . to_string ( )
16
- |> ElixirLS.LanguageServer.SourceFile.Path . to_uri ( )
17
-
18
- :sys . replace_state ( pid , fn _ ->
19
- % {
20
- state
21
- | modules_indexed: true ,
22
- modified_uris: [ fixture_uri ]
23
- }
9
+ { :ok , _ } = start_supervised ( Tracer )
10
+ { :ok , server } = Server . start_link ( )
11
+ { :ok , _ } = start_supervised ( MixProjectCache )
12
+ # {:ok, pid} = start_supervised({WorkspaceSymbols, name: nil} )
13
+ start_server ( server )
14
+ :persistent_term . put ( :language_server_override_test_mode , true )
15
+
16
+ on_exit ( fn ->
17
+ :persistent_term . put ( :language_server_override_test_mode , false )
18
+ if Process . alive? ( server ) do
19
+ Process . monitor ( server )
20
+ GenServer . stop ( server )
21
+
22
+ receive do
23
+ { :DOWN , _ , _ , ^ server , _ } ->
24
+ :ok
25
+ end
26
+ end
24
27
end )
25
28
26
- WorkspaceSymbols . notify_build_complete ( pid , true )
27
-
28
- wait_until_indexed ( pid )
29
-
30
- { :ok , server: pid }
29
+ { :ok , % { server: server } }
31
30
end
32
31
33
32
test "empty query" , % { server: server } do
34
- assert { :ok , list } = WorkspaceSymbols . symbols ( "" , server )
33
+ in_fixture ( Path . join ( __DIR__ , ".." ) , "workspace_symbols" , fn ->
34
+ initialize ( server )
35
+
36
+ assert_receive % {
37
+ "method" => "window/logMessage" ,
38
+ "params" => % { "message" => "Compile took" <> _ }
39
+ } ,
40
+ 20000
41
+
42
+ assert { :ok , list } = WorkspaceSymbols . symbols ( "" )
35
43
assert is_list ( list )
36
44
assert list != [ ]
45
+ end )
37
46
end
38
47
39
48
test "returns modules" , % { server: server } do
40
- assert { :ok , list } = WorkspaceSymbols . symbols ( "ElixirLS.LanguageServer.Fixtures." , server )
49
+ in_fixture ( Path . join ( __DIR__ , ".." ) , "workspace_symbols" , fn ->
50
+ initialize ( server )
51
+
52
+ assert_receive % {
53
+ "method" => "window/logMessage" ,
54
+ "params" => % { "message" => "Compile took" <> _ }
55
+ } ,
56
+ 20000
57
+
58
+ assert { :ok , list } = WorkspaceSymbols . symbols ( "ElixirLS.LanguageServer.Fixtures." )
41
59
42
60
assert module =
43
61
Enum . find ( list , & ( & 1 . name == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols" ) )
44
62
45
63
assert module . kind == 11
46
- assert module . location . uri |> String . ends_with? ( "test/support/fixtures /workspace_symbols.ex" )
64
+ assert module . location . uri |> String . ends_with? ( "lib /workspace_symbols.ex" )
47
65
48
66
assert module . location . range == % {
49
67
end: % { character: 0 , line: 1 } ,
50
68
start: % { character: 0 , line: 0 }
51
69
}
52
70
53
- assert WorkspaceSymbols . symbols ( "work" , server )
71
+ assert WorkspaceSymbols . symbols ( "work" )
54
72
|> elem ( 1 )
55
73
|> Enum . any? ( & ( & 1 . name == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols" ) )
74
+ end )
56
75
end
57
76
58
77
test "returns functions" , % { server: server } do
59
- assert { :ok , list } = WorkspaceSymbols . symbols ( "ElixirLS.LanguageServer.Fixtures." , server )
78
+ in_fixture ( Path . join ( __DIR__ , ".." ) , "workspace_symbols" , fn ->
79
+ initialize ( server )
80
+
81
+ assert_receive % {
82
+ "method" => "window/logMessage" ,
83
+ "params" => % { "message" => "Compile took" <> _ }
84
+ } ,
85
+ 20000
86
+ assert { :ok , list } = WorkspaceSymbols . symbols ( "ElixirLS.LanguageServer.Fixtures." )
60
87
61
88
assert some_function =
62
89
Enum . find (
@@ -69,22 +96,31 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbolsTest do
69
96
assert some_function . containerName == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols"
70
97
71
98
assert some_function . location . uri
72
- |> String . ends_with? ( "test/support/fixtures /workspace_symbols.ex" )
99
+ |> String . ends_with? ( "lib /workspace_symbols.ex" )
73
100
74
101
assert some_function . location . range == % {
75
102
end: % { character: 0 , line: 2 } ,
76
103
start: % { character: 0 , line: 1 }
77
104
}
78
105
79
- assert WorkspaceSymbols . symbols ( "fun" , server )
106
+ assert WorkspaceSymbols . symbols ( "fun" )
80
107
|> elem ( 1 )
81
108
|> Enum . any? (
82
109
& ( & 1 . name == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols.some_function/1" )
83
110
)
111
+ end )
84
112
end
85
113
86
114
test "returns types" , % { server: server } do
87
- assert { :ok , list } = WorkspaceSymbols . symbols ( "ElixirLS.LanguageServer.Fixtures." , server )
115
+ in_fixture ( Path . join ( __DIR__ , ".." ) , "workspace_symbols" , fn ->
116
+ initialize ( server )
117
+
118
+ assert_receive % {
119
+ "method" => "window/logMessage" ,
120
+ "params" => % { "message" => "Compile took" <> _ }
121
+ } ,
122
+ 20000
123
+ assert { :ok , list } = WorkspaceSymbols . symbols ( "ElixirLS.LanguageServer.Fixtures." )
88
124
89
125
assert some_type =
90
126
Enum . find (
@@ -97,7 +133,7 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbolsTest do
97
133
assert some_type . containerName == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols"
98
134
99
135
assert some_type . location . uri
100
- |> String . ends_with? ( "test/support/fixtures /workspace_symbols.ex" )
136
+ |> String . ends_with? ( "lib /workspace_symbols.ex" )
101
137
102
138
assert some_type . location . range == % {
103
139
end: % { character: 0 , line: 8 } ,
@@ -109,15 +145,24 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbolsTest do
109
145
& ( & 1 . name == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols.some_opaque_type/0" )
110
146
)
111
147
112
- assert WorkspaceSymbols . symbols ( "opa" , server )
148
+ assert WorkspaceSymbols . symbols ( "opa" )
113
149
|> elem ( 1 )
114
150
|> Enum . any? (
115
151
& ( & 1 . name == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols.some_opaque_type/0" )
116
152
)
153
+ end )
117
154
end
118
155
119
156
test "returns callbacks" , % { server: server } do
120
- assert { :ok , list } = WorkspaceSymbols . symbols ( "ElixirLS.LanguageServer.Fixtures." , server )
157
+ in_fixture ( Path . join ( __DIR__ , ".." ) , "workspace_symbols" , fn ->
158
+ initialize ( server )
159
+
160
+ assert_receive % {
161
+ "method" => "window/logMessage" ,
162
+ "params" => % { "message" => "Compile took" <> _ }
163
+ } ,
164
+ 20000
165
+ assert { :ok , list } = WorkspaceSymbols . symbols ( "ElixirLS.LanguageServer.Fixtures." )
121
166
122
167
assert some_callback =
123
168
Enum . find (
@@ -130,7 +175,7 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbolsTest do
130
175
assert some_callback . containerName == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols"
131
176
132
177
assert some_callback . location . uri
133
- |> String . ends_with? ( "test/support/fixtures /workspace_symbols.ex" )
178
+ |> String . ends_with? ( "lib /workspace_symbols.ex" )
134
179
135
180
assert some_callback . location . range == % {
136
181
end: % { character: 0 , line: 5 } ,
@@ -142,19 +187,11 @@ defmodule ElixirLS.LanguageServer.Providers.WorkspaceSymbolsTest do
142
187
& ( & 1 . name == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols.some_macrocallback/1" )
143
188
)
144
189
145
- assert WorkspaceSymbols . symbols ( "macr" , server )
190
+ assert WorkspaceSymbols . symbols ( "macr" )
146
191
|> elem ( 1 )
147
192
|> Enum . any? (
148
193
& ( & 1 . name == "ElixirLS.LanguageServer.Fixtures.WorkspaceSymbols.some_macrocallback/1" )
149
194
)
150
- end
151
-
152
- defp wait_until_indexed ( pid ) do
153
- state = :sys . get_state ( pid )
154
-
155
- if state . modules == [ ] do
156
- Process . sleep ( 500 )
157
- wait_until_indexed ( pid )
158
- end
195
+ end )
159
196
end
160
197
end
0 commit comments