Class: Mui::Lsp::Protocol::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/mui/lsp/protocol/location.rb

Overview

LSP Location (URI and range)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, range:) ⇒ Location



12
13
14
15
# File 'lib/mui/lsp/protocol/location.rb', line 12

def initialize(uri:, range:)
  @uri = uri
  @range = range.is_a?(Range) ? range : Range.from_hash(range)
end

Instance Attribute Details

#rangeObject

Returns the value of attribute range.



10
11
12
# File 'lib/mui/lsp/protocol/location.rb', line 10

def range
  @range
end

#uriObject

Returns the value of attribute uri.



10
11
12
# File 'lib/mui/lsp/protocol/location.rb', line 10

def uri
  @uri
end

Class Method Details

.from_hash(hash) ⇒ Object



21
22
23
24
25
26
# File 'lib/mui/lsp/protocol/location.rb', line 21

def self.from_hash(hash)
  new(
    uri: hash["uri"] || hash[:uri],
    range: hash["range"] || hash[:range]
  )
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
38
# File 'lib/mui/lsp/protocol/location.rb', line 34

def ==(other)
  return false unless other.is_a?(Location)

  @uri == other.uri && @range == other.range
end

#file_pathObject



28
29
30
31
32
# File 'lib/mui/lsp/protocol/location.rb', line 28

def file_path
  return nil unless @uri&.start_with?("file://")

  URI.decode_www_form_component(@uri.sub("file://", ""))
end

#to_hObject



17
18
19
# File 'lib/mui/lsp/protocol/location.rb', line 17

def to_h
  { uri: @uri, range: @range.to_h }
end