@@ -9,11 +9,24 @@ defmodule ElixirSense.Core.Compiler do
99 alias ElixirSense.Core.State.ModFunInfo
1010
1111 @ trace_key :elixir_sense_trace
12+ @ trace_paused_key :elixir_sense_trace_paused
13+
14+ def pause_trace do
15+ Process . put ( @ trace_paused_key , true )
16+ end
17+
18+ def resume_trace do
19+ Process . delete ( @ trace_paused_key )
20+ end
1221
1322 def trace ( event , env ) do
14- trace = get_trace ( )
15- Process . put ( @ trace_key , [ { event , env } | trace ] )
16- :ok
23+ if Process . get ( @ trace_paused_key ) do
24+ :ok
25+ else
26+ trace = get_trace ( )
27+ Process . put ( @ trace_key , [ { event , env } | trace ] )
28+ :ok
29+ end
1730 end
1831
1932 defp get_trace do
@@ -63,6 +76,12 @@ defmodule ElixirSense.Core.Compiler do
6376 acc
6477 |> State . add_call_to_line ( { env . module , name , arity } , meta , kind )
6578
79+ { :struct_expansion , meta , name , _assocs } ->
80+ acc
81+ |> State . add_call_to_line ( { name , nil , nil } , meta , :struct_expansion )
82+
83+ # TODO: handle :alias_expansion
84+
6685 _ ->
6786 Logger . warning ( "Unhandled trace event: #{ inspect ( event ) } " )
6887 acc
@@ -1728,40 +1747,42 @@ defmodule ElixirSense.Core.Compiler do
17281747 # here we handle module callbacks. Only before_compile macro callbacks are expanded as they
17291748 # affect module body. Func before_compile callbacks are not executed. after_compile and after_verify
17301749 # are not executed as we do not preform a real compilation
1731- { state , _e_env } = ~w( before_compile after_compile after_verify) a
1732- |> Enum . reduce ( { state , e_env } , fn attribute , { state , env } ->
1733- for args <- Map . get ( state . attribute_store , { full , attribute } , [ ] ) do
1734- case args do
1735- { module , fun } -> [ module , fun ]
1736- module -> [ module , :"__#{ attribute } __" ]
1737- end
1738- end
1739- |> Enum . reduce ( { state , e_env } , fn target , { state , env } ->
1740- # module vars are not accessible in module callbacks
1741- env = % { env | versioned_vars: % { } , line: meta [ :line ] }
1742- state_orig = state
1743- state = State . new_func_vars_scope ( state )
1744-
1745- # elixir dispatches callbacks by raw dispatch and eval_forms
1746- # instead we expand a bock with require and possibly expand macros
1747- # we do not attempt to exec function callbacks
1748- args = case attribute do
1749- :before_compile -> [ env ]
1750- :after_compile -> [ env , << >> ]
1751- :after_verify -> [ full ]
1750+ { state , _e_env } =
1751+ ~w( before_compile after_compile after_verify) a
1752+ |> Enum . reduce ( { state , e_env } , fn attribute , { state , env } ->
1753+ for args <- Map . get ( state . attribute_store , { full , attribute } , [ ] ) do
1754+ case args do
1755+ { module , fun } -> [ module , fun ]
1756+ module -> [ module , :"__#{ attribute } __" ]
1757+ end
17521758 end
1759+ |> Enum . reduce ( { state , e_env } , fn target , { state , env } ->
1760+ # module vars are not accessible in module callbacks
1761+ env = % { env | versioned_vars: % { } , line: meta [ :line ] }
1762+ state_orig = state
1763+ state = State . new_func_vars_scope ( state )
1764+
1765+ # elixir dispatches callbacks by raw dispatch and eval_forms
1766+ # instead we expand a bock with require and possibly expand macros
1767+ # we do not attempt to exec function callbacks
1768+ args =
1769+ case attribute do
1770+ :before_compile -> [ env ]
1771+ :after_compile -> [ env , << >> ]
1772+ :after_verify -> [ full ]
1773+ end
17531774
1754- ast =
1755- { :__block__ , [ ] ,
1756- [
1757- { :require , [ ] , [ hd ( target ) ] } ,
1758- { { :. , [ line: meta [ :line ] ] , target } , [ line: meta [ :line ] ] , args }
1759- ] }
1775+ ast =
1776+ { :__block__ , [ ] ,
1777+ [
1778+ { :require , [ ] , [ hd ( target ) ] } ,
1779+ { { :. , [ line: meta [ :line ] ] , target } , [ line: meta [ :line ] ] , args }
1780+ ] }
17601781
1761- { _result , state , env } = expand ( ast , state , env )
1762- { State . remove_func_vars_scope ( state , state_orig ) , env }
1782+ { _result , state , env } = expand ( ast , state , env )
1783+ { State . remove_func_vars_scope ( state , state_orig ) , env }
1784+ end )
17631785 end )
1764- end )
17651786
17661787 # restore vars from outer scope
17671788 # restore version counter
0 commit comments