ruby-lsp 0.23.11 → 0.23.13

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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/VERSION +1 -1
  4. data/exe/ruby-lsp-launcher +12 -11
  5. data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
  6. data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
  7. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +81 -115
  8. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +117 -166
  9. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +9 -7
  10. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +88 -200
  11. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +56 -192
  12. data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
  13. data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +14 -16
  14. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +22 -45
  15. data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +42 -60
  16. data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +9 -16
  17. data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
  18. data/lib/ruby_indexer/test/configuration_test.rb +42 -3
  19. data/lib/ruby_indexer/test/method_test.rb +28 -2
  20. data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
  21. data/lib/ruby_lsp/addon.rb +44 -71
  22. data/lib/ruby_lsp/base_server.rb +29 -32
  23. data/lib/ruby_lsp/client_capabilities.rb +10 -12
  24. data/lib/ruby_lsp/document.rb +34 -45
  25. data/lib/ruby_lsp/erb_document.rb +24 -36
  26. data/lib/ruby_lsp/global_state.rb +51 -56
  27. data/lib/ruby_lsp/internal.rb +2 -0
  28. data/lib/ruby_lsp/listeners/code_lens.rb +81 -88
  29. data/lib/ruby_lsp/listeners/completion.rb +36 -55
  30. data/lib/ruby_lsp/listeners/definition.rb +37 -51
  31. data/lib/ruby_lsp/listeners/document_highlight.rb +123 -150
  32. data/lib/ruby_lsp/listeners/document_link.rb +43 -62
  33. data/lib/ruby_lsp/listeners/document_symbol.rb +35 -49
  34. data/lib/ruby_lsp/listeners/folding_ranges.rb +32 -39
  35. data/lib/ruby_lsp/listeners/hover.rb +81 -100
  36. data/lib/ruby_lsp/listeners/inlay_hints.rb +4 -11
  37. data/lib/ruby_lsp/listeners/semantic_highlighting.rb +42 -51
  38. data/lib/ruby_lsp/listeners/signature_help.rb +6 -25
  39. data/lib/ruby_lsp/listeners/spec_style.rb +155 -0
  40. data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
  41. data/lib/ruby_lsp/listeners/test_style.rb +160 -88
  42. data/lib/ruby_lsp/node_context.rb +12 -39
  43. data/lib/ruby_lsp/rbs_document.rb +8 -6
  44. data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
  45. data/lib/ruby_lsp/requests/code_actions.rb +14 -26
  46. data/lib/ruby_lsp/requests/code_lens.rb +6 -17
  47. data/lib/ruby_lsp/requests/completion.rb +7 -20
  48. data/lib/ruby_lsp/requests/completion_resolve.rb +5 -5
  49. data/lib/ruby_lsp/requests/definition.rb +8 -17
  50. data/lib/ruby_lsp/requests/diagnostics.rb +8 -11
  51. data/lib/ruby_lsp/requests/discover_tests.rb +18 -5
  52. data/lib/ruby_lsp/requests/document_highlight.rb +5 -15
  53. data/lib/ruby_lsp/requests/document_link.rb +6 -17
  54. data/lib/ruby_lsp/requests/document_symbol.rb +5 -8
  55. data/lib/ruby_lsp/requests/folding_ranges.rb +7 -15
  56. data/lib/ruby_lsp/requests/formatting.rb +6 -9
  57. data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
  58. data/lib/ruby_lsp/requests/hover.rb +8 -18
  59. data/lib/ruby_lsp/requests/inlay_hints.rb +6 -17
  60. data/lib/ruby_lsp/requests/on_type_formatting.rb +28 -38
  61. data/lib/ruby_lsp/requests/prepare_rename.rb +4 -9
  62. data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
  63. data/lib/ruby_lsp/requests/range_formatting.rb +5 -6
  64. data/lib/ruby_lsp/requests/references.rb +6 -36
  65. data/lib/ruby_lsp/requests/rename.rb +11 -37
  66. data/lib/ruby_lsp/requests/request.rb +7 -19
  67. data/lib/ruby_lsp/requests/selection_ranges.rb +5 -5
  68. data/lib/ruby_lsp/requests/semantic_highlighting.rb +12 -31
  69. data/lib/ruby_lsp/requests/show_syntax_tree.rb +5 -6
  70. data/lib/ruby_lsp/requests/signature_help.rb +8 -26
  71. data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
  72. data/lib/ruby_lsp/requests/support/common.rb +13 -50
  73. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +27 -35
  74. data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +9 -12
  75. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +22 -34
  76. data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
  77. data/lib/ruby_lsp/requests/support/sorbet.rb +29 -38
  78. data/lib/ruby_lsp/requests/support/source_uri.rb +16 -30
  79. data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +12 -19
  80. data/lib/ruby_lsp/requests/support/test_item.rb +10 -14
  81. data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +5 -6
  82. data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
  83. data/lib/ruby_lsp/response_builders/collection_response_builder.rb +5 -5
  84. data/lib/ruby_lsp/response_builders/document_symbol.rb +10 -16
  85. data/lib/ruby_lsp/response_builders/hover.rb +10 -13
  86. data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
  87. data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +59 -87
  88. data/lib/ruby_lsp/response_builders/signature_help.rb +5 -6
  89. data/lib/ruby_lsp/response_builders/test_collection.rb +6 -10
  90. data/lib/ruby_lsp/ruby_document.rb +22 -60
  91. data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +109 -0
  92. data/lib/ruby_lsp/scope.rb +7 -11
  93. data/lib/ruby_lsp/server.rb +133 -74
  94. data/lib/ruby_lsp/setup_bundler.rb +58 -57
  95. data/lib/ruby_lsp/static_docs.rb +4 -7
  96. data/lib/ruby_lsp/store.rb +21 -40
  97. data/lib/ruby_lsp/test_helper.rb +3 -12
  98. data/lib/ruby_lsp/test_reporter.rb +207 -0
  99. data/lib/ruby_lsp/test_unit_test_runner.rb +98 -0
  100. data/lib/ruby_lsp/type_inferrer.rb +9 -13
  101. data/lib/ruby_lsp/utils.rb +37 -81
  102. metadata +9 -3
