Class: Byebug::DAP::ContextualCommand Abstract

Inherits:
Command
  • Object
show all
Defined in:
lib/byebug/dap/contextual_command.rb

Overview

This class is abstract.

Subclasses must implement #execute_in_context

Implementation of a DAP command that must be executed in-context.

Constant Summary

Constants inherited from Command

Byebug::DAP::Command::EVAL_ERROR

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

command, execute, #execute_on_thread, #log, register!, #safe_execute, #started!, #stopped!

Methods included from SafeHelpers

#safe

Constructor Details

#initialize(session, request, processor = nil) ⇒ ContextualCommand

Create a new instance of the receiver.

Parameters:

  • session (Session)

    the debug session

  • request (Protocol::Request)

    the DAP request

  • processor (CommandProcessor) (defaults to: nil)

    the command processor associated with the context



18
19
20
21
22
# File 'lib/byebug/dap/contextual_command.rb', line 18

def initialize(session, request, processor = nil)
  super(session, request)
  @processor = processor
  @context = processor&.context
end

Class Method Details

.resolve!(session, request) ⇒ std:Class

Note:

Raises an error if the resolved class is not a subclass of Byebug::DAP::ContextualCommand

Resolve the requested command. Calls Session#respond! indicating a failed request if the command cannot be found.

Parameters:

  • session (Session)

    the debug session

  • request (Protocol::Request)

    the DAP request

Returns:



7
8
9
10
11
12
# File 'lib/byebug/dap/contextual_command.rb', line 7

def self.resolve!(session, request)
  return unless cls = super
  return cls if cls < ContextualCommand

  raise "Not a contextual command: #{command}"
end

Instance Method Details

#executeObject

Execute in-context if ‘processor` is defined. Otherwise, ensure debugging is started, find the requested thread context, and forward the request.



27
28
29
30
31
32
33
# File 'lib/byebug/dap/contextual_command.rb', line 27

def execute
  return execute_in_context if @processor

  started!

  forward_to_context find_thread(args.threadId)
end

#forward_to_context(ctx) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Forward the request to the context’s thread.

Parameters:

  • ctx (gem:byebug:Byebug::Context)

    the context



41
42
43
# File 'lib/byebug/dap/contextual_command.rb', line 41

def forward_to_context(ctx)
  ctx.processor << @request
end