Class: Solargraph::Parser::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/parser/region.rb

Overview

Data used by the parser to track context at various locations in a source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source: Solargraph::Source.load_string(''), closure: nil, scope: nil, visibility: :public, lvars: []) ⇒ Region



28
29
30
31
32
33
34
35
36
# File 'lib/solargraph/parser/region.rb', line 28

def initialize source: Solargraph::Source.load_string(''), closure: nil,
               scope: nil, visibility: :public, lvars: []
  @source = source
  # @closure = closure

  @closure = closure || Pin::Namespace.new(name: '', location: source.location, source: :parser)
  @scope = scope
  @visibility = visibility
  @lvars = lvars
end

Instance Attribute Details

#closurePin::Closure (readonly)



10
11
12
# File 'lib/solargraph/parser/region.rb', line 10

def closure
  @closure
end

#lvarsArray<Symbol> (readonly)



22
23
24
# File 'lib/solargraph/parser/region.rb', line 22

def lvars
  @lvars
end

#scopeSymbol (readonly)



13
14
15
# File 'lib/solargraph/parser/region.rb', line 13

def scope
  @scope
end

#sourceSolargraph::Source (readonly)



19
20
21
# File 'lib/solargraph/parser/region.rb', line 19

def source
  @source
end

#visibilitySymbol (readonly)



16
17
18
# File 'lib/solargraph/parser/region.rb', line 16

def visibility
  @visibility
end

Instance Method Details

#code_for(node) ⇒ String



61
62
63
# File 'lib/solargraph/parser/region.rb', line 61

def code_for node
  source.code_for(node)
end

#filenameString



39
40
41
# File 'lib/solargraph/parser/region.rb', line 39

def filename
  source.filename
end

#update(closure: nil, scope: nil, visibility: nil, lvars: nil) ⇒ Region

Generate a new Region with the provided attribute changes.



49
50
51
52
53
54
55
56
57
# File 'lib/solargraph/parser/region.rb', line 49

def update closure: nil, scope: nil, visibility: nil, lvars: nil
  Region.new(
    source: source,
    closure: closure || self.closure,
    scope: scope || self.scope,
    visibility: visibility || self.visibility,
    lvars: lvars || self.lvars
  )
end