@@ -21,47 +21,47 @@ module RubyLsp
21
21
  # This maximum number of characters for providing expensive features, like semantic highlighting and diagnostics.
22
22
  # This is the same number used by the TypeScript extension in VS Code
23
23
  MAXIMUM_CHARACTERS_FOR_EXPENSIVE_FEATURES = 100_000
24
- EMPTY_CACHE = T.let(Object.new.freeze, Object)
24
+ EMPTY_CACHE = Object.new.freeze #: Object
25
25
 
26
26
  abstract!
27
27
 
28
- sig { returns(ParseResultType) }
28
+ #: ParseResultType
29
29
  attr_reader :parse_result
30
30
 
31
- sig { returns(String) }
31
+ #: String
32
32
  attr_reader :source
33
33
 
34
- sig { returns(Integer) }
34
+ #: Integer
35
35
  attr_reader :version
36
36
 
37
- sig { returns(URI::Generic) }
37
+ #: URI::Generic
38
38
  attr_reader :uri
39
39
 
40
- sig { returns(Encoding) }
40
+ #: Encoding
41
41
  attr_reader :encoding
42
42
 
43
- sig { returns(T.nilable(Edit)) }
43
+ #: Edit?
44
44
  attr_reader :last_edit
45
45
 
46
- sig { returns(T.any(Interface::SemanticTokens, Object)) }
46
+ #: (Interface::SemanticTokens | Object)
47
47
  attr_accessor :semantic_tokens
48
48
 
49
- sig { params(source: String, version: Integer, uri: URI::Generic, global_state: GlobalState).void }
49
+ #: (source: String, version: Integer, uri: URI::Generic, global_state: GlobalState) -> void
50
50
  def initialize(source:, version:, uri:, global_state:)
51
51
  @source = source
52
52
  @version = version
53
53
  @global_state = global_state
54
- @cache = T.let(Hash.new(EMPTY_CACHE), T::Hash[String, T.untyped])
55
- @semantic_tokens = T.let(EMPTY_CACHE, T.any(Interface::SemanticTokens, Object))
56
- @encoding = T.let(global_state.encoding, Encoding)
57
- @uri = T.let(uri, URI::Generic)
58
- @needs_parsing = T.let(true, T::Boolean)
59
- @parse_result = T.let(T.unsafe(nil), ParseResultType)
60
- @last_edit = T.let(nil, T.nilable(Edit))
54
+ @cache = Hash.new(EMPTY_CACHE) #: Hash[String, untyped]
55
+ @semantic_tokens = EMPTY_CACHE #: (Interface::SemanticTokens | Object)
56
+ @encoding = global_state.encoding #: Encoding
57
+ @uri = uri #: URI::Generic
58
+ @needs_parsing = true #: bool
59
+ @parse_result = T.unsafe(nil) #: ParseResultType
60
+ @last_edit = nil #: Edit?
61
61
  parse!
