|
14 | 14 | module RubyLsp |
15 | 15 | module RSpec |
16 | 16 | class Addon < ::RubyLsp::Addon |
17 | | - extend T::Sig |
| 17 | + FORMATTER_PATH = File.expand_path("rspec_formatter.rb", __dir__) #: String |
| 18 | + FORMATTER_NAME = "RubyLsp::RSpec::RSpecFormatter" #: String |
18 | 19 |
|
19 | | - FORMATTER_PATH = T.let(File.expand_path("rspec_formatter.rb", __dir__), String) |
20 | | - FORMATTER_NAME = T.let("RubyLsp::RSpec::RSpecFormatter", String) |
21 | | - |
22 | | - sig { returns(T::Boolean) } |
| 20 | + #: bool |
23 | 21 | attr_reader :debug |
24 | 22 |
|
25 | | - sig { void } |
| 23 | + #: -> void |
26 | 24 | def initialize |
27 | 25 | super |
28 | | - @debug = T.let(false, T::Boolean) |
29 | | - @rspec_command = T.let(nil, T.nilable(String)) |
| 26 | + @debug = false #: bool |
| 27 | + @rspec_command = nil #: String? |
30 | 28 | end |
31 | 29 |
|
32 | | - sig { override.params(global_state: GlobalState, message_queue: Thread::Queue).void } |
| 30 | + # @override |
| 31 | + #: (GlobalState, Thread::Queue) -> void |
33 | 32 | def activate(global_state, message_queue) |
34 | | - @index = T.let(global_state.index, T.nilable(RubyIndexer::Index)) |
| 33 | + @index = global_state.index #: RubyIndexer::Index? |
35 | 34 |
|
36 | 35 | settings = global_state.settings_for_addon(name) |
37 | 36 | @rspec_command = rspec_command(settings) |
38 | | - @workspace_path = T.let(global_state.workspace_path, T.nilable(String)) |
| 37 | + @workspace_path = global_state.workspace_path #: String? |
39 | 38 | @debug = settings&.dig(:debug) || false |
40 | 39 | end |
41 | 40 |
|
42 | | - sig { override.void } |
| 41 | + # @override |
| 42 | + #: -> void |
43 | 43 | def deactivate; end |
44 | 44 |
|
45 | | - sig { override.returns(String) } |
| 45 | + # @override |
| 46 | + #: -> String |
46 | 47 | def name |
47 | 48 | "ruby-lsp-rspec" |
48 | 49 | end |
49 | 50 |
|
50 | | - sig { override.returns(String) } |
| 51 | + # @override |
| 52 | + #: -> String |
51 | 53 | def version |
52 | 54 | VERSION |
53 | 55 | end |
54 | 56 |
|
55 | 57 | # Creates a new CodeLens listener. This method is invoked on every CodeLens request |
56 | | - sig do |
57 | | - override.params( |
58 | | - response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens], |
59 | | - uri: URI::Generic, |
60 | | - dispatcher: Prism::Dispatcher, |
61 | | - ).void |
62 | | - end |
| 58 | + # @override |
| 59 | + #: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens], URI::Generic, Prism::Dispatcher) -> void |
63 | 60 | def create_code_lens_listener(response_builder, uri, dispatcher) |
64 | 61 | return unless uri.to_standardized_path&.end_with?("_test.rb") || uri.to_standardized_path&.end_with?("_spec.rb") |
65 | 62 |
|
66 | | - CodeLens.new(response_builder, uri, dispatcher, T.must(@rspec_command), debug: debug) |
| 63 | + CodeLens.new( |
| 64 | + response_builder, |
| 65 | + uri, |
| 66 | + dispatcher, |
| 67 | + @rspec_command, #: as !nil |
| 68 | + debug: debug, |
| 69 | + ) |
67 | 70 | end |
68 | 71 |
|
69 | 72 | # Creates a new Discover Tests listener. This method is invoked on every DiscoverTests request |
70 | | - sig do |
71 | | - override.params( |
72 | | - response_builder: ResponseBuilders::TestCollection, |
73 | | - dispatcher: Prism::Dispatcher, |
74 | | - uri: URI::Generic, |
75 | | - ).void |
76 | | - end |
| 73 | + # @override |
| 74 | + #: (ResponseBuilders::TestCollection, Prism::Dispatcher, URI::Generic) -> void |
77 | 75 | def create_discover_tests_listener(response_builder, dispatcher, uri) |
78 | 76 | return unless uri.to_standardized_path&.end_with?("_spec.rb") |
79 | 77 |
|
80 | | - TestDiscovery.new(response_builder, dispatcher, uri, T.must(@workspace_path)) |
| 78 | + TestDiscovery.new( |
| 79 | + response_builder, |
| 80 | + dispatcher, |
| 81 | + uri, |
| 82 | + @workspace_path, #: as !nil |
| 83 | + ) |
81 | 84 | end |
82 | 85 |
|
83 | 86 | # Resolves the minimal set of commands required to execute the requested tests |
84 | | - sig do |
85 | | - override.params( |
86 | | - items: T::Array[T::Hash[Symbol, T.untyped]], |
87 | | - ).returns(T::Array[String]) |
88 | | - end |
| 87 | + # @override |
| 88 | + #: (Array[Hash[Symbol, untyped]]) -> Array[String] |
89 | 89 | def resolve_test_commands(items) |
90 | 90 | commands = [] |
91 | 91 | queue = items.dup |
92 | 92 |
|
93 | 93 | full_files = [] |
94 | 94 |
|
95 | 95 | until queue.empty? |
96 | | - item = T.must(queue.shift) |
| 96 | + item = queue.shift #: as !nil |
97 | 97 | tags = Set.new(item[:tags]) |
98 | 98 | next unless tags.include?("framework:rspec") |
99 | 99 |
|
@@ -128,33 +128,29 @@ def resolve_test_commands(items) |
128 | 128 | commands |
129 | 129 | end |
130 | 130 |
|
131 | | - sig do |
132 | | - override.params( |
133 | | - response_builder: ResponseBuilders::DocumentSymbol, |
134 | | - dispatcher: Prism::Dispatcher, |
135 | | - ).void |
136 | | - end |
| 131 | + # @override |
| 132 | + #: (ResponseBuilders::DocumentSymbol, Prism::Dispatcher) -> void |
137 | 133 | def create_document_symbol_listener(response_builder, dispatcher) |
138 | 134 | DocumentSymbol.new(response_builder, dispatcher) |
139 | 135 | end |
140 | 136 |
|
141 | | - sig do |
142 | | - override.params( |
143 | | - response_builder: ResponseBuilders::CollectionResponseBuilder[T.any(Interface::Location, Interface::LocationLink)], |
144 | | - uri: URI::Generic, |
145 | | - node_context: NodeContext, |
146 | | - dispatcher: Prism::Dispatcher, |
147 | | - ).void |
148 | | - end |
| 137 | + # @override |
| 138 | + #: (ResponseBuilders::CollectionResponseBuilder[Interface::Location | Interface::LocationLink], URI::Generic, NodeContext, Prism::Dispatcher) -> void |
149 | 139 | def create_definition_listener(response_builder, uri, node_context, dispatcher) |
150 | 140 | return unless uri.to_standardized_path&.end_with?("_test.rb") || uri.to_standardized_path&.end_with?("_spec.rb") |
151 | 141 |
|
152 | | - Definition.new(response_builder, uri, node_context, T.must(@index), dispatcher) |
| 142 | + Definition.new( |
| 143 | + response_builder, |
| 144 | + uri, |
| 145 | + node_context, |
| 146 | + @index, #: as !nil |
| 147 | + dispatcher, |
| 148 | + ) |
153 | 149 | end |
154 | 150 |
|
155 | 151 | private |
156 | 152 |
|
157 | | - sig { params(settings: T.nilable(T::Hash[Symbol, T.untyped])).returns(String) } |
| 153 | + #: (Hash[Symbol, untyped]?) -> String |
158 | 154 | def rspec_command(settings) |
159 | 155 | @rspec_command ||= settings&.dig(:rspecCommand) || begin |
160 | 156 | cmd = if File.exist?(File.join(Dir.pwd, "bin", "rspec")) |
|
0 commit comments