Sha256: 9c631b7c3c7d689e6eb44d60a0135d024f0995edf9d1e91f82de3e65146475c5

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

module Byebug::DAP
  class Command::Scopes < Command
    # "The request returns the variable scopes for a given stackframe ID.

    register!

    def execute
      started!

      frame, thnum, frnum = resolve_frame_id(args.frameId)
      return unless frame

      scopes = []

      locals = frame_local_names(frame).sort
      unless locals.empty?
        scopes << Protocol::Scope.new(
          name: 'Locals',
          presentationHint: 'locals',
          variablesReference: @session.save_variables(thnum, frnum, :locals, locals),
          namedVariables: locals.size,
          indexedVariables: 0,
          expensive: false)
          .validate!
      end

      globals = global_names.sort
      unless globals.empty?
        scopes << Protocol::Scope.new(
          name: 'Globals',
          presentationHint: 'globals',
          variablesReference: @session.save_variables(thnum, frnum, :globals, globals),
          namedVariables: globals.size,
          indexedVariables: 0,
          expensive: true)
          .validate!
      end

      respond! body: Protocol::ScopesResponseBody.new(scopes: scopes)
    end

    private

    def frame_local_names(frame)
      locals = frame.locals
      locals = locals.keys unless locals == [] # BUG in Byebug?
      locals << :self if frame._self.to_s != 'main'
      locals << :$! if frame.pos == 0 && !frame.context.processor.last_exception.nil?
      locals
    end

    def global_names
      global_variables - %i[$IGNORECASE $= $KCODE $-K $binding]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
byebug-dap-0.1.4 lib/byebug/dap/commands/scopes.rb