62
62
  end
63
63
 
64
- sig { params(other: Document[T.untyped]).returns(T::Boolean) }
64
+ #: (Document[untyped] other) -> bool
65
65
  def ==(other)
66
66
  self.class == other.class && uri == other.uri && @source == other.source
67
67
  end
@@ -69,13 +69,7 @@ module RubyLsp
69
69
  sig { abstract.returns(LanguageId) }
70
70
  def language_id; end
71
71
 
72
- sig do
73
- type_parameters(:T)
74
- .params(
75
- request_name: String,
76
- block: T.proc.params(document: Document[ParseResultType]).returns(T.type_parameter(:T)),
77
- ).returns(T.type_parameter(:T))
78
- end
72
+ #: [T] (String request_name) { (Document[ParseResultType] document) -> T } -> T
79
73
  def cache_fetch(request_name, &block)
80
74
  cached = @cache[request_name]
81
75
  return cached if cached != EMPTY_CACHE
@@ -85,17 +79,17 @@ module RubyLsp
85
79
  result
86
80
  end
87
81
 
88
- sig { type_parameters(:T).params(request_name: String, value: T.type_parameter(:T)).returns(T.type_parameter(:T)) }
82
+ #: [T] (String request_name, T value) -> T
89
83
  def cache_set(request_name, value)
90
84
  @cache[request_name] = value
91
85
  end
92
86
 
93
- sig { params(request_name: String).returns(T.untyped) }
87
+ #: (String request_name) -> untyped
94
88
  def cache_get(request_name)
95
89
  @cache[request_name]
96
90
  end
97
91
 
98
- sig { params(edits: T::Array[T::Hash[Symbol, T.untyped]], version: Integer).void }
92
+ #: (Array[Hash[Symbol, untyped]] edits, version: Integer) -> void
99
93
  def push_edits(edits, version:)
100
94
  edits.each do |edit|
101
95
  range = edit[:range]
@@ -132,17 +126,12 @@ module RubyLsp
132
126
  sig { abstract.returns(T::Boolean) }
133
127
  def syntax_error?; end
134
128
 
135
- sig { returns(T::Boolean) }
129
+ #: -> bool
136
130
  def past_expensive_limit?
137
131
  @source.length > MAXIMUM_CHARACTERS_FOR_EXPENSIVE_FEATURES
138
132
  end
139
133
 
140
- sig do
141
- params(
142
- start_pos: T::Hash[Symbol, T.untyped],
143
- end_pos: T.nilable(T::Hash[Symbol, T.untyped]),
144
- ).returns([Integer, T.nilable(Integer)])
145
- end
134
+ #: (Hash[Symbol, untyped] start_pos, ?Hash[Symbol, untyped]? end_pos) -> [Integer, Integer?]
146
135
  def find_index_by_position(start_pos, end_pos = nil)
147
136
  @global_state.synchronize do
148
137
  scanner = create_scanner
@@ -154,7 +143,7 @@ module RubyLsp
154
143
 
155
144
  private
156
145
 
157
- sig { returns(Scanner) }
146
+ #: -> Scanner
158
147
  def create_scanner
159
148
  Scanner.new(@source, @encoding)
160
149
  end
@@ -165,10 +154,10 @@ module RubyLsp
165
154
 
166
155
  abstract!
167
156
 
168
- sig { returns(T::Hash[Symbol, T.untyped]) }
157
+ #: Hash[Symbol, untyped]
169
158
  attr_reader :range
170
159
 
171
- sig { params(range: T::Hash[Symbol, T.untyped]).void }
160
+ #: (Hash[Symbol, untyped] range) -> void
172
161
  def initialize(range)
173
162
  @range = range
174
163
  end
@@ -181,20 +170,20 @@ module RubyLsp
181
170
  class Scanner
182
171
  extend T::Sig
183
172
 
184
- LINE_BREAK = T.let(0x0A, Integer)
173
+ LINE_BREAK = 0x0A #: Integer
185
174
  # After character 0xFFFF, UTF-16 considers characters to have length 2 and we have to account for that
