Class: RubyLsp::Document::Scanner

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/ruby_lsp/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Scanner

Returns a new instance of Scanner.



117
118
119
120
121
# File 'lib/ruby_lsp/document.rb', line 117

def initialize(source)
  @current_line = T.let(0, Integer)
  @pos = T.let(0, Integer)
  @source = source
end

Instance Method Details

#find_position(position) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/ruby_lsp/document.rb', line 124

def find_position(position)
  until @current_line == position[:line]
    @pos += 1 until /\R/.match?(@source[@pos])
    @pos += 1
    @current_line += 1
  end

  @pos + position[:character]
end