@@ -24,10 +24,6 @@ defmodule ElixirLS.LanguageServer.Tracer do
2424 GenServer . cast ( __MODULE__ , :notify_settings_stored )
2525 end
2626
27- def save ( ) do
28- GenServer . cast ( __MODULE__ , :save )
29- end
30-
3127 defp get_project_dir ( ) do
3228 case Process . get ( :elixir_ls_project_dir ) do
3329 nil ->
@@ -60,17 +56,6 @@ defmodule ElixirLS.LanguageServer.Tracer do
6056 project_dir = :persistent_term . get ( :language_server_project_dir , nil )
6157 state = % { project_dir: project_dir }
6258
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-
7459 { :ok , state }
7560 end
7661
@@ -82,24 +67,12 @@ defmodule ElixirLS.LanguageServer.Tracer do
8267 @ impl true
8368 def handle_cast ( :notify_settings_stored , state ) do
8469 project_dir = :persistent_term . get ( :language_server_project_dir )
85- maybe_close_tables ( state )
8670
8771 for table <- @ tables do
8872 table_name = table_name ( table )
8973 :ets . delete_all_objects ( table_name )
9074 end
9175
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-
10376 { :noreply , % { state | project_dir: project_dir } }
10477 end
10578
@@ -113,20 +86,8 @@ defmodule ElixirLS.LanguageServer.Tracer do
11386 { :noreply , state }
11487 end
11588
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-
12689 @ impl true
12790 def terminate ( reason , state ) do
128- maybe_close_tables ( state )
129-
13091 case reason do
13192 :normal ->
13293 :ok
@@ -166,112 +127,6 @@ defmodule ElixirLS.LanguageServer.Tracer do
166127 end
167128 end
168129
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-
275130 defp modules_by_file_matchspec ( file , return ) do
276131 [
277132 { { :"$1" , :"$2" } ,
@@ -432,11 +287,6 @@ defmodule ElixirLS.LanguageServer.Tracer do
432287 end
433288 end
434289
435- defp sync ( table_name ) do
436- :ok = :dets . from_ets ( table_name , table_name )
437- :ok = :dets . sync ( table_name )
438- end
439-
440290 defp in_project_sources? ( path ) do
441291 project_dir = get_project_dir ( )
442292
0 commit comments