Class: TypeProf::Diagnostic

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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
  @tags = tags
end

Instance Attribute Details

#msgObject (readonly)

Returns the value of attribute msg.



14
15
16
# File 'lib/typeprof/diagnostic.rb', line 14

def msg
  @msg
end

#nodeObject (readonly)

Returns the value of attribute node.



14
15
16
# File 'lib/typeprof/diagnostic.rb', line 14

def node
  @node
end

#tagsObject (readonly)

Returns the value of attribute tags.



14
15
16
# File 'lib/typeprof/diagnostic.rb', line 14

def tags
  @tags
end

Instance Method Details

#code_rangeObject



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] = @tags.map {|tag| TAG[tag] } if @tags
  json
end