Class: ThemeCheck::LanguageServer::Diagnostic

Inherits:
Object
  • Object
show all
Includes:
URIHelper
Defined in:
lib/theme_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/theme_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/theme_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/theme_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



102
103
104
# File 'lib/theme_check/language_server/diagnostic.rb', line 102

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

#codeObject



54
55
56
# File 'lib/theme_check/language_server/diagnostic.rb', line 54

def code
  offense.code_name
end

#code_descriptionObject



62
63
64
65
66
# File 'lib/theme_check/language_server/diagnostic.rb', line 62

def code_description
  {
    href: offense.doc,
  }
end

#correctable?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/theme_check/language_server/diagnostic.rb', line 50

def correctable?
  offense.correctable?
end

#dataObject



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

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

#end_indexObject



98
99
100
# File 'lib/theme_check/language_server/diagnostic.rb', line 98

def end_index
  offense.end_index
end

#file_versionObject



114
115
116
# File 'lib/theme_check/language_server/diagnostic.rb', line 114

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

#messageObject



58
59
60
# File 'lib/theme_check/language_server/diagnostic.rb', line 58

def message
  offense.message
end

#rangeObject



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

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

#relative_pathObject



106
107
108
# File 'lib/theme_check/language_server/diagnostic.rb', line 106

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

#severityObject



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

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

#single_file?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/theme_check/language_server/diagnostic.rb', line 42

def single_file?
  offense.single_file?
end

#start_indexObject



94
95
96
# File 'lib/theme_check/language_server/diagnostic.rb', line 94

def start_index
  offense.start_index
end

#to_hObject



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

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

#to_sObject



38
39
40
# File 'lib/theme_check/language_server/diagnostic.rb', line 38

def to_s
  to_h.to_s
end

#uriObject



110
111
112
# File 'lib/theme_check/language_server/diagnostic.rb', line 110

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

#whole_theme?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/theme_check/language_server/diagnostic.rb', line 46

def whole_theme?
  offense.whole_theme?
end