Class: Mui::Lsp::Protocol::Diagnostic

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

Overview

LSP Diagnostic (error/warning/info/hint message)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range:, message:, severity: nil, code: nil, source: nil, related_information: nil) ⇒ Diagnostic

Returns a new instance of Diagnostic.



18
19
20
21
22
23
24
25
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 18

def initialize(range:, message:, severity: nil, code: nil, source: nil, related_information: nil)
  @range = range.is_a?(Range) ? range : Range.from_hash(range)
  @message = message
  @severity = severity
  @code = code
  @source = source
  @related_information = related_information
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



16
17
18
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 16

def code
  @code
end

#messageObject

Returns the value of attribute message.



16
17
18
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 16

def message
  @message
end

#rangeObject

Returns the value of attribute range.



16
17
18
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 16

def range
  @range
end

Returns the value of attribute related_information.



16
17
18
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 16

def related_information
  @related_information
end

#severityObject

Returns the value of attribute severity.



16
17
18
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 16

def severity
  @severity
end

#sourceObject

Returns the value of attribute source.



16
17
18
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 16

def source
  @source
end

Class Method Details

.from_hash(hash) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 39

def self.from_hash(hash)
  new(
    range: hash["range"] || hash[:range],
    message: hash["message"] || hash[:message],
    severity: hash["severity"] || hash[:severity],
    code: hash["code"] || hash[:code],
    source: hash["source"] || hash[:source],
    related_information: hash["relatedInformation"] || hash[:relatedInformation]
  )
end

Instance Method Details

#==(other) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 76

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

  @range == other.range &&
    @message == other.message &&
    @severity == other.severity &&
    @code == other.code &&
    @source == other.source
end

#error?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 50

def error?
  @severity == DiagnosticSeverity::ERROR
end

#hint?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 62

def hint?
  @severity == DiagnosticSeverity::HINT
end

#information?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 58

def information?
  @severity == DiagnosticSeverity::INFORMATION
end

#severity_nameObject



66
67
68
69
70
71
72
73
74
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 66

def severity_name
  case @severity
  when DiagnosticSeverity::ERROR then "Error"
  when DiagnosticSeverity::WARNING then "Warning"
  when DiagnosticSeverity::INFORMATION then "Information"
  when DiagnosticSeverity::HINT then "Hint"
  else "Unknown"
  end
end

#to_hObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 27

def to_h
  result = {
    range: @range.to_h,
    message: @message
  }
  result[:severity] = @severity if @severity
  result[:code] = @code if @code
  result[:source] = @source if @source
  result[:relatedInformation] = @related_information if @related_information
  result
end

#warning?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/mui/lsp/protocol/diagnostic.rb', line 54

def warning?
  @severity == DiagnosticSeverity::WARNING
end