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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b902a160bf7f96c2b65716065887523f5e4d1788e9ba7211a5500513f951d2f
4
- data.tar.gz: d2500874ca70ea7aa4df5d1ce2106d16e67143fb5cff87208bdfab36a4b49414
3
+ metadata.gz: e224f23084eccd6f7b441b6cf6ae2793fb9c73a0045bf36f8c1bbdf2b1f00445
4
+ data.tar.gz: 581749c8bd2ab362075e49940d364af6a237068e6107d340a2535043d7fdec37
5
5
  SHA512:
6
- metadata.gz: 5d7d14c58e08d99a9c4f19d2ccde6171da415093c7ebab744181af7ebc8617eae4ba09a992123542d5a5ba44177457cd23cd8bd0ece1886b17237c7bad73fc2b
7
- data.tar.gz: eea9a42eeabe3e8c5ce86210770f76e210b313bd94bc457dcfe99fc7a0913e24443b67e35c4c64e46420e95a47cd2cb0eaa7004fbbb8e9544932a90c63686219
6
+ metadata.gz: a5d7cb45c56ad5e9e92cba7a0012be7a1626044da4fbc936c413b7a8e5cb3cdd4463bf56dd35ef65feed10f0de363edd04702a4496572248e6e74ea9f720a373
7
+ data.tar.gz: 53639a355c1641e8b11d4e756a417ea9ee96421cb5a87090ffc94cd8f905d41ca3fa5111e4171a81fa62b452c23088895deca0e7eb52fd2e8fed82e1232d2d06
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.23.12
1
+ 0.23.13
@@ -29,7 +29,7 @@ module RuboCop
29
29
  class UseLanguageServerAliases < RuboCop::Cop::Base
30
30
  extend RuboCop::Cop::AutoCorrector
31
31
 
32
- ALIASED_CONSTANTS = T.let([:Interface, :Transport, :Constant].freeze, T::Array[Symbol])
32
+ ALIASED_CONSTANTS = [:Interface, :Transport, :Constant].freeze #: Array[Symbol]
33
33
 
34
34
  MSG = "Use constant alias `%{constant}`."
35
35
 
@@ -3,16 +3,13 @@
3
3
 
4
4
  module RubyIndexer
5
5
  class Configuration
6
- CONFIGURATION_SCHEMA = T.let(
7
- {
8
- "excluded_gems" => Array,
9
- "included_gems" => Array,
10
- "excluded_patterns" => Array,
11
- "included_patterns" => Array,
12
- "excluded_magic_comments" => Array,
13
- }.freeze,
14
- T::Hash[String, T.untyped],
15
- )
6
+ CONFIGURATION_SCHEMA = {
7
+ "excluded_gems" => Array,
8
+ "included_gems" => Array,
9
+ "excluded_patterns" => Array,
10
+ "included_patterns" => Array,
11
+ "excluded_magic_comments" => Array,
12
+ }.freeze #: Hash[String, untyped]
16
13
 
17
14
  #: String
18
15
  attr_writer :workspace_path
@@ -22,18 +19,15 @@ module RubyIndexer
22
19
 
23
20
  #: -> void
24
21
  def initialize
25
- @workspace_path = T.let(Dir.pwd, String)
26
- @encoding = T.let(Encoding::UTF_8, Encoding)
27
- @excluded_gems = T.let(initial_excluded_gems, T::Array[String])
28
- @included_gems = T.let([], T::Array[String])
29
-
30
- @excluded_patterns = T.let(
31
- [
32
- "**/{test,spec}/**/{*_test.rb,test_*.rb,*_spec.rb}",
33
- "**/fixtures/**/*",
34
- ],
35
- T::Array[String],
36
- )
22
+ @workspace_path = Dir.pwd #: String
23
+ @encoding = Encoding::UTF_8 #: Encoding
24
+ @excluded_gems = initial_excluded_gems #: Array[String]
25
+ @included_gems = [] #: Array[String]
26
+
27
+ @excluded_patterns = [
28
+ "**/{test,spec}/**/{*_test.rb,test_*.rb,*_spec.rb}",
29
+ "**/fixtures/**/*",
30
+ ] #: Array[String]
37
31
 
38
32
  path = Bundler.settings["path"]
39
33
  if path
