ruby-lsp 0.23.15 → 0.26.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/exe/ruby-lsp +17 -14
  4. data/exe/ruby-lsp-check +0 -4
  5. data/exe/ruby-lsp-launcher +41 -14
  6. data/exe/ruby-lsp-test-exec +6 -0
  7. data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +0 -1
  8. data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +0 -1
  9. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +4 -3
  10. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +42 -20
  11. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +1 -7
  12. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +49 -62
  13. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +84 -74
  14. data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +6 -9
  15. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +9 -14
  16. data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +12 -8
  17. data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +4 -4
  18. data/lib/ruby_lsp/addon.rb +44 -15
  19. data/lib/ruby_lsp/base_server.rb +56 -37
  20. data/lib/ruby_lsp/client_capabilities.rb +6 -1
  21. data/lib/ruby_lsp/document.rb +174 -62
  22. data/lib/ruby_lsp/erb_document.rb +10 -8
  23. data/lib/ruby_lsp/global_state.rb +86 -33
  24. data/lib/ruby_lsp/internal.rb +6 -3
  25. data/lib/ruby_lsp/listeners/completion.rb +22 -11
  26. data/lib/ruby_lsp/listeners/definition.rb +41 -21
  27. data/lib/ruby_lsp/listeners/document_highlight.rb +26 -1
  28. data/lib/ruby_lsp/listeners/document_link.rb +64 -28
  29. data/lib/ruby_lsp/listeners/hover.rb +27 -16
  30. data/lib/ruby_lsp/listeners/inlay_hints.rb +5 -3
  31. data/lib/ruby_lsp/listeners/semantic_highlighting.rb +2 -2
  32. data/lib/ruby_lsp/listeners/signature_help.rb +2 -2
  33. data/lib/ruby_lsp/listeners/spec_style.rb +155 -79
  34. data/lib/ruby_lsp/listeners/test_discovery.rb +39 -21
  35. data/lib/ruby_lsp/listeners/test_style.rb +75 -35
  36. data/lib/ruby_lsp/rbs_document.rb +3 -6
  37. data/lib/ruby_lsp/requests/code_action_resolve.rb +83 -58
  38. data/lib/ruby_lsp/requests/code_actions.rb +20 -5
  39. data/lib/ruby_lsp/requests/code_lens.rb +27 -6
  40. data/lib/ruby_lsp/requests/completion.rb +3 -3
  41. data/lib/ruby_lsp/requests/completion_resolve.rb +8 -6
  42. data/lib/ruby_lsp/requests/definition.rb +4 -7
  43. data/lib/ruby_lsp/requests/discover_tests.rb +2 -2
  44. data/lib/ruby_lsp/requests/document_highlight.rb +2 -2
  45. data/lib/ruby_lsp/requests/document_link.rb +1 -1
  46. data/lib/ruby_lsp/requests/folding_ranges.rb +1 -1
  47. data/lib/ruby_lsp/requests/go_to_relevant_file.rb +64 -12
  48. data/lib/ruby_lsp/requests/hover.rb +3 -6
  49. data/lib/ruby_lsp/requests/inlay_hints.rb +4 -4
  50. data/lib/ruby_lsp/requests/on_type_formatting.rb +1 -1
  51. data/lib/ruby_lsp/requests/prepare_rename.rb +1 -1
  52. data/lib/ruby_lsp/requests/references.rb +10 -21
  53. data/lib/ruby_lsp/requests/rename.rb +9 -10
  54. data/lib/ruby_lsp/requests/request.rb +8 -8
  55. data/lib/ruby_lsp/requests/selection_ranges.rb +2 -2
  56. data/lib/ruby_lsp/requests/semantic_highlighting.rb +1 -1
  57. data/lib/ruby_lsp/requests/show_syntax_tree.rb +2 -2
  58. data/lib/ruby_lsp/requests/signature_help.rb +2 -2
  59. data/lib/ruby_lsp/requests/support/annotation.rb +1 -1
  60. data/lib/ruby_lsp/requests/support/common.rb +9 -12
  61. data/lib/ruby_lsp/requests/support/formatter.rb +16 -15
  62. data/lib/ruby_lsp/requests/support/package_url.rb +414 -0
  63. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +7 -1
  64. data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +2 -2
  65. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +13 -3
  66. data/lib/ruby_lsp/requests/support/source_uri.rb +7 -4
  67. data/lib/ruby_lsp/requests/support/test_item.rb +7 -1
  68. data/lib/ruby_lsp/requests/workspace_symbol.rb +20 -12
  69. data/lib/ruby_lsp/response_builders/collection_response_builder.rb +1 -4
  70. data/lib/ruby_lsp/response_builders/document_symbol.rb +2 -3
  71. data/lib/ruby_lsp/response_builders/hover.rb +1 -4
  72. data/lib/ruby_lsp/response_builders/response_builder.rb +6 -7
  73. data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +4 -5
  74. data/lib/ruby_lsp/response_builders/signature_help.rb +1 -2
  75. data/lib/ruby_lsp/response_builders/test_collection.rb +29 -3
  76. data/lib/ruby_lsp/ruby_document.rb +14 -42
  77. data/lib/ruby_lsp/scripts/compose_bundle.rb +3 -3
  78. data/lib/ruby_lsp/scripts/compose_bundle_windows.rb +3 -1
  79. data/lib/ruby_lsp/server.rb +173 -130
  80. data/lib/ruby_lsp/setup_bundler.rb +114 -47
  81. data/lib/ruby_lsp/static_docs.rb +1 -0
  82. data/lib/ruby_lsp/store.rb +6 -16
  83. data/lib/ruby_lsp/test_helper.rb +1 -4
  84. data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +121 -17
  85. data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +65 -25
  86. data/lib/ruby_lsp/test_reporters/test_unit_reporter.rb +16 -18
  87. data/lib/ruby_lsp/utils.rb +102 -13
  88. data/static_docs/break.md +103 -0
  89. metadata +8 -33
  90. data/lib/ruby_indexer/test/class_variables_test.rb +0 -140
  91. data/lib/ruby_indexer/test/classes_and_modules_test.rb +0 -770
  92. data/lib/ruby_indexer/test/configuration_test.rb +0 -280
  93. data/lib/ruby_indexer/test/constant_test.rb +0 -402
  94. data/lib/ruby_indexer/test/enhancements_test.rb +0 -325
  95. data/lib/ruby_indexer/test/global_variable_test.rb +0 -49
  96. data/lib/ruby_indexer/test/index_test.rb +0 -2190
  97. data/lib/ruby_indexer/test/instance_variables_test.rb +0 -240
  98. data/lib/ruby_indexer/test/method_test.rb +0 -973
  99. data/lib/ruby_indexer/test/prefix_tree_test.rb +0 -150
  100. data/lib/ruby_indexer/test/rbs_indexer_test.rb +0 -380
  101. data/lib/ruby_indexer/test/reference_finder_test.rb +0 -330
  102. data/lib/ruby_indexer/test/test_case.rb +0 -51
  103. data/lib/ruby_indexer/test/uri_test.rb +0 -85
  104. data/lib/ruby_lsp/load_sorbet.rb +0 -62
@@ -10,7 +10,6 @@ rescue LoadError
10
10
  end
11
11
 
12
12
  require_relative "lsp_reporter"
13
- require "ruby_indexer/lib/ruby_indexer/uri"
14
13
 
15
14
  module RubyLsp
16
15
  class TestUnitReporter < Test::Unit::UI::Console::TestRunner
@@ -26,12 +25,12 @@ module RubyLsp
26
25
  def test_started(test)
27
26
  super
28
27
 
29
- current_test = test
30
- @current_uri = uri_for_test(current_test)
31
- return unless @current_uri
28
+ uri, line = LspReporter.uri_and_line_for(test.method(test.method_name))
29
+ return unless uri
32
30
 
33
- @current_test_id = "#{current_test.class.name}##{current_test.method_name}"
34
- LspReporter.instance.start_test(id: @current_test_id, uri: @current_uri)
31
+ @current_uri = uri
32
+ @current_test_id = "#{test.class.name}##{test.method_name}"
33
+ LspReporter.instance.start_test(id: @current_test_id, uri: @current_uri, line: line)
35
34
  end
36
35
 
37
36
  #: (::Test::Unit::TestCase test) -> void
@@ -59,21 +58,10 @@ module RubyLsp
59
58
 
60
59
  #: (Float) -> void
61
60
  def finished(elapsed_time)
61
+ super
62
62
  LspReporter.instance.shutdown
63
63
  end
64
64
 
65
- #: (::Test::Unit::TestCase test) -> URI::Generic?
66
- def uri_for_test(test)
67
- location = test.method(test.method_name).source_location
68
- return unless location
69
-
70
- file, _line = location
71
- return if file.start_with?("(eval at ")
72
-
73
- absolute_path = File.expand_path(file, Dir.pwd)
74
- URI::Generic.from_path(path: absolute_path)
75
- end
76
-
77
65
  #: -> void
78
66
  def attach_to_mediator
79
67
  # Events we care about
@@ -92,3 +80,13 @@ end
92
80
 
93
81
  Test::Unit::AutoRunner.register_runner(:ruby_lsp) { |_auto_runner| RubyLsp::TestUnitReporter }
94
82
  Test::Unit::AutoRunner.default_runner = :ruby_lsp
83
+
84
+ if RubyLsp::LspReporter.start_coverage?
85
+ Test::Unit.at_exit do
86
+ RubyLsp::LspReporter.instance.at_coverage_exit
87
+ end
88
+ elsif RubyLsp::LspReporter.executed_under_test_runner?
89
+ Test::Unit.at_exit do
90
+ RubyLsp::LspReporter.instance.at_exit
91
+ end
92
+ end
@@ -5,7 +5,6 @@ module RubyLsp
5
5
  # rubocop:disable RubyLsp/UseLanguageServerAliases
6
6
  Interface = LanguageServer::Protocol::Interface
7
7
  Constant = LanguageServer::Protocol::Constant
8
- Transport = LanguageServer::Protocol::Transport
9
8
  # rubocop:enable RubyLsp/UseLanguageServerAliases
10
9
 
11
10
  # Used to indicate that a request shouldn't return a response
@@ -20,6 +19,7 @@ module RubyLsp
20
19
  "Gemfile"
21
20
  end #: String
22
21
  GUESSED_TYPES_URL = "https://shopify.github.io/ruby-lsp/#guessed-types"
22
+ TEST_PATH_PATTERN = "**/{test,spec,features}/**/{*_test.rb,test_*.rb,*_spec.rb,*.feature}"
23
23
 
24
24
  # Request delegation for embedded languages is not yet standardized into the language server specification. Here we
25
25
  # use this custom error class as a way to return a signal to the client that the request should be delegated to the
@@ -31,29 +31,30 @@ module RubyLsp
31
31
  CODE = -32900
32
32
  end
33
33
 
34
+ class AbstractMethodInvokedError < StandardError; end
35
+
34
36
  BUNDLE_COMPOSE_FAILED_CODE = -33000
35
37
 
36
38
  # A notification to be sent to the client
39
+ # @abstract
37
40
  class Message
38
- extend T::Sig
39
- extend T::Helpers
40
-
41
41
  #: String
42
42
  attr_reader :method
43
43
 
44
44
  #: Object
45
45
  attr_reader :params
46
46
 
47
- abstract!
48
-
49
47
  #: (method: String, params: Object) -> void
50
48
  def initialize(method:, params:)
51
49
  @method = method
52
50
  @params = params
53
51
  end
54
52
 
55
- sig { abstract.returns(T::Hash[Symbol, T.untyped]) }
56
- def to_hash; end
53
+ # @abstract
54
+ #: -> Hash[Symbol, untyped]
55
+ def to_hash
56
+ raise AbstractMethodInvokedError
57
+ end
57
58
  end
58
59
 
59
60
  class Notification < Message
@@ -137,7 +138,12 @@ module RubyLsp
137
138
  #: -> Hash[Symbol, untyped]
138
139
  def to_hash
139
140
  hash = { method: @method }
140
- hash[:params] = T.unsafe(@params).to_hash if @params
141
+
142
+ if @params
143
+ hash[:params] = @params #: as untyped
144
+ .to_hash
145
+ end
146
+
141
147
  hash
142
148
  end
143
149
  end
@@ -181,7 +187,12 @@ module RubyLsp
181
187
  #: -> Hash[Symbol, untyped]
182
188
  def to_hash
183
189
  hash = { id: @id, method: @method }
184
- hash[:params] = T.unsafe(@params).to_hash if @params
190
+
191
+ if @params
192
+ hash[:params] = @params #: as untyped
193
+ .to_hash
194
+ end
195
+
185
196
  hash
186
197
  end
187
198
  end
@@ -236,9 +247,6 @@ module RubyLsp
236
247
 
237
248
  # A request configuration, to turn on/off features
238
249
  class RequestConfig
239
- #: Hash[Symbol, bool]
240
- attr_accessor :configuration
241
-
242
250
  #: (Hash[Symbol, bool] configuration) -> void
243
251
  def initialize(configuration)
244
252
  @configuration = configuration
@@ -248,5 +256,86 @@ module RubyLsp
248
256
  def enabled?(feature)
249
257
  @configuration[:enableAll] || @configuration[feature]
250
258
  end
259
+
260
+ #: (Hash[Symbol, bool]) -> void
261
+ def merge!(hash)
262
+ @configuration.merge!(hash)
263
+ end
264
+ end
265
+
266
+ class SorbetLevel
267
+ class << self
268
+ #: -> SorbetLevel
269
+ def ignore
270
+ new("ignore")
271
+ end
272
+ end
273
+
274
+ #: (String?) -> void
275
+ def initialize(sigil)
276
+ @level = case sigil
277
+ when "ignore"
278
+ :ignore
279
+ when "false"
280
+ :false
281
+ when "true"
282
+ :true
283
+ when "strict", "strong"
284
+ :strict
285
+ else
286
+ :none
287
+ end #: Symbol
288
+ end
289
+
290
+ #: -> bool
291
+ def ignore? = @level == :ignore
292
+
293
+ #: -> bool
294
+ def false? = @level == :false
295
+
296
+ #: -> bool
297
+ def true? = @level == :true
298
+
299
+ #: -> bool
300
+ def strict? = @level == :strict
301
+
302
+ #: -> bool
303
+ def none? = @level == :none
304
+
305
+ #: -> bool
306
+ def true_or_higher? = @level == :true || @level == :strict
307
+ end
308
+
309
+ # Reads JSON RPC messages from the given IO in a loop
310
+ class MessageReader
311
+ #: (IO) -> void
312
+ def initialize(io)
313
+ @io = io
314
+ end
315
+
316
+ #: () { (Hash[Symbol, untyped]) -> void } -> void
317
+ def each_message(&block)
318
+ while (headers = @io.gets("\r\n\r\n"))
319
+ raw_message = @io.read(headers[/Content-Length: (\d+)/i, 1].to_i) #: as !nil
320
+ block.call(JSON.parse(raw_message, symbolize_names: true))
321
+ end
322
+ end
323
+ end
324
+
325
+ # Writes JSON RPC messages to the given IO
326
+ class MessageWriter
327
+ #: (IO) -> void
328
+ def initialize(io)
329
+ @io = io
330
+ end
331
+
332
+ #: (Hash[Symbol, untyped]) -> void
333
+ def write(message)
334
+ message[:jsonrpc] = "2.0"
335
+ json_message = message.to_json
336
+
337
+ @io.write("Content-Length: #{json_message.bytesize}\r\n\r\n#{json_message}")
338
+ @io.flush
339
+ end
251
340
  end
252
341
  end
@@ -0,0 +1,103 @@
1
+ # Break
2
+
3
+ In Ruby, the `break` keyword is used to exit a loop or block prematurely. Unlike `next` which skips to the next iteration, `break` terminates the loop entirely and continues with the code after the loop.
4
+
5
+ ```ruby
6
+ # Basic break usage in a loop
7
+ 5.times do |i|
8
+ break if i == 3
9
+
10
+ puts i
11
+ end
12
+ # Output:
13
+ # 0
14
+ # 1
15
+ # 2
16
+ ```
17
+
18
+ The `break` statement can be used with any of Ruby's iteration methods or loops.
19
+
20
+ ```ruby
21
+ array = [1, 2, 3, 4, 5]
22
+
23
+ # Break in each iteration
24
+ array.each do |num|
25
+ break if num > 3
26
+
27
+ puts "Number: #{num}"
28
+ end
29
+ # Output:
30
+ # Number: 1
31
+ # Number: 2
32
+ # Number: 3
33
+
34
+ # Break in an infinite loop
35
+ count = 0
36
+ loop do
37
+ count += 1
38
+ break if count >= 3
39
+
40
+ puts "Count: #{count}"
41
+ end
42
+ # Output:
43
+ # Count: 1
44
+ # Count: 2
45
+ ```
46
+
47
+ ## Break with a Value
48
+
49
+ When used inside a block, `break` can return a value that becomes the result of the method call.
50
+
51
+ ```ruby
52
+ # Break with a return value in map
53
+ result = [1, 2, 3, 4, 5].map do |num|
54
+ break "Too large!" if num > 3
55
+
56
+ num * 2
57
+ end
58
+ puts result # Output: "Too large!"
59
+
60
+ # Break with a value in find
61
+ number = (1..10).find do |n|
62
+ break n if n > 5 && n.even?
63
+ end
64
+ puts number # Output: 6
65
+ ```
66
+
67
+ ## Break in Nested Loops
68
+
69
+ When using `break` in nested loops, it only exits the innermost loop. To break from nested loops, you typically need to use a flag or return.
70
+
71
+ ```ruby
72
+ # Break in nested iteration
73
+ (1..3).each do |i|
74
+ puts "Outer: #{i}"
75
+
76
+ (1..3).each do |j|
77
+ break if j == 2
78
+
79
+ puts " Inner: #{j}"
80
+ end
81
+ end
82
+ # Output:
83
+ # Outer: 1
84
+ # Inner: 1
85
+ # Outer: 2
86
+ # Inner: 1
87
+ # Outer: 3
88
+ # Inner: 1
89
+
90
+ # Breaking from nested loops with a flag
91
+ found = false
92
+ (1..3).each do |i|
93
+ (1..3).each do |j|
94
+ if i * j == 4
95
+ found = true
96
+ break
97
+ end
98
+ end
99
+ break if found
100
+ end
101
+ ```
102
+
103
+ The `break` keyword is essential for controlling loop execution and implementing early exit conditions. It's particularly useful when you've found what you're looking for and don't need to continue iterating.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.15
4
+ version: 0.26.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
@@ -52,7 +52,7 @@ dependencies:
52
52
  version: '3'
53
53
  - - "<"
54
54
  - !ruby/object:Gem::Version
55
- version: '4'
55
+ version: '5'
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
@@ -62,21 +62,7 @@ dependencies:
62
62
  version: '3'
63
63
  - - "<"
64
64
  - !ruby/object:Gem::Version
65
- version: '4'
66
- - !ruby/object:Gem::Dependency
67
- name: sorbet-runtime
68
- requirement: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 0.5.10782
73
- type: :runtime
74
- prerelease: false
75
- version_requirements: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: 0.5.10782
65
+ version: '5'
80
66
  description: An opinionated language server for Ruby
81
67
  email:
82
68
  - ruby@shopify.com
@@ -84,6 +70,7 @@ executables:
84
70
  - ruby-lsp
85
71
  - ruby-lsp-check
86
72
  - ruby-lsp-launcher
73
+ - ruby-lsp-test-exec
87
74
  extensions: []
88
75
  extra_rdoc_files: []
89
76
  files:
@@ -93,6 +80,7 @@ files:
93
80
  - exe/ruby-lsp
94
81
  - exe/ruby-lsp-check
95
82
  - exe/ruby-lsp-launcher
83
+ - exe/ruby-lsp-test-exec
96
84
  - lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb
97
85
  - lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb
98
86
  - lib/ruby-lsp.rb
@@ -108,20 +96,6 @@ files:
108
96
  - lib/ruby_indexer/lib/ruby_indexer/uri.rb
109
97
  - lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb
110
98
  - lib/ruby_indexer/ruby_indexer.rb
111
- - lib/ruby_indexer/test/class_variables_test.rb
112
- - lib/ruby_indexer/test/classes_and_modules_test.rb
113
- - lib/ruby_indexer/test/configuration_test.rb
114
- - lib/ruby_indexer/test/constant_test.rb
115
- - lib/ruby_indexer/test/enhancements_test.rb
116
- - lib/ruby_indexer/test/global_variable_test.rb
117
- - lib/ruby_indexer/test/index_test.rb
118
- - lib/ruby_indexer/test/instance_variables_test.rb
119
- - lib/ruby_indexer/test/method_test.rb
120
- - lib/ruby_indexer/test/prefix_tree_test.rb
121
- - lib/ruby_indexer/test/rbs_indexer_test.rb
122
- - lib/ruby_indexer/test/reference_finder_test.rb
123
- - lib/ruby_indexer/test/test_case.rb
124
- - lib/ruby_indexer/test/uri_test.rb
125
99
  - lib/ruby_lsp/addon.rb
126
100
  - lib/ruby_lsp/base_server.rb
127
101
  - lib/ruby_lsp/client_capabilities.rb
@@ -143,7 +117,6 @@ files:
143
117
  - lib/ruby_lsp/listeners/spec_style.rb
144
118
  - lib/ruby_lsp/listeners/test_discovery.rb
145
119
  - lib/ruby_lsp/listeners/test_style.rb
146
- - lib/ruby_lsp/load_sorbet.rb
147
120
  - lib/ruby_lsp/node_context.rb
148
121
  - lib/ruby_lsp/rbs_document.rb
149
122
  - lib/ruby_lsp/requests/code_action_resolve.rb
@@ -176,6 +149,7 @@ files:
176
149
  - lib/ruby_lsp/requests/support/annotation.rb
177
150
  - lib/ruby_lsp/requests/support/common.rb
178
151
  - lib/ruby_lsp/requests/support/formatter.rb
152
+ - lib/ruby_lsp/requests/support/package_url.rb
179
153
  - lib/ruby_lsp/requests/support/rubocop_diagnostic.rb
180
154
  - lib/ruby_lsp/requests/support/rubocop_formatter.rb
181
155
  - lib/ruby_lsp/requests/support/rubocop_runner.rb
@@ -207,6 +181,7 @@ files:
207
181
  - lib/ruby_lsp/test_reporters/test_unit_reporter.rb
208
182
  - lib/ruby_lsp/type_inferrer.rb
209
183
  - lib/ruby_lsp/utils.rb
184
+ - static_docs/break.md
210
185
  - static_docs/yield.md
211
186
  homepage: https://github.com/Shopify/ruby-lsp
212
187
  licenses:
@@ -228,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
203
  - !ruby/object:Gem::Version
229
204
  version: '0'
230
205
  requirements: []
231
- rubygems_version: 3.6.8
206
+ rubygems_version: 4.0.3
232
207
  specification_version: 4
233
208
  summary: An opinionated language server for Ruby
234
209
  test_files: []
@@ -1,140 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
- require_relative "test_case"
5
-
6
- module RubyIndexer
7
- class ClassVariableTest < TestCase
8
- def test_class_variable_and_write
9
- index(<<~RUBY)
10
- class Foo
11
- @@bar &&= 1
12
- end
13
- RUBY
14
-
15
- assert_entry("@@bar", Entry::ClassVariable, "/fake/path/foo.rb:1-2:1-7")
16
-
17
- entry = @index["@@bar"]&.first #: as Entry::ClassVariable
18
- owner = entry.owner #: as !nil
19
- assert_instance_of(Entry::Class, owner)
20
- assert_equal("Foo", owner.name)
21
- end
22
-
23
- def test_class_variable_operator_write
24
- index(<<~RUBY)
25
- class Foo
26
- @@bar += 1
27
- end
28
- RUBY
29
-
30
- assert_entry("@@bar", Entry::ClassVariable, "/fake/path/foo.rb:1-2:1-7")
31
- end
32
-
33
- def test_class_variable_or_write
34
- index(<<~RUBY)
35
- class Foo
36
- @@bar ||= 1
37
- end
38
- RUBY
39
-
40
- assert_entry("@@bar", Entry::ClassVariable, "/fake/path/foo.rb:1-2:1-7")
41
- end
42
-
43
- def test_class_variable_target_node
44
- index(<<~RUBY)
45
- class Foo
46
- @@foo, @@bar = 1
47
- end
48
- RUBY
49
-
50
- assert_entry("@@foo", Entry::ClassVariable, "/fake/path/foo.rb:1-2:1-7")
51
- assert_entry("@@bar", Entry::ClassVariable, "/fake/path/foo.rb:1-9:1-14")
52
-
53
- entry = @index["@@foo"]&.first #: as Entry::ClassVariable
54
- owner = entry.owner #: as !nil
55
- assert_instance_of(Entry::Class, owner)
56
- assert_equal("Foo", owner.name)
57
-
58
- entry = @index["@@bar"]&.first #: as Entry::ClassVariable
59
- owner = entry.owner #: as !nil
60
- assert_instance_of(Entry::Class, owner)
61
- assert_equal("Foo", owner.name)
62
- end
63
-
64
- def test_class_variable_write
65
- index(<<~RUBY)
66
- class Foo
67
- @@bar = 1
68
- end
69
- RUBY
70
-
71
- assert_entry("@@bar", Entry::ClassVariable, "/fake/path/foo.rb:1-2:1-7")
72
- end
73
-
74
- def test_empty_name_class_variable
75
- index(<<~RUBY)
76
- module Foo
77
- @@ = 1
78
- end
79
- RUBY
80
-
81
- refute_entry("@@")
82
- end
83
-
84
- def test_top_level_class_variable
85
- index(<<~RUBY)
86
- @@foo = 123
87
- RUBY
88
-
89
- entry = @index["@@foo"]&.first #: as Entry::ClassVariable
90
- assert_nil(entry.owner)
91
- end
92
-
93
- def test_class_variable_inside_self_method
94
- index(<<~RUBY)
95
- class Foo
96
- def self.bar
97
- @@bar = 123
98
- end
99
- end
100
- RUBY
101
-
102
- entry = @index["@@bar"]&.first #: as Entry::ClassVariable
103
- owner = entry.owner #: as !nil
104
- assert_instance_of(Entry::Class, owner)
105
- assert_equal("Foo", owner.name)
106
- end
107
-
108
- def test_class_variable_inside_singleton_class
109
- index(<<~RUBY)
110
- class Foo
111
- class << self
112
- @@bar = 123
113
- end
114
- end
115
- RUBY
116
-
117
- entry = @index["@@bar"]&.first #: as Entry::ClassVariable
118
- owner = entry.owner #: as !nil
119
- assert_instance_of(Entry::Class, owner)
120
- assert_equal("Foo", owner.name)
121
- end
122
-
123
- def test_class_variable_in_singleton_class_method
124
- index(<<~RUBY)
125
- class Foo
126
- class << self
127
- def self.bar
128
- @@bar = 123
129
- end
130
- end
131
- end
132
- RUBY
133
-
134
- entry = @index["@@bar"]&.first #: as Entry::ClassVariable
135
- owner = entry.owner #: as !nil
136
- assert_instance_of(Entry::Class, owner)
137
- assert_equal("Foo", owner.name)
138
- end
139
- end
140
- end