186
- SURROGATE_PAIR_START = T.let(0xFFFF, Integer)
175
+ SURROGATE_PAIR_START = 0xFFFF #: Integer
187
176
 
188
- sig { params(source: String, encoding: Encoding).void }
177
+ #: (String source, Encoding encoding) -> void
189
178
  def initialize(source, encoding)
190
- @current_line = T.let(0, Integer)
191
- @pos = T.let(0, Integer)
192
- @source = T.let(source.codepoints, T::Array[Integer])
179
+ @current_line = 0 #: Integer
180
+ @pos = 0 #: Integer
181
+ @source = source.codepoints #: Array[Integer]
193
182
  @encoding = encoding
194
183
  end
195
184
 
196
185
  # Finds the character index inside the source string for a given line and column
197
- sig { params(position: T::Hash[Symbol, T.untyped]).returns(Integer) }
186
+ #: (Hash[Symbol, untyped] position) -> Integer
198
187
  def find_char_position(position)
199
188
  # Find the character index for the beginning of the requested line
200
189
  until @current_line == position[:line]
@@ -224,7 +213,7 @@ module RubyLsp
224
213
 
225
214
  # Subtract 1 for each character after 0xFFFF in the current line from the column position, so that we hit the
226
215
  # right character in the UTF-8 representation
227
- sig { params(current_position: Integer, requested_position: Integer).returns(Integer) }
216
+ #: (Integer current_position, Integer requested_position) -> Integer
228
217
  def utf_16_character_position_correction(current_position, requested_position)
229
218
  utf16_unicode_correction = 0
230
219
 
@@ -3,35 +3,28 @@
3
3
 
4
4
  module RubyLsp
5
5
  class ERBDocument < Document
6
- extend T::Sig
7
6
  extend T::Generic
8
7
 
9
8
  ParseResultType = type_member { { fixed: Prism::ParseResult } }
10
9
 
11
- sig { returns(String) }
10
+ #: String
12
11
  attr_reader :host_language_source
13
12
 
14
- sig do
15
- returns(T.any(
16
- T.proc.params(arg0: Integer).returns(Integer),
17
- Prism::CodeUnitsCache,
18
- ))
19
- end
13
+ #: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
20
14
  attr_reader :code_units_cache
21
15
 
22
- sig { params(source: String, version: Integer, uri: URI::Generic, global_state: GlobalState).void }
16
+ #: (source: String, version: Integer, uri: URI::Generic, global_state: GlobalState) -> void
23
17
  def initialize(source:, version:, uri:, global_state:)
24
18
  # This has to be initialized before calling super because we call `parse` in the parent constructor, which
25
19
  # overrides this with the proper virtual host language source
26
- @host_language_source = T.let("", String)
20
+ @host_language_source = "" #: String
27
21
  super
28
- @code_units_cache = T.let(@parse_result.code_units_cache(@encoding), T.any(
29
- T.proc.params(arg0: Integer).returns(Integer),
30
- Prism::CodeUnitsCache,
31
- ))
22
+ @code_units_cache =
23
+ @parse_result.code_units_cache(@encoding) #: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
32
24
  end
33
25
 
34
- sig { override.returns(T::Boolean) }
26
+ # @override
27
+ #: -> bool
35
28
  def parse!
36
29
  return false unless @needs_parsing
37
30
 
@@ -46,22 +39,19 @@ module RubyLsp
46
39
  true
47
40
  end
48
41
 
49
- sig { override.returns(T::Boolean) }
42
+ # @override
43
+ #: -> bool
50
44
  def syntax_error?
51
45
  @parse_result.failure?
52
46
  end
53
47
 
54
- sig { override.returns(LanguageId) }
48
+ # @override
49
+ #: -> LanguageId
55
50
  def language_id
56
51
  LanguageId::ERB
57
52
  end
58
53
 
59
- sig do
60
- params(
61
- position: T::Hash[Symbol, T.untyped],
62
- node_types: T::Array[T.class_of(Prism::Node)],
63
- ).returns(NodeContext)
64
- end
54
+ #: (Hash[Symbol, untyped] position, ?node_types: Array[singleton(Prism::Node)]) -> NodeContext
65
55
  def locate_node(position, node_types: [])
66
56
  char_position, _ = find_index_by_position(position)
67
57
 
@@ -73,28 +63,26 @@ module RubyLsp
73
63
  )
