Class: ThemeCheck::LanguageServer::Diagnostic
- Inherits:
-
Object
- Object
- ThemeCheck::LanguageServer::Diagnostic
- Includes:
- URIHelper
- Defined in:
- lib/theme_check/language_server/diagnostic.rb
Instance Attribute Summary collapse
-
#offense ⇒ Object
readonly
Returns the value of attribute offense.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #absolute_path ⇒ Object
- #code ⇒ Object
- #code_description ⇒ Object
- #correctable? ⇒ Boolean
- #data ⇒ Object
- #end_index ⇒ Object
- #file_version ⇒ Object
-
#initialize(offense) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #message ⇒ Object
- #range ⇒ Object
- #relative_path ⇒ Object
- #severity ⇒ Object
- #single_file? ⇒ Boolean
- #start_index ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #uri ⇒ Object
- #whole_theme? ⇒ Boolean
Methods included from URIHelper
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
#offense ⇒ Object (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_path ⇒ Object
102 103 104 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 102 def absolute_path @absolute_path ||= offense&.theme_file&.path end |
#code ⇒ Object
54 55 56 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 54 def code offense.code_name end |
#code_description ⇒ Object
62 63 64 65 66 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 62 def code_description { href: offense.doc, } end |
#correctable? ⇒ Boolean
50 51 52 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 50 def correctable? offense.correctable? end |
#data ⇒ Object
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_index ⇒ Object
98 99 100 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 98 def end_index offense.end_index end |
#file_version ⇒ Object
114 115 116 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 114 def file_version @version ||= offense&.version end |
#message ⇒ Object
58 59 60 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 58 def offense. end |
#range ⇒ Object
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_path ⇒ Object
106 107 108 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 106 def relative_path @relative_path ||= offense&.theme_file&.relative_path end |
#severity ⇒ Object
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
42 43 44 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 42 def single_file? offense.single_file? end |
#start_index ⇒ Object
94 95 96 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 94 def start_index offense.start_index end |
#to_h ⇒ Object
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: , range: range, severity: severity, data: data, } @diagnostic[:codeDescription] = code_description unless offense.doc.nil? @diagnostic end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 38 def to_s to_h.to_s end |
#uri ⇒ Object
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
46 47 48 |
# File 'lib/theme_check/language_server/diagnostic.rb', line 46 def whole_theme? offense.whole_theme? end |