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

Inherits:
Object
  • Object
show all
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

: (String location_string) -> Interface::Location

Raises:

  • (ArgumentError)


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

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