Class: RubyLsp::Rails::Support::LocationBuilder

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

Class Method Summary collapse

Class Method Details

.line_location_from_s(location_string) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb', line 12

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