@@ -45,23 +39,20 @@ module RubyIndexer
45
39
 
46
40
  # We start the included patterns with only the non excluded directories so that we can avoid paying the price of
47
41
  # traversing large directories that don't include Ruby files like `node_modules`
48
- @included_patterns = T.let(["{#{top_level_directories.join(",")}}/**/*.rb", "*.rb"], T::Array[String])
49
- @excluded_magic_comments = T.let(
50
- [
51
- "frozen_string_literal:",
52
- "typed:",
53
- "compiled:",
54
- "encoding:",
55
- "shareable_constant_value:",
56
- "warn_indent:",
57
- "rubocop:",
58
- "nodoc:",
59
- "doc:",
60
- "coding:",
61
- "warn_past_scope:",
62
- ],
63
- T::Array[String],
64
- )
42
+ @included_patterns = ["{#{top_level_directories.join(",")}}/**/*.rb", "*.rb"] #: Array[String]
43
+ @excluded_magic_comments = [
44
+ "frozen_string_literal:",
45
+ "typed:",
46
+ "compiled:",
47
+ "encoding:",
48
+ "shareable_constant_value:",
49
+ "warn_indent:",
50
+ "rubocop:",
51
+ "nodoc:",
52
+ "doc:",
53
+ "coding:",
54
+ "warn_past_scope:",
55
+ ] #: Array[String]
65
56
  end
66
57
 
67
58
  #: -> Array[URI::Generic]
@@ -177,7 +168,7 @@ module RubyIndexer
177
168
 
178
169
  #: -> Regexp
179
170
  def magic_comment_regex