74
64
  end
75
65
 
76
- sig { params(char_position: Integer).returns(T.nilable(T::Boolean)) }
66
+ #: (Integer char_position) -> bool?
77
67
  def inside_host_language?(char_position)
78
68
  char = @host_language_source[char_position]
79
69
  char && char != " "
80
70
  end
81
71
 
82
72
  class ERBScanner
83
- extend T::Sig
84
-
85
- sig { returns(String) }
73
+ #: String
86
74
  attr_reader :ruby, :host_language
87
75
 
88
- sig { params(source: String).void }
76
+ #: (String source) -> void
89
77
  def initialize(source)
90
78
  @source = source
91
- @host_language = T.let(+"", String)
92
- @ruby = T.let(+"", String)
93
- @current_pos = T.let(0, Integer)
94
- @inside_ruby = T.let(false, T::Boolean)
79
+ @host_language = +"" #: String
80
+ @ruby = +"" #: String
81
+ @current_pos = 0 #: Integer
82
+ @inside_ruby = false #: bool
95
83
  end
96
84
 
97
- sig { void }
85
+ #: -> void
98
86
  def scan
99
87
  while @current_pos < @source.length
100
88
  scan_char
@@ -104,7 +92,7 @@ module RubyLsp
104
92
 
105
93
  private
106
94
 
107
- sig { void }
95
+ #: -> void
108
96
  def scan_char
109
97
  char = @source[@current_pos]
110
98
 
@@ -159,7 +147,7 @@ module RubyLsp
159
147
  end
160
148
  end
161
149
 
162
- sig { params(char: String).void }
150
+ #: (String char) -> void
163
151
  def push_char(char)
164
152
  if @inside_ruby
165
153
  @ruby << char
@@ -170,7 +158,7 @@ module RubyLsp
170
158
  end
171
159
  end
172
160
 
173
- sig { returns(String) }
161
+ #: -> String
174
162
  def next_char
175
163
  @source[@current_pos + 1] || ""
176
164
  end
@@ -3,93 +3,88 @@
3
3
 
4
4
  module RubyLsp
5
5
  class GlobalState
6
- extend T::Sig
7
-
8
- sig { returns(String) }
6
+ #: String
9
7
  attr_reader :test_library
10
8
 
11
- sig { returns(String) }
9
+ #: String
12
10
  attr_accessor :formatter
13
11
 
14
- sig { returns(T::Boolean) }
12
+ #: bool
15
13
  attr_reader :has_type_checker
16
14
 
17
- sig { returns(RubyIndexer::Index) }
15
+ #: RubyIndexer::Index
18
16
  attr_reader :index
19
17
 
20
- sig { returns(Encoding) }
18
+ #: Encoding
21
19
  attr_reader :encoding
22
20
 
23
- sig { returns(T::Boolean) }
21
+ #: bool
24
22
  attr_reader :top_level_bundle
25
23
 
26
- sig { returns(TypeInferrer) }
24
+ #: TypeInferrer
27
25
  attr_reader :type_inferrer
28
26
 
29
- sig { returns(ClientCapabilities) }
27
+ #: ClientCapabilities
30
28
  attr_reader :client_capabilities
31
29
 
32
- sig { returns(URI::Generic) }
30
+ #: URI::Generic
33
31
  attr_reader :workspace_uri
34
32
 
35
- sig { returns(T.nilable(String)) }
33
+ #: String?
36
34
  attr_reader :telemetry_machine_id
37
35
 
38
- sig { void }
36
+ #: -> void
39
37
  def initialize
