class TypeProf::CodeLocation

Attributes

column[R]
lineno[R]

Public Class Methods

from_lsp(lsp_loc) click to toggle source
# File typeprof-0.21.2/lib/typeprof/code-range.rb, line 15
def self.from_lsp(lsp_loc)
  # In the Language Server Protocol, lineno and column are both 0-origin
  CodeLocation.new(lsp_loc[:line] + 1, lsp_loc[:character])
end
new(lineno, column) click to toggle source

In Ruby, lineno is 1-origin, and column is 0-origin

# File typeprof-0.21.2/lib/typeprof/code-range.rb, line 4
def initialize(lineno, column)
  @lineno = lineno
  @column = column
end

Public Instance Methods

<=>(other) click to toggle source
# File typeprof-0.21.2/lib/typeprof/code-range.rb, line 42
def <=>(other)
  ret = @lineno <=> other.lineno
  return ret if ret != 0
  @column <=> other.column
end
advance_cursor(offset, source_text) click to toggle source
# File typeprof-0.21.2/lib/typeprof/code-range.rb, line 24
def advance_cursor(offset, source_text)
  new_lineno = @lineno
  new_column = @column
  while offset > 0
    line_text = source_text.lines[new_lineno - 1]
    if new_column + offset >= line_text.length
      advanced = line_text.length - new_column
      offset -= advanced
      new_lineno += 1
      new_column = 0
    else
      new_column += offset
      break
    end
  end
  CodeLocation.new(new_lineno, new_column)
end
inspect() click to toggle source
# File typeprof-0.21.2/lib/typeprof/code-range.rb, line 9
def inspect
  "(%d,%d)" % [@lineno, @column]
end
to_lsp() click to toggle source
# File typeprof-0.21.2/lib/typeprof/code-range.rb, line 20
def to_lsp
  { line: @lineno - 1, character: @column }
end