Sha256: ad28b7920920fec28d68cee6fd8aaa4f3c3f67429fc0097a01a46fc17c44cdda

Contents?: true

Size: 590 Bytes

Versions: 8

Compression:

Stored size: 590 Bytes

Contents

# frozen_string_literal: true
# Note: Everything is 0-indexed here.

module ThemeCheck
  module LanguageServer
    module PositionHelper
      def from_line_column_to_index(content, row, col)
        i = 0
        result = 0
        lines = content.lines
        while i < row
          result += lines[i].size
          i += 1
        end
        result += col
        result
      end

      def from_index_to_line_column(content, index)
        lines = content[0..index].lines
        row = lines.size - 1
        col = lines.last.size - 1
        [row, col]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
theme-check-0.8.0 lib/theme_check/language_server/position_helper.rb
theme-check-0.7.3 lib/theme_check/language_server/position_helper.rb
theme-check-0.7.2 lib/theme_check/language_server/position_helper.rb
theme-check-0.7.1 lib/theme_check/language_server/position_helper.rb
theme-check-0.7.0 lib/theme_check/language_server/position_helper.rb
theme-check-0.6.0 lib/theme_check/language_server/position_helper.rb
theme-check-0.5.0 lib/theme_check/language_server/position_helper.rb
theme-check-0.4.0 lib/theme_check/language_server/position_helper.rb