40
- @workspace_uri = T.let(URI::Generic.from_path(path: Dir.pwd), URI::Generic)
41
- @encoding = T.let(Encoding::UTF_8, Encoding)
42
-
43
- @formatter = T.let("auto", String)
44
- @linters = T.let([], T::Array[String])
45
- @test_library = T.let("minitest", String)
46
- @has_type_checker = T.let(true, T::Boolean)
47
- @index = T.let(RubyIndexer::Index.new, RubyIndexer::Index)
48
- @supported_formatters = T.let({}, T::Hash[String, Requests::Support::Formatter])
49
- @type_inferrer = T.let(TypeInferrer.new(@index), TypeInferrer)
50
- @addon_settings = T.let({}, T::Hash[String, T.untyped])
51
- @top_level_bundle = T.let(
52
- begin
53
- Bundler.with_original_env { Bundler.default_gemfile }
54
- true
55
- rescue Bundler::GemfileNotFound, Bundler::GitError
56
- false
57
- end,
58
- T::Boolean,
59
- )
60
- @client_capabilities = T.let(ClientCapabilities.new, ClientCapabilities)
61
- @enabled_feature_flags = T.let({}, T::Hash[Symbol, T::Boolean])
62
- @mutex = T.let(Mutex.new, Mutex)
63
- @telemetry_machine_id = T.let(nil, T.nilable(String))
38
+ @workspace_uri = URI::Generic.from_path(path: Dir.pwd) #: URI::Generic
39
+ @encoding = Encoding::UTF_8 #: Encoding
40
+
41
+ @formatter = "auto" #: String
42
+ @linters = [] #: Array[String]
43
+ @test_library = "minitest" #: String
44
+ @has_type_checker = true #: bool
45
+ @index = RubyIndexer::Index.new #: RubyIndexer::Index
46
+ @supported_formatters = {} #: Hash[String, Requests::Support::Formatter]
47
+ @type_inferrer = TypeInferrer.new(@index) #: TypeInferrer
48
+ @addon_settings = {} #: Hash[String, untyped]
49
+ @top_level_bundle = begin
50
+ Bundler.with_original_env { Bundler.default_gemfile }
51
+ true
52
+ rescue Bundler::GemfileNotFound, Bundler::GitError
53
+ false
54
+ end #: bool
55
+ @client_capabilities = ClientCapabilities.new #: ClientCapabilities
56
+ @enabled_feature_flags = {} #: Hash[Symbol, bool]
57
+ @mutex = Mutex.new #: Mutex
58
+ @telemetry_machine_id = nil #: String?
64
59
  end
65
60
 
66
- sig { type_parameters(:T).params(block: T.proc.returns(T.type_parameter(:T))).returns(T.type_parameter(:T)) }
61
+ #: [T] { -> T } -> T
67
62
  def synchronize(&block)
68
63
  @mutex.synchronize(&block)
69
64
  end
70
65
 
