class Solargraph::Source::Cursor


word located there.
Information about a single Position in a Source, including the

def argument?

Returns:
  • (Boolean) -
def argument?
  # @argument ||= !signature_position.nil?

  @argument ||= !recipient.nil?
end

def assign?

Returns:
  • (Boolean) -
def assign?
  [:lvasgn, :ivasgn, :gvasgn, :cvasgn].include? chain&.node&.type
end

def chain

Returns:
  • (Chain) -
def chain
  @chain ||= SourceChainer.chain(source, position)
end

def comment?

Returns:
  • (Boolean) -
def comment?
  @comment ||= source.comment_at?(position)
end

def end_of_word

Returns:
  • (String) -
def end_of_word
  @end_of_word ||= begin
    match = source.code[offset..-1].to_s.match(end_word_pattern)
    match ? match[0] : ''
  end
end

def end_word_pattern

Returns:
  • (Regexp) -
def end_word_pattern
  /^([a-z0-9_]|[^\u0000-\u007F])*[\?\!]?/i
end

def filename

Returns:
  • (String) -
def filename
  source.filename
end

def initialize source, position

Parameters:
  • position (Position, Array(Integer, Integer)) --
  • source (Source) --
def initialize source, position
  @source = source
  @position = Position.normalize(position)
end

def node

Returns:
  • (AST::Node) -
def node
  @node ||= source.node_at(position.line, position.column)
end

def node_position

Returns:
  • (Position) -
def node_position
  @node_position ||= begin
    if start_of_word.empty?
      match = source.code[0, offset].match(/[\s]*(\.|:+)[\s]*$/)
      if match
        Position.from_offset(source.code, offset - match[0].length)
      else
        position
      end
    else
      position
    end
  end
end

def offset

Returns:
  • (Integer) -
def offset
  @offset ||= Position.to_offset(source.code, position)
end

def range

Returns:
  • (Range) -
def range
  @range ||= begin
    s = Position.from_offset(source.code, offset - start_of_word.length)
    e = Position.from_offset(source.code, offset + end_of_word.length)
    Solargraph::Range.new(s, e)
  end
end

def recipient

Returns:
  • (Cursor, nil) -
def recipient
  @recipient ||= begin
    node = recipient_node
    node ? Cursor.new(source, Range.from_node(node).ending) : nil
  end
end

def recipient_node

Returns:
  • (Parser::AST::Node, nil) -
def recipient_node
  @recipient_node ||= Solargraph::Parser::NodeMethods.find_recipient_node(self)
end

def start_of_constant?

Returns:
  • (Boolean) -
def start_of_constant?
  source.code[offset-2, 2] == '::'
end

def start_of_word

Returns:
  • (String) -
def start_of_word
  @start_of_word ||= begin
    match = source.code[0..offset-1].to_s.match(start_word_pattern)
    result = (match ? match[0] : '')
    # Including the preceding colon if the word appears to be a symbol

    result = ":#{result}" if source.code[0..offset-result.length-1].end_with?(':') and !source.code[0..offset-result.length-1].end_with?('::')
    result
  end
end

def start_word_pattern

Returns:
  • (Regexp) -
def start_word_pattern
  /(@{1,2}|\$)?([a-z0-9_]|[^\u0000-\u007F])*\z/i
end

def string?

Returns:
  • (Boolean) -
def string?
  @string ||= source.string_at?(position)
end

def word

Returns:
  • (String) -
def word
  @word ||= start_of_word + end_of_word
end