class Solargraph::Source::Cursor


there.
Information about a position in a source, including the word located

def argument?

Returns:
  • (Boolean) -
def argument?
  @argument ||= !signature_position.nil?
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_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
  return nil unless argument?
  @recipient ||= Cursor.new(source, signature_position)
end

def signature_position

def signature_position
  if @signature_position.nil?
    open_parens = 0
    cursor = offset - 1
    while cursor >= 0
      break if cursor < 0
      if source.code[cursor] == ')'
        open_parens -= 1
      elsif source.code[cursor] == '('
        open_parens += 1
      end
      break if open_parens == 1
      cursor -= 1
    end
    if cursor >= 0
      @signature_position = Position.from_offset(source.code, cursor)
    end
  end
  @signature_position
end

def start_of_constant?

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