Class: TypeProf::Diagnostic
- Inherits:
-
Object
- Object
- TypeProf::Diagnostic
- Defined in:
- lib/typeprof/diagnostic.rb
Constant Summary collapse
- SEVERITY =
{ error: 1, warning: 2, info: 3, hint: 4 }
- TAG =
{ unnecessary: 1, deprecated: 2 }
Instance Attribute Summary collapse
-
#msg ⇒ Object
readonly
Returns the value of attribute msg.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #code_range ⇒ Object
-
#initialize(node, meth, msg, tags: nil) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #reuse(new_node) ⇒ Object
- #to_lsp(severity: :error) ⇒ Object
Constructor Details
#initialize(node, meth, msg, tags: nil) ⇒ Diagnostic
Returns a new instance of Diagnostic.
3 4 5 6 7 8 |
# File 'lib/typeprof/diagnostic.rb', line 3 def initialize(node, meth, msg, tags: nil) @node = node @meth = meth @msg = msg = end |
Instance Attribute Details
#msg ⇒ Object (readonly)
Returns the value of attribute msg.
14 15 16 |
# File 'lib/typeprof/diagnostic.rb', line 14 def msg @msg end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
14 15 16 |
# File 'lib/typeprof/diagnostic.rb', line 14 def node @node end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
14 15 16 |
# File 'lib/typeprof/diagnostic.rb', line 14 def end |
Instance Method Details
#code_range ⇒ Object
16 17 18 |
# File 'lib/typeprof/diagnostic.rb', line 16 def code_range @node.send(@meth) end |
#reuse(new_node) ⇒ Object
10 11 12 |
# File 'lib/typeprof/diagnostic.rb', line 10 def reuse(new_node) @node = new_node end |
#to_lsp(severity: :error) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/typeprof/diagnostic.rb', line 23 def to_lsp(severity: :error) json = { range: code_range.to_lsp, source: "TypeProf", message: @msg, } json[:severity] = SEVERITY[severity] json[:tags] = .map {|tag| TAG[tag] } if json end |