180
- @magic_comment_regex ||= T.let(/^#\s*#{@excluded_magic_comments.join("|")}/, T.nilable(Regexp))
171
+ @magic_comment_regex ||= /^#\s*#{@excluded_magic_comments.join("|")}/ #: Regexp?
181
172
  end
182
173
 
183
174
  #: (Hash[String, untyped] config) -> void
@@ -3,8 +3,8 @@
3
3
 
4
4
  module RubyIndexer
5
5
  class DeclarationListener
6
- OBJECT_NESTING = T.let(["Object"].freeze, T::Array[String])
7
- BASIC_OBJECT_NESTING = T.let(["BasicObject"].freeze, T::Array[String])
6
+ OBJECT_NESTING = ["Object"].freeze #: Array[String]
7
+ BASIC_OBJECT_NESTING = ["BasicObject"].freeze #: Array[String]
8
8
 
9
9
  #: Array[String]
10
10
  attr_reader :indexing_errors
@@ -13,28 +13,24 @@ module RubyIndexer
13
13
  def initialize(index, dispatcher, parse_result, uri, collect_comments: false)
14
14
  @index = index
15
15
  @uri = uri
16
- @enhancements = T.let(Enhancement.all(self), T::Array[Enhancement])
17
- @visibility_stack = T.let([VisibilityScope.public_scope], T::Array[VisibilityScope])
18
- @comments_by_line = T.let(
19
- parse_result.comments.to_h do |c|
20
- [c.location.start_line, c]
21
- end,
22
- T::Hash[Integer, Prism::Comment],
23
- )
24
- @inside_def = T.let(false, T::Boolean)
25
- @code_units_cache = T.let(
26
- parse_result.code_units_cache(@index.configuration.encoding),
27
- T.any(T.proc.params(arg0: Integer).returns(Integer), Prism::CodeUnitsCache),
28
- )
29
- @source_lines = T.let(parse_result.source.lines, T::Array[String])
16
+ @enhancements = Enhancement.all(self) #: Array[Enhancement]
17
+ @visibility_stack = [VisibilityScope.public_scope] #: Array[VisibilityScope]
18
+ @comments_by_line = parse_result.comments.to_h do |c|
19
+ [c.location.start_line, c]
20
+ end #: Hash[Integer, Prism::Comment]
21
+ @inside_def = false #: bool
22
+ @code_units_cache = parse_result
23
+ .code_units_cache(@index.configuration.encoding) #: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache)
24
+
25
+ @source_lines = parse_result.source.lines #: Array[String]
30
26
 
31
27
  # The nesting stack we're currently inside. Used to determine the fully qualified name of constants, but only
32
28
  # stored by unresolved aliases which need the original nesting to be lazily resolved
33
- @stack = T.let([], T::Array[String])
29
+ @stack = [] #: Array[String]
34
30
 
35
31
  # A stack of namespace entries that represent where we currently are. Used to properly assign methods to an owner
36
- @owner_stack = T.let([], T::Array[Entry::Namespace])
37
- @indexing_errors = T.let([], T::Array[String])
32
+ @owner_stack = [] #: Array[Entry::Namespace]
33
+ @indexing_errors = [] #: Array[String]
38
34
  @collect_comments = collect_comments
39
35
 
40
36
  dispatcher.register(
@@ -269,11 +265,11 @@ module RubyIndexer
269
265
  when :include, :prepend, :extend
270
266
  handle_module_operation(node, message)
271
267
  when :public
272
- @visibility_stack.push(VisibilityScope.public_scope)
268
+ handle_visibility_change(node, Entry::Visibility::PUBLIC)
273
269
  when :protected
274
- @visibility_stack.push(VisibilityScope.new(visibility: Entry::Visibility::PROTECTED))
270
+ handle_visibility_change(node, Entry::Visibility::PROTECTED)
275
271
  when :private
276
- @visibility_stack.push(VisibilityScope.new(visibility: Entry::Visibility::PRIVATE))
272
+ handle_visibility_change(node, Entry::Visibility::PRIVATE)
277
273
  when :module_function
278
274
  handle_module_function(node)
279
275
  when :private_class_method
@@ -1038,5 +1034,43 @@ module RubyIndexer
1038
1034
 
1039
1035
  name.split("::").last
1040
1036
  end
1037
+
1038
+ #: (Prism::CallNode, Entry::Visibility) -> void
1039
+ def handle_visibility_change(node, visibility)
1040
+ owner = @owner_stack.last
1041
+ return unless owner
1042
+
1043
+ owner_name = owner.name
1044
+ method_names = string_or_symbol_argument_values(node)
1045
+
1046
+ if method_names.empty?
1047
+ @visibility_stack.push(VisibilityScope.new(visibility: visibility))
1048
+ return
1049
+ end
1050
+
1051
+ method_names.each do |method_name|
1052
+ entries = @index.resolve_method(method_name, owner_name)
1053
+ next unless entries
1054
+
1055
+ entries.each do |entry|
1056
+ entry.visibility = visibility
1057
+ end
1058
+ end
1059
+ end
1060
+
1061
+ #: (Prism::CallNode) -> Array[String]
1062
+ def string_or_symbol_argument_values(node)
1063
+ arguments = node.arguments&.arguments
1064
+ return [] unless arguments
1065
+
1066
+ arguments.filter_map do |argument|
1067
+ case argument
1068
+ when Prism::StringNode
1069
+ argument.content
1070
+ when Prism::SymbolNode
1071
+ argument.value
1072
+ end
1073
+ end
1074
+ end
1041
1075
  end
1042
1076
  end
@@ -8,7 +8,7 @@ module RubyIndexer
8
8
 
9
9
  abstract!
10
10
 
11
- @enhancements = T.let([], T::Array[T::Class[Enhancement]])
11
+ @enhancements = [] #: Array[Class[Enhancement]]
12
12
 
13
13
  class << self
14
14
  extend T::Sig
@@ -30,7 +30,7 @@ module RubyIndexer
30
30
  @name = name
31
31
  @uri = uri
32
32
  @comments = comments
33
- @visibility = T.let(Visibility::PUBLIC, Visibility)
33
+ @visibility = Visibility::PUBLIC #: Visibility
34
34
  @location = location
35
35
  end
36
36
 
@@ -137,7 +137,7 @@ module RubyIndexer
137
137
 
138
138
  #: (Array[String] nesting, URI::Generic uri, Location location, Location name_location, String? comments) -> void
139
139
  def initialize(nesting, uri, location, name_location, comments)
140
- @name = T.let(nesting.join("::"), String)
140
+ @name = nesting.join("::") #: String
141
141
  # The original nesting where this namespace was discovered
142
142
  @nesting = nesting
143
143
 
@@ -156,7 +156,7 @@ module RubyIndexer
156
156
  # and prepended
157
157
  #: -> Array[ModuleOperation]
158
158
  def mixin_operations
159
- @mixin_operations ||= T.let([], T.nilable(T::Array[ModuleOperation]))
159
+ @mixin_operations ||= [] #: Array[ModuleOperation]?
160
160
  end
161
161
 
162
162
  #: -> Integer
@@ -251,7 +251,7 @@ module RubyIndexer
251
251
 
252
252
  # A rest method parameter, e.g. `def foo(*a)`
253
253
  class RestParameter < Parameter
254
- DEFAULT_NAME = T.let(:"<anonymous splat>", Symbol)
254
+ DEFAULT_NAME = :"<anonymous splat>" #: Symbol
255
255
 
256
256
  # @override
257
257
  #: -> Symbol
@@ -262,7 +262,7 @@ module RubyIndexer
262
262
 
263
263
  # A keyword rest method parameter, e.g. `def foo(**a)`
264
264
  class KeywordRestParameter < Parameter
265
- DEFAULT_NAME = T.let(:"<anonymous keyword splat>", Symbol)
265
+ DEFAULT_NAME = :"<anonymous keyword splat>" #: Symbol
266
266
 
267
267
  # @override
268
268
  #: -> Symbol
@@ -273,7 +273,7 @@ module RubyIndexer
273
273
 
274
274
  # A block method parameter, e.g. `def foo(&block)`
275
275
  class BlockParameter < Parameter
276
- DEFAULT_NAME = T.let(:"<anonymous block>", Symbol)
276
+ DEFAULT_NAME = :"<anonymous block>" #: Symbol
277
277
 
278
278
  class << self
279
279
  #: -> BlockParameter
@@ -343,14 +343,11 @@ module RubyIndexer
343
343
  # @override
344
344
  #: -> Array[Signature]
345
345
  def signatures
346
- @signatures ||= T.let(
347
- begin
348
- params = []
349
- params << RequiredParameter.new(name: name.delete_suffix("=").to_sym) if name.end_with?("=")
350
- [Entry::Signature.new(params)]
351
- end,
352
- T.nilable(T::Array[Signature]),
353
- )
346
+ @signatures ||= begin
347
+ params = []
348
+ params << RequiredParameter.new(name: name.delete_suffix("=").to_sym) if name.end_with?("=")
349
+ [Entry::Signature.new(params)]
350
+ end #: Array[Signature]?
354
351
  end
355
352
  end
356
353
 
@@ -484,7 +481,7 @@ module RubyIndexer
484
481
  )
485
482
 
486
483
  @target = target
487
- @owner = T.let(unresolved_alias.owner, T.nilable(Entry::Namespace))
484
+ @owner = unresolved_alias.owner #: Entry::Namespace?
488
485
  end
489
486
 
490
487
  #: -> String
@@ -539,10 +536,10 @@ module RubyIndexer
539
536
  #: (Array[Prism::Node] arguments) -> bool
540
537
  def matches?(arguments)
541
538
  min_pos = 0
542
- max_pos = T.let(0, T.any(Integer, Float))
539
+ max_pos = 0 #: (Integer | Float)
543
540
  names = []
544
- has_forward = T.let(false, T::Boolean)
545
- has_keyword_rest = T.let(false, T::Boolean)
541
+ has_forward = false #: bool
542
+ has_keyword_rest = false #: bool
546
543
 
547
544
  @parameters.each do |param|
548
545
  case param
@@ -57,10 +57,10 @@ module RubyIndexer
57
57
  # "Foo" => [#<Entry::Class>, #<Entry::Class>],
58
58
  # "Foo::Bar" => [#<Entry::Class>],
59
59
  # }
60
- @entries = T.let({}, T::Hash[String, T::Array[Entry]])
60
+ @entries = {} #: Hash[String, Array[Entry]]
61
61
 
62
62
  # Holds all entries in the index using a prefix tree for searching based on prefixes to provide autocompletion
63
- @entries_tree = T.let(PrefixTree[T::Array[Entry]].new, PrefixTree[T::Array[Entry]])
63
+ @entries_tree = PrefixTree[T::Array[Entry]].new #: PrefixTree[Array[Entry]]
64
64
 
65
65
  # Holds references to where entries where discovered so that we can easily delete them
66
66
  # {
@@ -68,23 +68,20 @@ module RubyIndexer
68
68
  # "file:///my/project/bar.rb" => [#<Entry::Class>],
69
69
  # "untitled:Untitled-1" => [#<Entry::Class>],
70
70
  # }
71
- @uris_to_entries = T.let({}, T::Hash[String, T::Array[Entry]])
71
+ @uris_to_entries = {} #: Hash[String, Array[Entry]]
72
72
 
73
73
  # Holds all require paths for every indexed item so that we can provide autocomplete for requires
74
- @require_paths_tree = T.let(PrefixTree[URI::Generic].new, PrefixTree[URI::Generic])
74
+ @require_paths_tree = PrefixTree[URI::Generic].new #: PrefixTree[URI::Generic]
75
75
 
76
76
  # Holds the linearized ancestors list for every namespace
77
- @ancestors = T.let({}, T::Hash[String, T::Array[String]])
77
+ @ancestors = {} #: Hash[String, Array[String]]
78
78
 
79
79
  # Map of module name to included hooks that have to be executed when we include the given module
80
- @included_hooks = T.let(
81
- {},
82
- T::Hash[String, T::Array[T.proc.params(index: Index, base: Entry::Namespace).void]],
83
- )
80
+ @included_hooks = {} #: Hash[String, Array[^(Index index, Entry::Namespace base) -> void]]
84
81
 
85
- @configuration = T.let(RubyIndexer::Configuration.new, Configuration)
82
+ @configuration = RubyIndexer::Configuration.new #: Configuration
86
83
 
87
- @initial_indexing_completed = T.let(false, T::Boolean)
84
+ @initial_indexing_completed = false #: bool
88
85
  end
89
86
 
90
87
  # Register an included `hook` that will be executed when `module_name` is included into any namespace
@@ -39,7 +39,7 @@ module RubyIndexer
39
39
 
40
40
  #: -> void
41
41
  def initialize
42
- @root = T.let(Node.new("", ""), Node[Value])
42
+ @root = Node.new("", "") #: Node[Value]
43
43
  end
44
44
 
45
45
  # Search the PrefixTree based on a given `prefix`. If `foo` is an entry in the tree, then searching for `fo` will
@@ -78,7 +78,7 @@ module RubyIndexer
78
78
  return unless node
79
79
 
80
80
  # Remove the node from the tree and then go up the parents to remove any of them with empty children
81
- parent = T.let(T.must(node.parent), T.nilable(Node[Value]))
81
+ parent = T.must(node.parent) #: Node[Value]?
82
82
 
83
83
  while parent
84
84
  parent.children.delete(node.key)
@@ -3,7 +3,7 @@
3
3
 
4
4
  module RubyIndexer
5
5
  class RBSIndexer
6
- HAS_UNTYPED_FUNCTION = T.let(!!defined?(RBS::Types::UntypedFunction), T::Boolean)
6
+ HAS_UNTYPED_FUNCTION = !!defined?(RBS::Types::UntypedFunction) #: bool
7
7
 
8
8
  #: (Index index) -> void
9
9
  def initialize(index)
@@ -66,8 +66,8 @@ module RubyIndexer
66
66
  @index = index
67
67
  @uri = uri
68
68
  @include_declarations = include_declarations
69
- @stack = T.let([], T::Array[String])
70
- @references = T.let([], T::Array[Reference])
69
+ @stack = [] #: Array[String]
70
+ @references = [] #: Array[Reference]
71
71
 
72
72
  dispatcher.register(
73
73
  self,
@@ -147,17 +147,26 @@ module RubyIndexer
147
147
  uris = @config.indexable_uris
148
148
  assert(uris.none? { |uri| uri.full_path.start_with?(File.join(dir, "ignore")) })
149
149
 
150
+ # The regular default gem path is ~/.rubies/3.4.1/lib/ruby/3.4.0
151
+ # The alternative default gem path is ~/.rubies/3.4.1/lib/ruby/gems/3.4.0
152
+ # Here part_1 contains ~/.rubies/3.4.1/lib/ruby/ and part_2 contains 3.4.0, so that we can turn it into the
153
+ # alternative path
154
+ part_1, part_2 = Pathname.new(RbConfig::CONFIG["rubylibdir"]).split
155
+ other_default_gem_dir = part_1.join("gems").join(part_2).to_s
156
+
150
157
  # After switching the workspace path, all indexable URIs will be found in one of these places:
151
158
  # - The new workspace path
152
159
  # - The Ruby LSP's own code (because Bundler is requiring the dependency from source)
153
160
  # - Bundled gems
154
161
  # - Default gems
162
+ # - Other default gem directory
155
163
  assert(
156
164
  uris.all? do |u|
157
165
  u.full_path.start_with?(dir) ||
158
166
  u.full_path.start_with?(File.join(Dir.pwd, "lib")) ||
159
167
  u.full_path.start_with?(Bundler.bundle_path.to_s) ||
160
- u.full_path.start_with?(RbConfig::CONFIG["rubylibdir"])
168
+ u.full_path.start_with?(RbConfig::CONFIG["rubylibdir"]) ||
169
+ u.full_path.start_with?(other_default_gem_dir)
161
170
  end,
162
171
  )
163
172
  end
@@ -924,6 +924,32 @@ module RubyIndexer
924
924
  RUBY
925
925
  end
926
926
 
927
+ def test_changing_visibility_post_definition
928
+ index(<<~RUBY)
929
+ class Foo
930
+ def bar; end
931
+ private :bar
932
+
933
+ def baz; end
934
+ protected :baz
935
+
936
+ private
937
+ def qux; end
938
+
939
+ public :qux
940
+ end
941
+ RUBY
942
+
943
+ entry = T.must(@index["bar"].first)
944
+ assert_predicate(entry, :private?)
945
+
946
+ entry = T.must(@index["baz"].first)
947
+ assert_predicate(entry, :protected?)
948
+
949
+ entry = T.must(@index["qux"].first)
950
+ assert_predicate(entry, :public?)
951
+ end
952
+
927
953
  private
928
954
 
929
955
  #: (Entry::Method entry, String call_string) -> void
@@ -359,7 +359,7 @@ module RubyIndexer
359
359
  assert_equal("all?", entry.old_name)
360
360
  assert_equal("Array", entry.owner.name)
361
361
  assert(entry.file_path.end_with?("core/array.rbs"))
362
- assert_includes(entry.comments, "Returns `true` if any element of `self` meets a given criterion.")
362
+ refute_empty(entry.comments)
363
363
  end
364
364
 
365
365
  def test_indexing_untyped_functions
@@ -25,10 +25,10 @@ module RubyLsp
25
25
 
26
26
  abstract!
27
27
 
28
- @addons = T.let([], T::Array[Addon])
29
- @addon_classes = T.let([], T::Array[T.class_of(Addon)])
28
+ @addons = [] #: Array[Addon]
29
+ @addon_classes = [] #: Array[singleton(Addon)]
30
30
  # Add-on instances that have declared a handler to accept file watcher events
31
- @file_watcher_addons = T.let([], T::Array[Addon])
31
+ @file_watcher_addons = [] #: Array[Addon]
32
32
 
33
33
  AddonNotFoundError = Class.new(StandardError)
34
34
 
@@ -149,7 +149,7 @@ module RubyLsp
149
149
 
150
150
  #: -> void
151
151
  def initialize
152
- @errors = T.let([], T::Array[StandardError])
152
+ @errors = [] #: Array[StandardError]
153
153
  end
154
154
 
155
155
  #: (StandardError error) -> self
@@ -236,5 +236,13 @@ module RubyLsp
236
236
  # @overridable
237
237
  #: (ResponseBuilders::TestCollection response_builder, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
238
238
  def create_discover_tests_listener(response_builder, dispatcher, uri); end
239
+
240
+ # Resolves the minimal set of commands required to execute the requested tests. Add-ons are responsible for only
241
+ # handling items related to the framework they add support for and have discovered themselves
242
+ # @overridable
243
+ #: (Array[Hash[Symbol, untyped]]) -> Array[String]
244
+ def resolve_test_commands(items)
245
+ []
246
+ end
239
247
  end
240
248
  end
@@ -10,28 +10,25 @@ module RubyLsp
10
10
 
11
11
  #: (**untyped options) -> void
12
12
  def initialize(**options)
13
- @test_mode = T.let(options[:test_mode], T.nilable(T::Boolean))
14
- @setup_error = T.let(options[:setup_error], T.nilable(StandardError))
15
- @install_error = T.let(options[:install_error], T.nilable(StandardError))
16
- @writer = T.let(Transport::Stdio::Writer.new, Transport::Stdio::Writer)
17
- @reader = T.let(Transport::Stdio::Reader.new, Transport::Stdio::Reader)
18
- @incoming_queue = T.let(Thread::Queue.new, Thread::Queue)
19
- @outgoing_queue = T.let(Thread::Queue.new, Thread::Queue)
20
- @cancelled_requests = T.let([], T::Array[Integer])
21
- @worker = T.let(new_worker, Thread)
22
- @current_request_id = T.let(1, Integer)
23
- @global_state = T.let(GlobalState.new, GlobalState)
24
- @store = T.let(Store.new(@global_state), Store)
25
- @outgoing_dispatcher = T.let(
26
- Thread.new do
27
- unless @test_mode
28
- while (message = @outgoing_queue.pop)
29
- @global_state.synchronize { @writer.write(message.to_hash) }
30
- end
13
+ @test_mode = options[:test_mode] #: bool?
14
+ @setup_error = options[:setup_error] #: StandardError?
15
+ @install_error = options[:install_error] #: StandardError?
16
+ @writer = Transport::Stdio::Writer.new #: Transport::Stdio::Writer
17
+ @reader = Transport::Stdio::Reader.new #: Transport::Stdio::Reader
18
+ @incoming_queue = Thread::Queue.new #: Thread::Queue
19
+ @outgoing_queue = Thread::Queue.new #: Thread::Queue
20
+ @cancelled_requests = [] #: Array[Integer]
21
+ @worker = new_worker #: Thread
22
+ @current_request_id = 1 #: Integer
23
+ @global_state = GlobalState.new #: GlobalState
24
+ @store = Store.new(@global_state) #: Store
25
+ @outgoing_dispatcher = Thread.new do
26
+ unless @test_mode
27
+ while (message = @outgoing_queue.pop)
28
+ @global_state.synchronize { @writer.write(message.to_hash) }
31
29
  end
32
- end,
33
- Thread,
34
- )
30
+ end
31
+ end #: Thread
35
32
 
36
33
  Thread.main.priority = 1
37
34
 
@@ -148,7 +145,7 @@ module RubyLsp
148
145
  #: -> Thread
149
146
  def new_worker
150
147
  Thread.new do
151
- while (message = T.let(@incoming_queue.pop, T.nilable(T::Hash[Symbol, T.untyped])))
148
+ while (message = @incoming_queue.pop)
152
149
  id = message[:id]
153
150
 
154
151
  # Check if the request was cancelled before trying to process it
@@ -16,24 +16,24 @@ module RubyLsp
16
16
  def initialize
17
17
  # The editor supports watching files. This requires two capabilities: dynamic registration and relative pattern
18
18
  # support
19
- @supports_watching_files = T.let(false, T::Boolean)
19
+ @supports_watching_files = false #: bool
20
20
 
21
21
  # The editor supports request delegation. This is an experimental capability since request delegation has not been
22
22
  # standardized into the LSP spec yet
23
- @supports_request_delegation = T.let(false, T::Boolean)
23
+ @supports_request_delegation = false #: bool
24
24
 
25
25
  # The editor supports extra arbitrary properties for `window/showMessageRequest`. Necessary for add-ons to show
26
26
  # dialogs with user interactions
27
- @window_show_message_supports_extra_properties = T.let(false, T::Boolean)
27
+ @window_show_message_supports_extra_properties = false #: bool
28
28
 
29
29
  # Which resource operations the editor supports, like renaming files
30
- @supported_resource_operations = T.let([], T::Array[String])
30
+ @supported_resource_operations = [] #: Array[String]
31
31
 
32
32
  # The editor supports displaying progress requests
33
- @supports_progress = T.let(false, T::Boolean)
33
+ @supports_progress = false #: bool
34
34
 
35
35
  # The editor supports server initiated refresh for diagnostics
36
- @supports_diagnostic_refresh = T.let(false, T::Boolean)
36
+ @supports_diagnostic_refresh = false #: bool
37
37
  end
38
38
 
39
39
  #: (Hash[Symbol, untyped] capabilities) -> void