11module PuppetDebugServer
22 module PuppetDebugSession
33 @hook_handler = nil
4-
4+
55 def self . hooks
66 if @hook_handler . nil?
77 @hook_handler = PuppetDebugServer ::Hooks . new
@@ -25,49 +25,49 @@ def self.hook_before_pops_evaluate(args)
2525 target = args [ 1 ]
2626 # Ignore this if there is no positioning information available
2727 return unless target . is_a? ( Puppet ::Pops ::Model ::Positioned )
28+ target_loc = get_location_from_pops_object ( target )
29+
2830 # Even if it's positioned, it can still contain invalid information. Ignore it if
2931 # it's missing required information. This can happen when evaluting strings (e.g. watches from VSCode)
3032 # i.e. not a file on disk
31- return if target . file . nil? || target . file . empty?
33+ return if target_loc . file . nil? || target_loc . file . empty?
34+ target_classname = get_puppet_class_name ( target )
35+ ast_classname = get_ast_class_name ( target )
3236
3337 # Break if we hit a specific puppet function
34- if target . _pcore_type . simple_name == 'CallNamedFunctionExpression'
38+ if target_classname == 'CallNamedFunctionExpression'
3539 # TODO Do we really need to break on a function called breakpoint?
3640 if target . functor_expr . value == 'breakpoint'
3741 # Re-raise the hook as a breakpoint
38- PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_function_breakpoint , [ target . functor_expr . value , target . _pcore_type . name ] +args )
42+ PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_function_breakpoint , [ target . functor_expr . value , ast_classname ] +args )
3943 return
4044 else
4145 func_names = PuppetDebugServer ::PuppetDebugSession . function_breakpoints
4246 func_names . each do |func |
4347 next unless func [ 'name' ] == target . functor_expr . value
4448 # Re-raise the hook as a breakpoint
45- PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_function_breakpoint , [ target . functor_expr . value , target . _pcore_type . name ] + args )
49+ PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_function_breakpoint , [ target . functor_expr . value , ast_classname ] + args )
4650 return
4751 end
4852 end
4953 end
5054
51- unless target . length == 0
55+ unless target_loc . length == 0
5256 excluded_classes = [ 'BlockExpression' , 'HostClassDefinition' ]
53- file_path = target . file
57+ file_path = target_loc . file
5458 breakpoints = PuppetDebugServer ::PuppetDebugSession . source_breakpoints ( file_path )
55-
56- #target._pcore_type.simple_name
5759 # TODO should check if it's an object we don't care aount
58-
59- unless excluded_classes . include? ( target . _pcore_type . simple_name ) || breakpoints . nil? || breakpoints . empty?
60+ unless excluded_classes . include? ( target_classname ) || breakpoints . nil? || breakpoints . empty?
6061 # Calculate the start and end lines of the target
61- target_start_line = target . line
62- target_end_line = target . locator . line_for_offset ( target . offset + target . length )
62+ target_start_line = target_loc . line
63+ target_end_line = line_for_offset ( target , target_loc . offset + target_loc . length )
6364
6465 breakpoints . each do |bp |
6566 bp_line = bp [ 'line' ]
6667 # TODO Hit and conditional BreakPoints?
6768 if bp_line >= target_start_line && bp_line <= target_end_line
6869 # Re-raise the hook as a breakpoint
69- PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_breakpoint , [ target . _pcore_type . name , '' ] + args )
70- #require 'pry'; binding.pry
70+ PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_breakpoint , [ ast_classname , '' ] + args )
7171 return
7272 end
7373 end
@@ -79,26 +79,27 @@ def self.hook_before_pops_evaluate(args)
7979 when :stepin
8080 # Stepping-in is basically break on everything
8181 # Re-raise the hook as a step breakpoint
82- PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_step_breakpoint , [ target . _pcore_type . name , '' ] + args )
82+ PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_step_breakpoint , [ ast_classname , '' ] + args )
8383 return
8484 when :next
8585 # Next will break on anything at this Pop depth or shallower
8686 # Re-raise the hook as a step breakpoint
8787 run_options = PuppetDebugServer ::PuppetDebugSession . run_mode_options
8888 if !run_options [ :pops_depth_level ] . nil? && @session_pops_eval_depth <= run_options [ :pops_depth_level ]
89- PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_step_breakpoint , [ target . _pcore_type . name , '' ] + args )
89+ PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_step_breakpoint , [ ast_classname , '' ] + args )
9090 return
9191 end
9292 when :stepout
9393 # Stepping-Out will break on anything shallower than this Pop depth
9494 # Re-raise the hook as a step breakpoint
9595 run_options = PuppetDebugServer ::PuppetDebugSession . run_mode_options
9696 if !run_options [ :pops_depth_level ] . nil? && @session_pops_eval_depth < run_options [ :pops_depth_level ]
97- PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_step_breakpoint , [ target . _pcore_type . name , '' ] + args )
97+ PuppetDebugServer ::PuppetDebugSession . hooks . exec_hook ( :hook_step_breakpoint , [ ast_classname , '' ] + args )
9898 return
9999 end
100100 end
101101 end
102+
102103 def self . hook_after_pops_evaluate ( args )
103104 @session_pops_eval_depth = @session_pops_eval_depth - 1
104105 target = args [ 1 ]
@@ -191,7 +192,7 @@ def self.hook_log_message(args)
191192 str = msg . respond_to? ( :multiline ) ? msg . multiline : msg . to_s
192193 str = msg . source == 'Puppet' ? str : "#{ msg . source } : #{ str } "
193194
194- level = msg . level . to_s . capitalize
195+ level = msg . level . to_s . capitalize
195196
196197 category = 'stderr'
197198 category = 'stdout' if msg . level == :notice || msg . level == :info || msg . level == :debug
0 commit comments