@@ -24,10 +24,6 @@ defmodule ElixirLS.LanguageServer.Tracer do
24
24
GenServer . cast ( __MODULE__ , :notify_settings_stored )
25
25
end
26
26
27
- def save ( ) do
28
- GenServer . cast ( __MODULE__ , :save )
29
- end
30
-
31
27
defp get_project_dir ( ) do
32
28
case Process . get ( :elixir_ls_project_dir ) do
33
29
nil ->
@@ -60,17 +56,6 @@ defmodule ElixirLS.LanguageServer.Tracer do
60
56
project_dir = :persistent_term . get ( :language_server_project_dir , nil )
61
57
state = % { project_dir: project_dir }
62
58
63
- if project_dir != nil do
64
- { us , _ } =
65
- :timer . tc ( fn ->
66
- for table <- @ tables do
67
- init_table ( table , project_dir )
68
- end
69
- end )
70
-
71
- Logger . info ( "Loaded DETS databases in #{ div ( us , 1000 ) } ms" )
72
- end
73
-
74
59
{ :ok , state }
75
60
end
76
61
@@ -82,24 +67,12 @@ defmodule ElixirLS.LanguageServer.Tracer do
82
67
@ impl true
83
68
def handle_cast ( :notify_settings_stored , state ) do
84
69
project_dir = :persistent_term . get ( :language_server_project_dir )
85
- maybe_close_tables ( state )
86
70
87
71
for table <- @ tables do
88
72
table_name = table_name ( table )
89
73
:ets . delete_all_objects ( table_name )
90
74
end
91
75
92
- if project_dir != nil do
93
- { us , _ } =
94
- :timer . tc ( fn ->
95
- for table <- @ tables do
96
- init_table ( table , project_dir )
97
- end
98
- end )
99
-
100
- Logger . info ( "Loaded DETS databases in #{ div ( us , 1000 ) } ms" )
101
- end
102
-
103
76
{ :noreply , % { state | project_dir: project_dir } }
104
77
end
105
78
@@ -113,20 +86,8 @@ defmodule ElixirLS.LanguageServer.Tracer do
113
86
{ :noreply , state }
114
87
end
115
88
116
- def handle_cast ( :save , % { project_dir: project_dir } = state ) do
117
- for table <- @ tables do
118
- table_name = table_name ( table )
119
-
120
- sync ( table_name )
121
- end
122
-
123
- { :noreply , state }
124
- end
125
-
126
89
@ impl true
127
90
def terminate ( reason , state ) do
128
- maybe_close_tables ( state )
129
-
130
91
case reason do
131
92
:normal ->
132
93
:ok
@@ -166,112 +127,6 @@ defmodule ElixirLS.LanguageServer.Tracer do
166
127
end
167
128
end
168
129
169
- defp maybe_close_tables ( % { project_dir: nil } ) , do: :ok
170
-
171
- defp maybe_close_tables ( _state ) do
172
- for table <- @ tables do
173
- close_table ( table )
174
- end
175
-
176
- :ok
177
- end
178
-
179
- defp dets_path ( project_dir , table ) do
180
- Path . join ( [ project_dir , ".elixir_ls" , "#{ table } .dets" ] )
181
- end
182
-
183
- def init_table ( table , project_dir ) do
184
- table_name = table_name ( table )
185
- path = dets_path ( project_dir , table )
186
-
187
- opts = [ file: path |> String . to_charlist ( ) , auto_save: 60_000 , repair: true ]
188
-
189
- :ok = path |> Path . dirname ( ) |> File . mkdir_p ( )
190
-
191
- case :dets . open_file ( table_name , opts ) do
192
- { :ok , _ } ->
193
- :ok
194
-
195
- { :error , { :needs_repair , _ } = reason } ->
196
- Logger . warning ( "Unable to open DETS #{ path } : #{ inspect ( reason ) } " )
197
- File . rm_rf! ( path )
198
-
199
- { :ok , _ } = :dets . open_file ( table_name , opts )
200
-
201
- { :error , { :repair_failed , _ } = reason } ->
202
- Logger . warning ( "Unable to open DETS #{ path } : #{ inspect ( reason ) } " )
203
- File . rm_rf! ( path )
204
-
205
- { :ok , _ } = :dets . open_file ( table_name , opts )
206
-
207
- { :error , { :cannot_repair , _ } = reason } ->
208
- Logger . warning ( "Unable to open DETS #{ path } : #{ inspect ( reason ) } " )
209
- File . rm_rf! ( path )
210
-
211
- { :ok , _ } = :dets . open_file ( table_name , opts )
212
-
213
- { :error , { :not_a_dets_file , _ } = reason } ->
214
- Logger . warning ( "Unable to open DETS #{ path } : #{ inspect ( reason ) } " )
215
- File . rm_rf! ( path )
216
-
217
- { :ok , _ } = :dets . open_file ( table_name , opts )
218
-
219
- { :error , { :format_8_no_longer_supported , _ } = reason } ->
220
- Logger . warning ( "Unable to open DETS #{ path } : #{ inspect ( reason ) } " )
221
- File . rm_rf! ( path )
222
-
223
- { :ok , _ } = :dets . open_file ( table_name , opts )
224
- end
225
-
226
- case :dets . to_ets ( table_name , table_name ) do
227
- ^ table_name ->
228
- :ok
229
-
230
- { :error , reason } ->
231
- Logger . warning ( "Unable to read DETS #{ path } : #{ inspect ( reason ) } " )
232
- File . rm_rf! ( path )
233
-
234
- { :ok , _ } = :dets . open_file ( table_name , opts )
235
- ^ table_name = :dets . to_ets ( table_name , table_name )
236
- end
237
- catch
238
- kind , payload ->
239
- { payload , stacktrace } = Exception . blame ( kind , payload , __STACKTRACE__ )
240
- error_msg = Exception . format ( kind , payload , stacktrace )
241
-
242
- Logger . error (
243
- "Unable to init tracer table #{ table } in directory #{ project_dir } : #{ error_msg } "
244
- )
245
-
246
- JsonRpc . show_message (
247
- :error ,
248
- "Unable to init tracer tables in #{ project_dir } "
249
- )
250
-
251
- JsonRpc . telemetry (
252
- "lsp_server_error" ,
253
- % {
254
- "elixir_ls.lsp_process" => inspect ( __MODULE__ ) ,
255
- "elixir_ls.lsp_server_error" => error_msg
256
- } ,
257
- % { }
258
- )
259
-
260
- unless :persistent_term . get ( :language_server_test_mode , false ) do
261
- Process . sleep ( 2000 )
262
- System . halt ( 1 )
263
- else
264
- IO . warn ( "Unable to init tracer table #{ table } in directory #{ project_dir } : #{ error_msg } " )
265
- end
266
- end
267
-
268
- def close_table ( table ) do
269
- table_name = table_name ( table )
270
- sync ( table_name )
271
-
272
- :ok = :dets . close ( table_name )
273
- end
274
-
275
130
defp modules_by_file_matchspec ( file , return ) do
276
131
[
277
132
{ { :"$1" , :"$2" } ,
@@ -432,11 +287,6 @@ defmodule ElixirLS.LanguageServer.Tracer do
432
287
end
433
288
end
434
289
435
- defp sync ( table_name ) do
436
- :ok = :dets . from_ets ( table_name , table_name )
437
- :ok = :dets . sync ( table_name )
438
- end
439
-
440
290
defp in_project_sources? ( path ) do
441
291
project_dir = get_project_dir ( )
442
292
0 commit comments