Class: RubyLsp::ResponseBuilders::TestCollection

Inherits:
ResponseBuilder show all
Defined in:
lib/ruby_lsp/response_builders/test_collection.rb

Overview

: [ResponseType = Requests::Support::TestItem]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestCollection

: -> void



12
13
14
15
16
# File 'lib/ruby_lsp/response_builders/test_collection.rb', line 12

def initialize
  super
  @items = {} #: Hash[String, ResponseType]
  @code_lens = [] #: Array[Interface::CodeLens]
end

Instance Attribute Details

#code_lensObject (readonly)

: Array



9
10
11
# File 'lib/ruby_lsp/response_builders/test_collection.rb', line 9

def code_lens
  @code_lens
end

Instance Method Details

#[](id) ⇒ Object

: (String id) -> ResponseType?



49
50
51
# File 'lib/ruby_lsp/response_builders/test_collection.rb', line 49

def [](id)
  @items[id]
end

#add(item) ⇒ Object

: (ResponseType item) -> void



19
20
21
# File 'lib/ruby_lsp/response_builders/test_collection.rb', line 19

def add(item)
  @items[item.id] = item
end

#add_code_lens(item) ⇒ Object

: (ResponseType item) -> void



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_lsp/response_builders/test_collection.rb', line 24

def add_code_lens(item)
  arguments = [item.uri.to_standardized_path, item.id]
  start = item.range.start
  range = Interface::Range.new(
    start: start,
    end: Interface::Position.new(line: start.line, character: start.character + 1),
  )

  @code_lens << Interface::CodeLens.new(
    range: range,
    data: { arguments: arguments, kind: "run_test" },
  )

  @code_lens << Interface::CodeLens.new(
    range: range,
    data: { arguments: arguments, kind: "run_test_in_terminal" },
  )

  @code_lens << Interface::CodeLens.new(
    range: range,
    data: { arguments: arguments, kind: "debug_test" },
  )
end

#responseObject

: -> Array



55
56
57
# File 'lib/ruby_lsp/response_builders/test_collection.rb', line 55

def response
  @items.values
end