Sha256: cca349a28dfe8e3ac8302bf1712505c47b70aa81384214b2c40f6fc3557da4f0

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

# typed: strict
# frozen_string_literal: true

module RubyLsp
  module Rails
    module Support
      class LocationBuilder
        class << self
          extend T::Sig

          sig { params(location_string: String).returns(Interface::Location) }
          def line_location_from_s(location_string)
            *file_parts, line = location_string.split(":")

            raise ArgumentError, "Invalid location string given" unless file_parts

            # On Windows, file paths will look something like `C:/path/to/file.rb:123`. Only the last colon is the line
            # number and all other parts compose the file path
            file_path = file_parts.join(":")

            Interface::Location.new(
              uri: URI::Generic.from_path(path: file_path).to_s,
              range: Interface::Range.new(
                start: Interface::Position.new(line: Integer(line) - 1, character: 0),
                end: Interface::Position.new(line: Integer(line) - 1, character: 0),
              ),
            )
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruby-lsp-rails-0.3.13 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.12 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.11 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.10 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.9 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.8 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.7 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb