ruby-lsp 0.24.1 → 0.25.0
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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/exe/ruby-lsp +10 -4
- data/exe/ruby-lsp-check +0 -4
- data/exe/ruby-lsp-launcher +18 -9
- data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +0 -1
- data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +0 -1
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +3 -1
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +2 -2
- data/lib/ruby_indexer/test/configuration_test.rb +1 -1
- data/lib/ruby_indexer/test/rbs_indexer_test.rb +2 -2
- data/lib/ruby_lsp/addon.rb +20 -6
- data/lib/ruby_lsp/base_server.rb +9 -5
- data/lib/ruby_lsp/document.rb +151 -50
- data/lib/ruby_lsp/global_state.rb +21 -0
- data/lib/ruby_lsp/internal.rb +0 -2
- data/lib/ruby_lsp/listeners/hover.rb +7 -0
- data/lib/ruby_lsp/listeners/inlay_hints.rb +5 -3
- data/lib/ruby_lsp/requests/code_action_resolve.rb +1 -1
- data/lib/ruby_lsp/requests/code_lens.rb +9 -3
- data/lib/ruby_lsp/requests/inlay_hints.rb +3 -3
- data/lib/ruby_lsp/requests/on_type_formatting.rb +1 -1
- data/lib/ruby_lsp/requests/references.rb +1 -1
- data/lib/ruby_lsp/requests/request.rb +3 -1
- data/lib/ruby_lsp/requests/support/formatter.rb +9 -3
- data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +2 -2
- data/lib/ruby_lsp/requests/support/rubocop_runner.rb +9 -3
- data/lib/ruby_lsp/response_builders/response_builder.rb +3 -3
- data/lib/ruby_lsp/ruby_document.rb +1 -1
- data/lib/ruby_lsp/server.rb +43 -21
- data/lib/ruby_lsp/setup_bundler.rb +48 -22
- data/lib/ruby_lsp/static_docs.rb +1 -0
- data/lib/ruby_lsp/store.rb +0 -10
- data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +13 -5
- data/lib/ruby_lsp/test_reporters/minitest_reporter.rb +17 -4
- data/lib/ruby_lsp/utils.rb +44 -5
- data/static_docs/break.md +103 -0
- metadata +2 -16
- data/lib/ruby_lsp/load_sorbet.rb +0 -62
@@ -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.
|
4
|
+
version: 0.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
@@ -63,20 +63,6 @@ dependencies:
|
|
63
63
|
- - "<"
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '5'
|
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
|
80
66
|
description: An opinionated language server for Ruby
|
81
67
|
email:
|
82
68
|
- ruby@shopify.com
|
@@ -145,7 +131,6 @@ files:
|
|
145
131
|
- lib/ruby_lsp/listeners/spec_style.rb
|
146
132
|
- lib/ruby_lsp/listeners/test_discovery.rb
|
147
133
|
- lib/ruby_lsp/listeners/test_style.rb
|
148
|
-
- lib/ruby_lsp/load_sorbet.rb
|
149
134
|
- lib/ruby_lsp/node_context.rb
|
150
135
|
- lib/ruby_lsp/rbs_document.rb
|
151
136
|
- lib/ruby_lsp/requests/code_action_resolve.rb
|
@@ -209,6 +194,7 @@ files:
|
|
209
194
|
- lib/ruby_lsp/test_reporters/test_unit_reporter.rb
|
210
195
|
- lib/ruby_lsp/type_inferrer.rb
|
211
196
|
- lib/ruby_lsp/utils.rb
|
197
|
+
- static_docs/break.md
|
212
198
|
- static_docs/yield.md
|
213
199
|
homepage: https://github.com/Shopify/ruby-lsp
|
214
200
|
licenses:
|
data/lib/ruby_lsp/load_sorbet.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require "sorbet-runtime"
|
5
|
-
|
6
|
-
begin
|
7
|
-
T::Configuration.default_checked_level = :never
|
8
|
-
# Suppresses call validation errors
|
9
|
-
T::Configuration.call_validation_error_handler = ->(*arg) {}
|
10
|
-
# Suppresses errors caused by T.cast, T.let, T.must, etc.
|
11
|
-
T::Configuration.inline_type_error_handler = ->(*arg) {}
|
12
|
-
# Suppresses errors caused by incorrect parameter ordering
|
13
|
-
T::Configuration.sig_validation_error_handler = ->(*arg) {}
|
14
|
-
rescue
|
15
|
-
# Need this rescue so that if another gem has
|
16
|
-
# already set the checked level by the time we
|
17
|
-
# get to it, we don't fail outright.
|
18
|
-
nil
|
19
|
-
end
|
20
|
-
|
21
|
-
module RubyLsp
|
22
|
-
# No-op all inline type assertions defined in T
|
23
|
-
module InlineTypeAssertions
|
24
|
-
def absurd(value)
|
25
|
-
value
|
26
|
-
end
|
27
|
-
|
28
|
-
def any(type_a, type_b, *types)
|
29
|
-
T::Types::Union.new([type_a, type_b, *types])
|
30
|
-
end
|
31
|
-
|
32
|
-
def assert_type!(value, type, checked: true)
|
33
|
-
value
|
34
|
-
end
|
35
|
-
|
36
|
-
def bind(value, type, checked: true)
|
37
|
-
value
|
38
|
-
end
|
39
|
-
|
40
|
-
def cast(value, type, checked: true)
|
41
|
-
value
|
42
|
-
end
|
43
|
-
|
44
|
-
def let(value, type, checked: true)
|
45
|
-
value
|
46
|
-
end
|
47
|
-
|
48
|
-
def must(arg)
|
49
|
-
arg
|
50
|
-
end
|
51
|
-
|
52
|
-
def nilable(type)
|
53
|
-
T::Types::Union.new([type, T::Utils::Nilable::NIL_TYPE])
|
54
|
-
end
|
55
|
-
|
56
|
-
def unsafe(value)
|
57
|
-
value
|
58
|
-
end
|
59
|
-
|
60
|
-
T.singleton_class.prepend(self)
|
61
|
-
end
|
62
|
-
end
|