Sha256: 6c0790fe4b8739db9954372b10340ddd54c852603334f8c45a8d1aaf6305a171

Contents?: true

Size: 1.11 KB

Versions: 18

Compression:

Stored size: 1.11 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" if file_parts.empty?

            # 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(":")
            line_as_number = line ? Integer(line.to_i) - 1 : 0

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ruby-lsp-rails-0.3.31 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.30 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.29 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.28 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.27 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.26 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.25 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.24 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.23 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.22 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.21 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.20 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.19 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.18 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.17 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.16 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.15 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb
ruby-lsp-rails-0.3.14 lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb