ruby-lsp 0.23.12 → 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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb +1 -1
  4. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +31 -40
  5. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +56 -22
  6. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +1 -1
  7. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +15 -18
  8. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +8 -11
  9. data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +2 -2
  10. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +1 -1
  11. data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +2 -2
  12. data/lib/ruby_indexer/test/configuration_test.rb +10 -1
  13. data/lib/ruby_indexer/test/method_test.rb +26 -0
  14. data/lib/ruby_indexer/test/rbs_indexer_test.rb +1 -1
  15. data/lib/ruby_lsp/addon.rb +12 -4
  16. data/lib/ruby_lsp/base_server.rb +19 -22
  17. data/lib/ruby_lsp/client_capabilities.rb +6 -6
  18. data/lib/ruby_lsp/document.rb +13 -13
  19. data/lib/ruby_lsp/erb_document.rb +7 -9
  20. data/lib/ruby_lsp/global_state.rb +21 -24
  21. data/lib/ruby_lsp/listeners/code_lens.rb +59 -48
  22. data/lib/ruby_lsp/listeners/completion.rb +2 -2
  23. data/lib/ruby_lsp/listeners/definition.rb +2 -2
  24. data/lib/ruby_lsp/listeners/document_highlight.rb +62 -80
  25. data/lib/ruby_lsp/listeners/document_link.rb +34 -43
  26. data/lib/ruby_lsp/listeners/document_symbol.rb +1 -1
  27. data/lib/ruby_lsp/listeners/folding_ranges.rb +1 -1
  28. data/lib/ruby_lsp/listeners/hover.rb +43 -52
  29. data/lib/ruby_lsp/listeners/inlay_hints.rb +1 -1
  30. data/lib/ruby_lsp/listeners/semantic_highlighting.rb +11 -14
  31. data/lib/ruby_lsp/listeners/signature_help.rb +2 -2
  32. data/lib/ruby_lsp/listeners/spec_style.rb +15 -59
  33. data/lib/ruby_lsp/listeners/test_discovery.rb +89 -0
  34. data/lib/ruby_lsp/listeners/test_style.rb +47 -81
  35. data/lib/ruby_lsp/node_context.rb +4 -4
  36. data/lib/ruby_lsp/rbs_document.rb +1 -1
  37. data/lib/ruby_lsp/requests/code_actions.rb +9 -12
  38. data/lib/ruby_lsp/requests/code_lens.rb +2 -4
  39. data/lib/ruby_lsp/requests/completion.rb +3 -5
  40. data/lib/ruby_lsp/requests/completion_resolve.rb +1 -1
  41. data/lib/ruby_lsp/requests/definition.rb +4 -5
  42. data/lib/ruby_lsp/requests/diagnostics.rb +2 -2
  43. data/lib/ruby_lsp/requests/discover_tests.rb +3 -2
  44. data/lib/ruby_lsp/requests/document_highlight.rb +2 -4
  45. data/lib/ruby_lsp/requests/document_link.rb +2 -4
  46. data/lib/ruby_lsp/requests/document_symbol.rb +1 -1
  47. data/lib/ruby_lsp/requests/folding_ranges.rb +3 -8
  48. data/lib/ruby_lsp/requests/formatting.rb +2 -2
  49. data/lib/ruby_lsp/requests/go_to_relevant_file.rb +3 -3
  50. data/lib/ruby_lsp/requests/hover.rb +2 -2
  51. data/lib/ruby_lsp/requests/inlay_hints.rb +2 -4
  52. data/lib/ruby_lsp/requests/on_type_formatting.rb +10 -13
  53. data/lib/ruby_lsp/requests/prepare_rename.rb +1 -1
  54. data/lib/ruby_lsp/requests/range_formatting.rb +2 -2
  55. data/lib/ruby_lsp/requests/references.rb +1 -1
  56. data/lib/ruby_lsp/requests/rename.rb +2 -2
  57. data/lib/ruby_lsp/requests/request.rb +2 -2
  58. data/lib/ruby_lsp/requests/selection_ranges.rb +2 -2
  59. data/lib/ruby_lsp/requests/semantic_highlighting.rb +5 -7
  60. data/lib/ruby_lsp/requests/show_syntax_tree.rb +1 -1
  61. data/lib/ruby_lsp/requests/signature_help.rb +2 -2
  62. data/lib/ruby_lsp/requests/support/common.rb +1 -1
  63. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +15 -21
  64. data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +2 -2
  65. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +12 -18
  66. data/lib/ruby_lsp/requests/support/sorbet.rb +28 -31
  67. data/lib/ruby_lsp/requests/support/source_uri.rb +11 -14
  68. data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +5 -9
  69. data/lib/ruby_lsp/requests/support/test_item.rb +4 -9
  70. data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +1 -1
  71. data/lib/ruby_lsp/requests/workspace_symbol.rb +1 -1
  72. data/lib/ruby_lsp/response_builders/collection_response_builder.rb +1 -1
  73. data/lib/ruby_lsp/response_builders/document_symbol.rb +2 -5
  74. data/lib/ruby_lsp/response_builders/hover.rb +5 -8
  75. data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +41 -47
  76. data/lib/ruby_lsp/response_builders/signature_help.rb +1 -1
  77. data/lib/ruby_lsp/response_builders/test_collection.rb +1 -1
  78. data/lib/ruby_lsp/ruby_document.rb +7 -20
  79. data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +7 -4
  80. data/lib/ruby_lsp/scope.rb +1 -1
  81. data/lib/ruby_lsp/server.rb +9 -1
  82. data/lib/ruby_lsp/setup_bundler.rb +36 -42
  83. data/lib/ruby_lsp/static_docs.rb +4 -7
  84. data/lib/ruby_lsp/store.rb +9 -12
  85. data/lib/ruby_lsp/test_reporter.rb +140 -4
  86. data/lib/ruby_lsp/test_unit_test_runner.rb +10 -8
  87. data/lib/ruby_lsp/utils.rb +10 -16
  88. metadata +3 -2
@@ -21,7 +21,7 @@ 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
 
@@ -51,13 +51,13 @@ module RubyLsp
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
 
@@ -170,15 +170,15 @@ module RubyLsp
170
170
  class Scanner
171
171
  extend T::Sig
172
172
 
173
- LINE_BREAK = T.let(0x0A, Integer)
173
+ LINE_BREAK = 0x0A #: Integer
174
174
  # After character 0xFFFF, UTF-16 considers characters to have length 2 and we have to account for that
175
- SURROGATE_PAIR_START = T.let(0xFFFF, Integer)
175
+ SURROGATE_PAIR_START = 0xFFFF #: Integer
176
176
 
177
177
  #: (String source, Encoding encoding) -> void
178
178
  def initialize(source, encoding)
179
- @current_line = T.let(0, Integer)
180
- @pos = T.let(0, Integer)
181
- @source = T.let(source.codepoints, T::Array[Integer])
179
+ @current_line = 0 #: Integer
180
+ @pos = 0 #: Integer
181
+ @source = source.codepoints #: Array[Integer]
182
182
  @encoding = encoding
183
183
  end
184
184
 
@@ -17,12 +17,10 @@ module RubyLsp
17
17
  def initialize(source:, version:, uri:, global_state:)
18
18
  # This has to be initialized before calling super because we call `parse` in the parent constructor, which
19
19
  # overrides this with the proper virtual host language source
20
- @host_language_source = T.let("", String)
20
+ @host_language_source = "" #: String
21
21
  super
22
- @code_units_cache = T.let(@parse_result.code_units_cache(@encoding), T.any(
23
- T.proc.params(arg0: Integer).returns(Integer),
24
- Prism::CodeUnitsCache,
25
- ))
22
+ @code_units_cache =
23
+ @parse_result.code_units_cache(@encoding) #: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
26
24
  end
27
25
 
28
26
  # @override
@@ -78,10 +76,10 @@ module RubyLsp
78
76
  #: (String source) -> void
79
77
  def initialize(source)
80
78
  @source = source
81
- @host_language = T.let(+"", String)
82
- @ruby = T.let(+"", String)
83
- @current_pos = T.let(0, Integer)
84
- @inside_ruby = T.let(false, T::Boolean)
79
+ @host_language = +"" #: String
80
+ @ruby = +"" #: String
81
+ @current_pos = 0 #: Integer
82
+ @inside_ruby = false #: bool
85
83
  end
86
84
 
87
85
  #: -> void
@@ -35,30 +35,27 @@ module RubyLsp
35
35
 
36
36
  #: -> void
37
37
  def initialize
38
- @workspace_uri = T.let(URI::Generic.from_path(path: Dir.pwd), URI::Generic)
39
- @encoding = T.let(Encoding::UTF_8, Encoding)
40
-
41
- @formatter = T.let("auto", String)
42
- @linters = T.let([], T::Array[String])
43
- @test_library = T.let("minitest", String)
44
- @has_type_checker = T.let(true, T::Boolean)
45
- @index = T.let(RubyIndexer::Index.new, RubyIndexer::Index)
46
- @supported_formatters = T.let({}, T::Hash[String, Requests::Support::Formatter])
47
- @type_inferrer = T.let(TypeInferrer.new(@index), TypeInferrer)
48
- @addon_settings = T.let({}, T::Hash[String, T.untyped])
49
- @top_level_bundle = T.let(
50
- begin
51
- Bundler.with_original_env { Bundler.default_gemfile }
52
- true
53
- rescue Bundler::GemfileNotFound, Bundler::GitError
54
- false
55
- end,
56
- T::Boolean,
57
- )
58
- @client_capabilities = T.let(ClientCapabilities.new, ClientCapabilities)
59
- @enabled_feature_flags = T.let({}, T::Hash[Symbol, T::Boolean])
60
- @mutex = T.let(Mutex.new, Mutex)
61
- @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?
62
59
  end
63
60
 
64
61
  #: [T] { -> T } -> T
@@ -8,33 +8,30 @@ module RubyLsp
8
8
  class CodeLens
9
9
  include Requests::Support::Common
10
10
 
11
- BASE_COMMAND = T.let(
12
- begin
13
- Bundler.with_original_env { Bundler.default_lockfile }
14
- "bundle exec ruby"
15
- rescue Bundler::GemfileNotFound
16
- "ruby"
17
- end,
18
- String,
19
- )
20
- ACCESS_MODIFIERS = T.let([:public, :private, :protected], T::Array[Symbol])
21
- SUPPORTED_TEST_LIBRARIES = T.let(["minitest", "test-unit"], T::Array[String])
22
- DYNAMIC_REFERENCE_MARKER = T.let("<dynamic_reference>", String)
11
+ BASE_COMMAND = begin
12
+ Bundler.with_original_env { Bundler.default_lockfile }
13
+ "bundle exec ruby"
14
+ rescue Bundler::GemfileNotFound
15
+ "ruby"
16
+ end #: String
17
+ ACCESS_MODIFIERS = [:public, :private, :protected] #: Array[Symbol]
18
+ SUPPORTED_TEST_LIBRARIES = ["minitest", "test-unit"] #: Array[String]
19
+ DYNAMIC_REFERENCE_MARKER = "<dynamic_reference>" #: String
23
20
 
24
21
  #: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, GlobalState global_state, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
25
22
  def initialize(response_builder, global_state, uri, dispatcher)
26
23
  @response_builder = response_builder
27
24
  @global_state = global_state
28
- @uri = T.let(uri, URI::Generic)
29
- @path = T.let(uri.to_standardized_path, T.nilable(String))
25
+ @uri = uri #: URI::Generic
26
+ @path = uri.to_standardized_path #: String?
30
27
  # visibility_stack is a stack of [current_visibility, previous_visibility]
31
- @visibility_stack = T.let([[:public, :public]], T::Array[T::Array[T.nilable(Symbol)]])
32
- @group_stack = T.let([], T::Array[String])
33
- @group_id = T.let(1, Integer)
34
- @group_id_stack = T.let([], T::Array[Integer])
28
+ @visibility_stack = [[:public, :public]] #: Array[Array[Symbol?]]
29
+ @group_stack = [] #: Array[String]
30
+ @group_id = 1 #: Integer
31
+ @group_id_stack = [] #: Array[Integer]
35
32
  # We want to avoid adding code lenses for nested definitions
36
- @def_depth = T.let(0, Integer)
37
- @spec_id = T.let(0, Integer)
33
+ @def_depth = 0 #: Integer
34
+ @spec_id = 0 #: Integer
38
35
 
39
36
  dispatcher.register(
40
37
  self,
@@ -219,38 +216,52 @@ module RubyLsp
219
216
 
220
217
  case @global_state.test_library
221
218
  when "minitest"
222
- last_dynamic_reference_index = group_stack.rindex(DYNAMIC_REFERENCE_MARKER)
223
- command += if last_dynamic_reference_index
224
- # In cases where the test path looks like `foo::Bar`
225
- # the best we can do is match everything to the right of it.
226
- # Tests are classes, dynamic references are only a thing for modules,
227
- # so there must be something to the left of the available path.
228
- group_stack = T.must(group_stack[last_dynamic_reference_index + 1..])
229
- if method_name
230
- " --name " + "/::#{Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)}$/"
231
- else
232
- # When clicking on a CodeLens for `Test`, `(#|::)` will match all tests
233
- # that are registered on the class itself (matches after `#`) and all tests
234
- # that are nested inside of that class in other modules/classes (matches after `::`)
235
- " --name " + "\"/::#{Shellwords.escape(group_stack.join("::"))}(#|::)/\""
236
- end
237
- elsif method_name
238
- # We know the entire path, do an exact match
239
- " --name " + Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)
240
- elsif spec_name
241
- " --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}##{Shellwords.escape(spec_name)}$/\""
242
- else
243
- # Execute all tests of the selected class and tests in
244
- # modules/classes nested inside of that class
245
- " --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}(#|::)/\""
246
- end
219
+ command += generate_minitest_command(group_stack, method_name, spec_name)
247
220
  when "test-unit"
248
- group_name = T.must(group_stack.last)
249
- command += " --testcase " + "/#{Shellwords.escape(group_name)}/"
221
+ command += generate_test_unit_command(group_stack, method_name)
222
+ end
223
+
224
+ command
225
+ end
226
+
227
+ #: (Array[String] group_stack, String? method_name, String? spec_name) -> String
228
+ def generate_minitest_command(group_stack, method_name, spec_name)
229
+ last_dynamic_reference_index = group_stack.rindex(DYNAMIC_REFERENCE_MARKER)
230
+
231
+ if last_dynamic_reference_index
232
+ # In cases where the test path looks like `foo::Bar`
233
+ # the best we can do is match everything to the right of it.
234
+ # Tests are classes, dynamic references are only a thing for modules,
235
+ # so there must be something to the left of the available path.
236
+ dynamic_stack = T.must(group_stack[last_dynamic_reference_index + 1..])
250
237
 
251
238
  if method_name
252
- command += " --name " + Shellwords.escape(method_name)
239
+ " --name " + "/::#{Shellwords.escape(dynamic_stack.join("::")) + "#" + Shellwords.escape(method_name)}$/"
240
+ else
241
+ # When clicking on a CodeLens for `Test`, `(#|::)` will match all tests
242
+ # that are registered on the class itself (matches after `#`) and all tests
243
+ # that are nested inside of that class in other modules/classes (matches after `::`)
244
+ " --name " + "\"/::#{Shellwords.escape(dynamic_stack.join("::"))}(#|::)/\""
253
245
  end
246
+ elsif method_name
247
+ # We know the entire path, do an exact match
248
+ " --name " + Shellwords.escape(group_stack.join("::")) + "#" + Shellwords.escape(method_name)
249
+ elsif spec_name
250
+ " --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}##{Shellwords.escape(spec_name)}$/\""
251
+ else
252
+ # Execute all tests of the selected class and tests in
253
+ # modules/classes nested inside of that class
254
+ " --name " + "\"/^#{Shellwords.escape(group_stack.join("::"))}(#|::)/\""
255
+ end
256
+ end
257
+
258
+ #: (Array[String] group_stack, String? method_name) -> String
259
+ def generate_test_unit_command(group_stack, method_name)
260
+ group_name = T.must(group_stack.last)
261
+ command = " --testcase " + "/#{Shellwords.escape(group_name)}/"
262
+
263
+ if method_name
264
+ command += " --name " + Shellwords.escape(method_name)
254
265
  end
255
266
 
256
267
  command
@@ -62,8 +62,8 @@ module RubyLsp
62
62
  )
63
63
  @response_builder = response_builder
64
64
  @global_state = global_state
65
- @index = T.let(global_state.index, RubyIndexer::Index)
66
- @type_inferrer = T.let(global_state.type_inferrer, TypeInferrer)
65
+ @index = global_state.index #: RubyIndexer::Index
66
+ @type_inferrer = global_state.type_inferrer #: TypeInferrer
67
67
  @node_context = node_context
68
68
  @sorbet_level = sorbet_level
69
69
  @uri = uri
@@ -12,8 +12,8 @@ module RubyLsp
12
12
  def initialize(response_builder, global_state, language_id, uri, node_context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
13
13
  @response_builder = response_builder
14
14
  @global_state = global_state
15
- @index = T.let(global_state.index, RubyIndexer::Index)
16
- @type_inferrer = T.let(global_state.type_inferrer, TypeInferrer)
15
+ @index = global_state.index #: RubyIndexer::Index
16
+ @type_inferrer = global_state.type_inferrer #: TypeInferrer
17
17
  @language_id = language_id
18
18
  @uri = uri
19
19
  @node_context = node_context
@@ -6,84 +6,66 @@ module RubyLsp
6
6
  class DocumentHighlight
7
7
  include Requests::Support::Common
8
8
 
9
- GLOBAL_VARIABLE_NODES = T.let(
10
- [
11
- Prism::GlobalVariableAndWriteNode,
12
- Prism::GlobalVariableOperatorWriteNode,
13
- Prism::GlobalVariableOrWriteNode,
14
- Prism::GlobalVariableReadNode,
15
- Prism::GlobalVariableTargetNode,
16
- Prism::GlobalVariableWriteNode,
17
- ],
18
- T::Array[T.class_of(Prism::Node)],
19
- )
20
-
21
- INSTANCE_VARIABLE_NODES = T.let(
22
- [
23
- Prism::InstanceVariableAndWriteNode,
24
- Prism::InstanceVariableOperatorWriteNode,
25
- Prism::InstanceVariableOrWriteNode,
26
- Prism::InstanceVariableReadNode,
27
- Prism::InstanceVariableTargetNode,
28
- Prism::InstanceVariableWriteNode,
29
- ],
30
- T::Array[T.class_of(Prism::Node)],
31
- )
32
-
33
- CONSTANT_NODES = T.let(
34
- [
35
- Prism::ConstantAndWriteNode,
36
- Prism::ConstantOperatorWriteNode,
37
- Prism::ConstantOrWriteNode,
38
- Prism::ConstantReadNode,
39
- Prism::ConstantTargetNode,
40
- Prism::ConstantWriteNode,
41
- ],
42
- T::Array[T.class_of(Prism::Node)],
43
- )
44
-
45
- CONSTANT_PATH_NODES = T.let(
46
- [
47
- Prism::ConstantPathAndWriteNode,
48
- Prism::ConstantPathNode,
49
- Prism::ConstantPathOperatorWriteNode,
50
- Prism::ConstantPathOrWriteNode,
51
- Prism::ConstantPathTargetNode,
52
- Prism::ConstantPathWriteNode,
53
- ],
54
- T::Array[T.class_of(Prism::Node)],
55
- )
56
-
57
- CLASS_VARIABLE_NODES = T.let(
58
- [
59
- Prism::ClassVariableAndWriteNode,
60
- Prism::ClassVariableOperatorWriteNode,
61
- Prism::ClassVariableOrWriteNode,
62
- Prism::ClassVariableReadNode,
63
- Prism::ClassVariableTargetNode,
64
- Prism::ClassVariableWriteNode,
65
- ],
66
- T::Array[T.class_of(Prism::Node)],
67
- )
68
-
69
- LOCAL_NODES = T.let(
70
- [
71
- Prism::LocalVariableAndWriteNode,
72
- Prism::LocalVariableOperatorWriteNode,
73
- Prism::LocalVariableOrWriteNode,
74
- Prism::LocalVariableReadNode,
75
- Prism::LocalVariableTargetNode,
76
- Prism::LocalVariableWriteNode,
77
- Prism::BlockParameterNode,
78
- Prism::RequiredParameterNode,
79
- Prism::RequiredKeywordParameterNode,
80
- Prism::OptionalKeywordParameterNode,
81
- Prism::RestParameterNode,
82
- Prism::OptionalParameterNode,
83
- Prism::KeywordRestParameterNode,
84
- ],
85
- T::Array[T.class_of(Prism::Node)],
86
- )
9
+ GLOBAL_VARIABLE_NODES = [
10
+ Prism::GlobalVariableAndWriteNode,
11
+ Prism::GlobalVariableOperatorWriteNode,
12
+ Prism::GlobalVariableOrWriteNode,
13
+ Prism::GlobalVariableReadNode,
14
+ Prism::GlobalVariableTargetNode,
15
+ Prism::GlobalVariableWriteNode,
16
+ ] #: Array[singleton(Prism::Node)]
17
+
18
+ INSTANCE_VARIABLE_NODES = [
19
+ Prism::InstanceVariableAndWriteNode,
20
+ Prism::InstanceVariableOperatorWriteNode,
21
+ Prism::InstanceVariableOrWriteNode,
22
+ Prism::InstanceVariableReadNode,
23
+ Prism::InstanceVariableTargetNode,
24
+ Prism::InstanceVariableWriteNode,
25
+ ] #: Array[singleton(Prism::Node)]
26
+
27
+ CONSTANT_NODES = [
28
+ Prism::ConstantAndWriteNode,
29
+ Prism::ConstantOperatorWriteNode,
30
+ Prism::ConstantOrWriteNode,
31
+ Prism::ConstantReadNode,
32
+ Prism::ConstantTargetNode,
33
+ Prism::ConstantWriteNode,
34
+ ] #: Array[singleton(Prism::Node)]
35
+
36
+ CONSTANT_PATH_NODES = [
37
+ Prism::ConstantPathAndWriteNode,
38
+ Prism::ConstantPathNode,
39
+ Prism::ConstantPathOperatorWriteNode,
40
+ Prism::ConstantPathOrWriteNode,
41
+ Prism::ConstantPathTargetNode,
42
+ Prism::ConstantPathWriteNode,
43
+ ] #: Array[singleton(Prism::Node)]
44
+
45
+ CLASS_VARIABLE_NODES = [
46
+ Prism::ClassVariableAndWriteNode,
47
+ Prism::ClassVariableOperatorWriteNode,
48
+ Prism::ClassVariableOrWriteNode,
49
+ Prism::ClassVariableReadNode,
50
+ Prism::ClassVariableTargetNode,
51
+ Prism::ClassVariableWriteNode,
52
+ ] #: Array[singleton(Prism::Node)]
53
+
54
+ LOCAL_NODES = [
55
+ Prism::LocalVariableAndWriteNode,
56
+ Prism::LocalVariableOperatorWriteNode,
57
+ Prism::LocalVariableOrWriteNode,
58
+ Prism::LocalVariableReadNode,
59
+ Prism::LocalVariableTargetNode,
60
+ Prism::LocalVariableWriteNode,
61
+ Prism::BlockParameterNode,
62
+ Prism::RequiredParameterNode,
63
+ Prism::RequiredKeywordParameterNode,
64
+ Prism::OptionalKeywordParameterNode,
65
+ Prism::RestParameterNode,
66
+ Prism::OptionalParameterNode,
67
+ Prism::KeywordRestParameterNode,
68
+ ] #: Array[singleton(Prism::Node)]
87
69
 
88
70
  #: (ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight] response_builder, Prism::Node? target, Prism::Node? parent, Prism::Dispatcher dispatcher, Hash[Symbol, untyped] position) -> void
89
71
  def initialize(response_builder, target, parent, dispatcher, position)
@@ -114,8 +96,8 @@ module RubyLsp
114
96
  [target, nil]
115
97
  end
116
98
 
117
- @target = T.let(highlight_target, T.nilable(Prism::Node))
118
- @target_value = T.let(highlight_target_value, T.nilable(String))
99
+ @target = highlight_target #: Prism::Node?
100
+ @target_value = highlight_target_value #: String?
119
101
  @target_position = position
120
102
 
121
103
  if @target
@@ -8,49 +8,43 @@ module RubyLsp
8
8
  class DocumentLink
9
9
  include Requests::Support::Common
10
10
 
11
- GEM_TO_VERSION_MAP = T.let(
12
- [*::Gem::Specification.default_stubs, *::Gem::Specification.stubs].map! do |s|
13
- [s.name, s.version.to_s]
14
- end.to_h.freeze,
15
- T::Hash[String, String],
16
- )
11
+ GEM_TO_VERSION_MAP = [*::Gem::Specification.default_stubs, *::Gem::Specification.stubs].map! do |s|
12
+ [s.name, s.version.to_s]
13
+ end.to_h.freeze #: Hash[String, String]
17
14
 
18
15
  class << self
19
16
  #: -> Hash[String, Hash[String, Hash[String, String]]]
20
17
  def gem_paths
21
- @gem_paths ||= T.let(
22
- begin
23
- lookup = {}
24
-
25
- Gem::Specification.stubs.each do |stub|
26
- spec = stub.to_spec
27
- lookup[spec.name] = {}
28
- lookup[spec.name][spec.version.to_s] = {}
29
-
30
- Dir.glob("**/*.rb", base: "#{spec.full_gem_path.delete_prefix("//?/")}/").each do |path|
31
- lookup[spec.name][spec.version.to_s][path] = "#{spec.full_gem_path}/#{path}"
32
- end
33
- end
18
+ @gem_paths ||= begin
19
+ lookup = {}
20
+
21
+ Gem::Specification.stubs.each do |stub|
22
+ spec = stub.to_spec
23
+ lookup[spec.name] = {}
24
+ lookup[spec.name][spec.version.to_s] = {}
34
25
 
35
- Gem::Specification.default_stubs.each do |stub|
36
- spec = stub.to_spec
37
- lookup[spec.name] = {}
38
- lookup[spec.name][spec.version.to_s] = {}
39
- prefix_matchers = Regexp.union(spec.require_paths.map do |rp|
40
- Regexp.new("^#{rp}/")
41
- end)
42
- prefix_matcher = Regexp.union(prefix_matchers, //)
43
-
44
- spec.files.each do |file|
45
- path = file.sub(prefix_matcher, "")
46
- lookup[spec.name][spec.version.to_s][path] = "#{RbConfig::CONFIG["rubylibdir"]}/#{path}"
47
- end
26
+ Dir.glob("**/*.rb", base: "#{spec.full_gem_path.delete_prefix("//?/")}/").each do |path|
27
+ lookup[spec.name][spec.version.to_s][path] = "#{spec.full_gem_path}/#{path}"
28
+ end
29
+ end
30
+
31
+ Gem::Specification.default_stubs.each do |stub|
32
+ spec = stub.to_spec
33
+ lookup[spec.name] = {}
34
+ lookup[spec.name][spec.version.to_s] = {}
35
+ prefix_matchers = Regexp.union(spec.require_paths.map do |rp|
36
+ Regexp.new("^#{rp}/")
37
+ end)
38
+ prefix_matcher = Regexp.union(prefix_matchers, //)
39
+
40
+ spec.files.each do |file|
41
+ path = file.sub(prefix_matcher, "")
42
+ lookup[spec.name][spec.version.to_s][path] = "#{RbConfig::CONFIG["rubylibdir"]}/#{path}"
48
43
  end
44
+ end
49
45
 
50
- lookup
51
- end,
52
- T.nilable(T::Hash[String, T::Hash[String, T::Hash[String, String]]]),
53
- )
46
+ lookup
47
+ end #: Hash[String, Hash[String, Hash[String, String]]]?
54
48
  end
55
49
  end
56
50
 
@@ -61,13 +55,10 @@ module RubyLsp
61
55
  @response_builder = response_builder
62
56
  path = uri.to_standardized_path
63
57
  version_match = path ? /(?<=%40)[\d.]+(?=\.rbi$)/.match(path) : nil
64
- @gem_version = T.let(version_match && version_match[0], T.nilable(String))
65
- @lines_to_comments = T.let(
66
- comments.to_h do |comment|
67
- [comment.location.end_line, comment]
68
- end,
69
- T::Hash[Integer, Prism::Comment],
70
- )
58
+ @gem_version = version_match && version_match[0] #: String?
59
+ @lines_to_comments = comments.to_h do |comment|
60
+ [comment.location.end_line, comment]
61
+ end #: Hash[Integer, Prism::Comment]
71
62
 
72
63
  dispatcher.register(
73
64
  self,
@@ -6,7 +6,7 @@ module RubyLsp
6
6
  class DocumentSymbol
7
7
  include Requests::Support::Common
8
8
 
9
- ATTR_ACCESSORS = T.let([:attr_reader, :attr_writer, :attr_accessor].freeze, T::Array[Symbol])
9
+ ATTR_ACCESSORS = [:attr_reader, :attr_writer, :attr_accessor].freeze #: Array[Symbol]
10
10
 
11
11
  #: (ResponseBuilders::DocumentSymbol response_builder, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
12
12
  def initialize(response_builder, uri, dispatcher)
@@ -9,7 +9,7 @@ module RubyLsp
9
9
  #: (ResponseBuilders::CollectionResponseBuilder[Interface::FoldingRange] response_builder, Array[Prism::Comment] comments, Prism::Dispatcher dispatcher) -> void
10
10
  def initialize(response_builder, comments, dispatcher)
11
11
  @response_builder = response_builder
12
- @requires = T.let([], T::Array[Prism::CallNode])
12
+ @requires = [] #: Array[Prism::CallNode]
13
13
  @comments = comments
14
14
 
15
15
  dispatcher.register(