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) ⇒ Diagnostic

Returns a new instance of Diagnostic.



3
4
5
6
7
8
9
# File 'lib/typeprof/diagnostic.rb', line 3

def initialize(node, meth, msg)
  @node = node
  @meth = meth
  @msg = msg
  @severity = :error # TODO: keyword argument
  @tags = nil # TODO: keyword argument
end

Instance Attribute Details

#msgObject (readonly)

Returns the value of attribute msg.



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

def msg
  @msg
end

#severityObject (readonly)

Returns the value of attribute severity.



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

def severity
  @severity
end

Instance Method Details

#code_rangeObject



17
18
19
# File 'lib/typeprof/diagnostic.rb', line 17

def code_range
  @node.send(@meth)
end

#reuse(new_node) ⇒ Object



11
12
13
# File 'lib/typeprof/diagnostic.rb', line 11

def reuse(new_node)
  @node = new_node
end

#to_lspObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/typeprof/diagnostic.rb', line 24

def to_lsp
  json = {
    range: code_range.to_lsp,
    source: "TypeProf",
    message: @msg,
  }
  json[:severity] = SEVERITY[@severity] if @severity
  json[:tags] = @tags.map {|tag| TAG[tag] } if @tags
  json
end