Class: LanguageServer::Protocol::Interface::Position

Inherits:
Object
  • Object
show all
Defined in:
lib/language_server/protocol/interface/position.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line:, character:) ⇒ Position

Returns a new instance of Position.



5
6
7
8
9
10
11
12
# File 'lib/language_server/protocol/interface/position.rb', line 5

def initialize(line:, character:)
  @attributes = {}

  @attributes[:line] = line
  @attributes[:character] = character

  @attributes.freeze
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



35
36
37
# File 'lib/language_server/protocol/interface/position.rb', line 35

def attributes
  @attributes
end

Instance Method Details

#characternumber

Character offset on a line in a document (zero-based). Assuming that the line is represented as a string, the ‘character` value represents the gap between the `character` and `character + 1`.

If the character value is greater than the line length it defaults back to the line length.

Returns:

  • (number)


31
32
33
# File 'lib/language_server/protocol/interface/position.rb', line 31

def character
  attributes.fetch(:character)
end

#linenumber

Line position in a document (zero-based).

Returns:

  • (number)


18
19
20
# File 'lib/language_server/protocol/interface/position.rb', line 18

def line
  attributes.fetch(:line)
end

#to_hashObject



37
38
39
# File 'lib/language_server/protocol/interface/position.rb', line 37

def to_hash
  attributes
end

#to_json(*args) ⇒ Object



41
42
43
# File 'lib/language_server/protocol/interface/position.rb', line 41

def to_json(*args)
  to_hash.to_json(*args)
end