71
- sig { params(addon_name: String).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
66
+ #: (String addon_name) -> Hash[Symbol, untyped]?
72
67
  def settings_for_addon(addon_name)
73
68
  @addon_settings[addon_name]
74
69
  end
75
70
 
76
- sig { params(identifier: String, instance: Requests::Support::Formatter).void }
71
+ #: (String identifier, Requests::Support::Formatter instance) -> void
77
72
  def register_formatter(identifier, instance)
78
73
  @supported_formatters[identifier] = instance
79
74
  end
80
75
 
81
- sig { returns(T.nilable(Requests::Support::Formatter)) }
76
+ #: -> Requests::Support::Formatter?
82
77
  def active_formatter
83
78
  @supported_formatters[@formatter]
84
79
  end
85
80
 
86
- sig { returns(T::Array[Requests::Support::Formatter]) }
81
+ #: -> Array[Requests::Support::Formatter]
87
82
  def active_linters
88
83
  @linters.filter_map { |name| @supported_formatters[name] }
89
84
  end
90
85
 
91
86
  # Applies the options provided by the editor and returns an array of notifications to send back to the client
92
- sig { params(options: T::Hash[Symbol, T.untyped]).returns(T::Array[Notification]) }
87
+ #: (Hash[Symbol, untyped] options) -> Array[Notification]
93
88
  def apply_options(options)
94
89
  notifications = []
95
90
  direct_dependencies = gather_direct_dependencies
@@ -183,17 +178,17 @@ module RubyLsp
183
178
  notifications
184
179
  end
185
180
 
186
- sig { params(flag: Symbol).returns(T.nilable(T::Boolean)) }
181
+ #: (Symbol flag) -> bool?
187
182
  def enabled_feature?(flag)
188
183
  @enabled_feature_flags[:all] || @enabled_feature_flags[flag]
189
184
  end
190
185
 
191
- sig { returns(String) }
186
+ #: -> String
192
187
  def workspace_path
193
188
  T.must(@workspace_uri.to_standardized_path)
194
189
  end
195
190
 
196
- sig { returns(String) }
191
+ #: -> String
197
192
  def encoding_name
198
193
  case @encoding
199
194
  when Encoding::UTF_8
@@ -205,14 +200,14 @@ module RubyLsp
205
200
  end
206
201
  end
207
202
 
208
- sig { returns(T::Boolean) }
203
+ #: -> bool
209
204
  def supports_watching_files
210
205
  @client_capabilities.supports_watching_files
211
206
  end
212
207
 
213
208
  private
214
209
 
215
- sig { params(direct_dependencies: T::Array[String], all_dependencies: T::Array[String]).returns(String) }
210
+ #: (Array[String] direct_dependencies, Array[String] all_dependencies) -> String
216
211
  def detect_formatter(direct_dependencies, all_dependencies)
217
212
  # NOTE: Intentionally no $ at end, since we want to match rubocop-shopify, etc.
218
213
  return "rubocop_internal" if direct_dependencies.any?(/^rubocop/)
@@ -228,7 +223,7 @@ module RubyLsp
228
223
 
229
224
  # Try to detect if there are linters in the project's dependencies. For auto-detection, we always only consider a
230
225
  # single linter. To have multiple linters running, the user must configure them manually
231
- sig { params(dependencies: T::Array[String], all_dependencies: T::Array[String]).returns(T::Array[String]) }
226
+ #: (Array[String] dependencies, Array[String] all_dependencies) -> Array[String]
232
227
  def detect_linters(dependencies, all_dependencies)
233
228
  linters = []
234
229
 
@@ -239,7 +234,7 @@ module RubyLsp
239
234
  linters
240
235
  end
241
236
 
242
- sig { params(dependencies: T::Array[String]).returns(String) }
237
+ #: (Array[String] dependencies) -> String
243
238
  def detect_test_library(dependencies)
244
239
  if dependencies.any?(/^rspec/)
245
240
  "rspec"
@@ -259,7 +254,7 @@ module RubyLsp
259
254
  end
260
255
  end
261
256
 
262
- sig { params(dependencies: T::Array[String]).returns(T::Boolean) }
257
+ #: (Array[String] dependencies) -> bool
263
258
  def detect_typechecker(dependencies)
264
259
  return false if ENV["RUBY_LSP_BYPASS_TYPECHECKER"]
265
260
 
@@ -268,17 +263,17 @@ module RubyLsp
268
263
  false
269
264
  end
270
265
 
271
- sig { returns(T::Boolean) }
266
+ #: -> bool
272
267
  def bin_rails_present
273
268
  File.exist?(File.join(workspace_path, "bin/rails"))
274
269
  end
275
270
 
276
- sig { returns(T::Boolean) }
271
+ #: -> bool
277
272
  def dot_rubocop_yml_present
278
273
  File.exist?(File.join(workspace_path, ".rubocop.yml"))
279
274
  end
280
275
 
281
- sig { returns(T::Array[String]) }
276
+ #: -> Array[String]
282
277
  def gather_direct_dependencies
283
278
  Bundler.with_original_env { Bundler.default_gemfile }
284
279
 
@@ -288,14 +283,14 @@ module RubyLsp
288
283
  []
289
284
  end
290
285
 
291
- sig { returns(T::Array[String]) }
286
+ #: -> Array[String]
292
287
  def gemspec_dependencies
293
288
  (Bundler.locked_gems&.sources || [])
294
289
  .grep(Bundler::Source::Gemspec)
295
290
  .flat_map { _1.gemspec&.dependencies&.map(&:name) }
296
291
  end
297
292
 
298
- sig { returns(T::Array[String]) }
293
+ #: -> Array[String]
299
294
  def gather_direct_and_indirect_dependencies
300
295
  Bundler.with_original_env { Bundler.default_gemfile }
301
296
  Bundler.locked_gems&.specs&.map(&:name) || []
@@ -25,6 +25,7 @@ require "fileutils"
25
25
  require "open3"
26
26
  require "securerandom"
27
27
  require "shellwords"
28
+ require "set"
28
29
 
29
30
  require "ruby-lsp"
30
31
  require "ruby_lsp/base_server"
@@ -79,6 +80,7 @@ require "ruby_lsp/requests/document_link"
79
80
  require "ruby_lsp/requests/document_symbol"
80
81
  require "ruby_lsp/requests/folding_ranges"
81
82
  require "ruby_lsp/requests/formatting"
83
+ require "ruby_lsp/requests/go_to_relevant_file"
82
84
  require "ruby_lsp/requests/hover"
83
85
  require "ruby_lsp/requests/inlay_hints"
84
86
  require "ruby_lsp/requests/on_type_formatting"