Sha256: 82c9235b3442145add3952c7007de4cab76c823dd60778acd19721e10e788f0b

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  # This class allows listeners to access contextual information about a node in the AST, such as its parent,
  # its namespace nesting, and the surrounding CallNode (e.g. a method call).
  class NodeContext
    extend T::Sig

    sig { returns(T.nilable(Prism::Node)) }
    attr_reader :node, :parent

    sig { returns(T::Array[String]) }
    attr_reader :nesting

    sig { returns(T.nilable(Prism::CallNode)) }
    attr_reader :call_node

    sig { returns(T.nilable(String)) }
    attr_reader :surrounding_method

    sig do
      params(
        node: T.nilable(Prism::Node),
        parent: T.nilable(Prism::Node),
        nesting: T::Array[String],
        call_node: T.nilable(Prism::CallNode),
        surrounding_method: T.nilable(String),
      ).void
    end
    def initialize(node, parent, nesting, call_node, surrounding_method)
      @node = node
      @parent = parent
      @nesting = nesting
      @call_node = call_node
      @surrounding_method = surrounding_method
    end

    sig { returns(String) }
    def fully_qualified_name
      @fully_qualified_name ||= T.let(@nesting.join("::"), T.nilable(String))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-lsp-0.17.6 lib/ruby_lsp/node_context.rb
ruby-lsp-0.17.5 lib/ruby_lsp/node_context.rb
ruby-lsp-0.17.4 lib/ruby_lsp/node_context.rb