Class: PlatformosCheck::LanguageServer::Diagnostic

Inherits:
Object
  • Object
show all
Includes:
URIHelper
Defined in:
lib/platformos_check/language_server/diagnostic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from URIHelper

#file_path, #file_uri

Constructor Details

#initialize(offense) ⇒ Diagnostic

Returns a new instance of Diagnostic.



10
11
12
13
# File 'lib/platformos_check/language_server/diagnostic.rb', line 10

def initialize(offense)
  @offense = offense
  @diagnostic = nil
end

Instance Attribute Details

#offenseObject (readonly)

Returns the value of attribute offense.



8
9
10
# File 'lib/platformos_check/language_server/diagnostic.rb', line 8

def offense
  @offense
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/platformos_check/language_server/diagnostic.rb', line 15

def ==(other)
  case other
  when Hash, Diagnostic
    to_h == other.to_h
  else
    raise ArgumentError
  end
end

#absolute_pathObject



103
104
105
# File 'lib/platformos_check/language_server/diagnostic.rb', line 103

def absolute_path
  @absolute_path ||= offense&.app_file&.path
end

#codeObject



55
56
57
# File 'lib/platformos_check/language_server/diagnostic.rb', line 55

def code
  offense.code_name
end

#code_descriptionObject



63
64
65
66
67
# File 'lib/platformos_check/language_server/diagnostic.rb', line 63

def code_description
  {
    href: offense.doc
  }
end

#correctable?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/platformos_check/language_server/diagnostic.rb', line 51

def correctable?
  offense.correctable?
end

#dataObject



119
120
121
122
123
124
125
126
# File 'lib/platformos_check/language_server/diagnostic.rb', line 119

def data
  {
    absolute_path: absolute_path.to_s,
    relative_path: relative_path.to_s,
    uri:,
    version: file_version
  }
end

#end_indexObject



99
100
101
# File 'lib/platformos_check/language_server/diagnostic.rb', line 99

def end_index
  offense.end_index
end

#file_versionObject



115
116
117
# File 'lib/platformos_check/language_server/diagnostic.rb', line 115

def file_version
  @version ||= offense&.version
end

#messageObject



59
60
61
# File 'lib/platformos_check/language_server/diagnostic.rb', line 59

def message
  offense.message
end

#rangeObject



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/platformos_check/language_server/diagnostic.rb', line 82

def range
  {
    start: {
      line: offense.start_row,
      character: offense.start_column
    },
    end: {
      line: offense.end_row,
      character: offense.end_column
    }
  }
end

#relative_pathObject



107
108
109
# File 'lib/platformos_check/language_server/diagnostic.rb', line 107

def relative_path
  @relative_path ||= offense&.app_file&.relative_path
end

#severityObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/platformos_check/language_server/diagnostic.rb', line 69

def severity
  case offense.severity
  when :error
    1
  when :suggestion
    2
  when :style
    3
  else
    4
  end
end

#single_file?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/platformos_check/language_server/diagnostic.rb', line 43

def single_file?
  offense.single_file?
end

#start_indexObject



95
96
97
# File 'lib/platformos_check/language_server/diagnostic.rb', line 95

def start_index
  offense.start_index
end

#to_hObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/platformos_check/language_server/diagnostic.rb', line 24

def to_h
  return @diagnostic unless @diagnostic.nil?

  @diagnostic = {
    source: "platformos-check",
    code:,
    message:,
    range:,
    severity:,
    data:
  }
  @diagnostic[:codeDescription] = code_description unless offense.doc.nil?
  @diagnostic
end

#to_sObject



39
40
41
# File 'lib/platformos_check/language_server/diagnostic.rb', line 39

def to_s
  to_h.to_s
end

#uriObject



111
112
113
# File 'lib/platformos_check/language_server/diagnostic.rb', line 111

def uri
  @uri ||= absolute_path && file_uri(absolute_path)
end

#whole_platformos_app?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/platformos_check/language_server/diagnostic.rb', line 47

def whole_platformos_app?
  offense.whole_platformos_app?
end