ruby-lsp 0.23.11 → 0.23.12

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 (98) 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_register_with_handler_method.rb +3 -5
  6. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +52 -77
  7. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +61 -144
  8. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +8 -6
  9. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +73 -182
  10. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +48 -181
  11. data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
  12. data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +12 -14
  13. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +21 -44
  14. data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +40 -58
  15. data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +9 -16
  16. data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
  17. data/lib/ruby_indexer/test/configuration_test.rb +32 -2
  18. data/lib/ruby_indexer/test/method_test.rb +2 -2
  19. data/lib/ruby_lsp/addon.rb +32 -67
  20. data/lib/ruby_lsp/base_server.rb +10 -10
  21. data/lib/ruby_lsp/client_capabilities.rb +4 -6
  22. data/lib/ruby_lsp/document.rb +21 -32
  23. data/lib/ruby_lsp/erb_document.rb +17 -27
  24. data/lib/ruby_lsp/global_state.rb +30 -32
  25. data/lib/ruby_lsp/internal.rb +2 -0
  26. data/lib/ruby_lsp/listeners/code_lens.rb +21 -39
  27. data/lib/ruby_lsp/listeners/completion.rb +34 -53
  28. data/lib/ruby_lsp/listeners/definition.rb +35 -49
  29. data/lib/ruby_lsp/listeners/document_highlight.rb +60 -69
  30. data/lib/ruby_lsp/listeners/document_link.rb +9 -19
  31. data/lib/ruby_lsp/listeners/document_symbol.rb +34 -48
  32. data/lib/ruby_lsp/listeners/folding_ranges.rb +31 -38
  33. data/lib/ruby_lsp/listeners/hover.rb +37 -47
  34. data/lib/ruby_lsp/listeners/inlay_hints.rb +3 -10
  35. data/lib/ruby_lsp/listeners/semantic_highlighting.rb +29 -35
  36. data/lib/ruby_lsp/listeners/signature_help.rb +4 -23
  37. data/lib/ruby_lsp/listeners/spec_style.rb +199 -0
  38. data/lib/ruby_lsp/listeners/test_style.rb +136 -30
  39. data/lib/ruby_lsp/node_context.rb +8 -35
  40. data/lib/ruby_lsp/rbs_document.rb +7 -5
  41. data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
  42. data/lib/ruby_lsp/requests/code_actions.rb +5 -14
  43. data/lib/ruby_lsp/requests/code_lens.rb +4 -13
  44. data/lib/ruby_lsp/requests/completion.rb +4 -15
  45. data/lib/ruby_lsp/requests/completion_resolve.rb +4 -4
  46. data/lib/ruby_lsp/requests/definition.rb +4 -12
  47. data/lib/ruby_lsp/requests/diagnostics.rb +6 -9
  48. data/lib/ruby_lsp/requests/discover_tests.rb +15 -3
  49. data/lib/ruby_lsp/requests/document_highlight.rb +3 -11
  50. data/lib/ruby_lsp/requests/document_link.rb +4 -13
  51. data/lib/ruby_lsp/requests/document_symbol.rb +4 -7
  52. data/lib/ruby_lsp/requests/folding_ranges.rb +4 -7
  53. data/lib/ruby_lsp/requests/formatting.rb +4 -7
  54. data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
  55. data/lib/ruby_lsp/requests/hover.rb +6 -16
  56. data/lib/ruby_lsp/requests/inlay_hints.rb +4 -13
  57. data/lib/ruby_lsp/requests/on_type_formatting.rb +17 -24
  58. data/lib/ruby_lsp/requests/prepare_rename.rb +3 -8
  59. data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
  60. data/lib/ruby_lsp/requests/range_formatting.rb +3 -4
  61. data/lib/ruby_lsp/requests/references.rb +5 -35
  62. data/lib/ruby_lsp/requests/rename.rb +9 -35
  63. data/lib/ruby_lsp/requests/request.rb +5 -17
  64. data/lib/ruby_lsp/requests/selection_ranges.rb +3 -3
  65. data/lib/ruby_lsp/requests/semantic_highlighting.rb +6 -23
  66. data/lib/ruby_lsp/requests/show_syntax_tree.rb +4 -5
  67. data/lib/ruby_lsp/requests/signature_help.rb +6 -24
  68. data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
  69. data/lib/ruby_lsp/requests/support/common.rb +12 -49
  70. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +12 -14
  71. data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +7 -10
  72. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +9 -15
  73. data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
  74. data/lib/ruby_lsp/requests/support/sorbet.rb +1 -7
  75. data/lib/ruby_lsp/requests/support/source_uri.rb +5 -16
  76. data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +7 -10
  77. data/lib/ruby_lsp/requests/support/test_item.rb +14 -13
  78. data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +4 -5
  79. data/lib/ruby_lsp/requests/workspace_symbol.rb +3 -3
  80. data/lib/ruby_lsp/response_builders/collection_response_builder.rb +4 -4
  81. data/lib/ruby_lsp/response_builders/document_symbol.rb +8 -11
  82. data/lib/ruby_lsp/response_builders/hover.rb +5 -5
  83. data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
  84. data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +18 -40
  85. data/lib/ruby_lsp/response_builders/signature_help.rb +4 -5
  86. data/lib/ruby_lsp/response_builders/test_collection.rb +5 -9
  87. data/lib/ruby_lsp/ruby_document.rb +15 -40
  88. data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +106 -0
  89. data/lib/ruby_lsp/scope.rb +6 -10
  90. data/lib/ruby_lsp/server.rb +125 -74
  91. data/lib/ruby_lsp/setup_bundler.rb +22 -15
  92. data/lib/ruby_lsp/store.rb +12 -28
  93. data/lib/ruby_lsp/test_helper.rb +3 -12
  94. data/lib/ruby_lsp/test_reporter.rb +71 -0
  95. data/lib/ruby_lsp/test_unit_test_runner.rb +96 -0
  96. data/lib/ruby_lsp/type_inferrer.rb +9 -13
  97. data/lib/ruby_lsp/utils.rb +27 -65
  98. metadata +8 -3
@@ -8,12 +8,11 @@ module RubyLsp
8
8
  # WARNING: Methods in this class may be used by Ruby LSP add-ons such as
9
9
  # https://github.com/Shopify/ruby-lsp-rails, or add-ons by created by developers outside of Shopify, so be
10
10
  # cautious of changing anything.
11
- extend T::Sig
12
11
  extend T::Helpers
13
12
 
14
13
  requires_ancestor { Kernel }
15
14
 
16
- sig { params(node: Prism::Node).returns(Interface::Range) }
15
+ #: (Prism::Node node) -> Interface::Range
17
16
  def range_from_node(node)
18
17
  loc = node.location
19
18
 
@@ -26,7 +25,7 @@ module RubyLsp
26
25
  )
27
26
  end
28
27
 
29
- sig { params(location: T.any(Prism::Location, RubyIndexer::Location)).returns(Interface::Range) }
28
+ #: ((Prism::Location | RubyIndexer::Location) location) -> Interface::Range
30
29
  def range_from_location(location)
31
30
  Interface::Range.new(
32
31
  start: Interface::Position.new(
@@ -37,15 +36,7 @@ module RubyLsp
37
36
  )
38
37
  end
39
38
 
40
- sig do
41
- params(
42
- node: Prism::Node,
43
- title: String,
44
- command_name: String,
45
- arguments: T.nilable(T::Array[T.untyped]),
46
- data: T.nilable(T::Hash[T.untyped, T.untyped]),
47
- ).returns(Interface::CodeLens)
48
- end
39
+ #: (Prism::Node node, title: String, command_name: String, arguments: Array[untyped]?, data: Hash[untyped, untyped]?) -> Interface::CodeLens
49
40
  def create_code_lens(node, title:, command_name:, arguments:, data:)
50
41
  range = range_from_node(node)
51
42
 
@@ -60,26 +51,20 @@ module RubyLsp
60
51
  )
61
52
  end
62
53
 
63
- sig { params(file_path: String).returns(T.nilable(T::Boolean)) }
54
+ #: (String file_path) -> bool?
64
55
  def not_in_dependencies?(file_path)
65
56
  BUNDLE_PATH &&
66
57
  !file_path.start_with?(T.must(BUNDLE_PATH)) &&
67
58
  !file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
68
59
  end
69
60
 
70
- sig { params(node: Prism::CallNode).returns(T::Boolean) }
61
+ #: (Prism::CallNode node) -> bool
71
62
  def self_receiver?(node)
72
63
  receiver = node.receiver
73
64
  receiver.nil? || receiver.is_a?(Prism::SelfNode)
74
65
  end
75
66
 
76
- sig do
77
- params(
78
- title: String,
79
- entries: T.any(T::Array[RubyIndexer::Entry], RubyIndexer::Entry),
80
- max_entries: T.nilable(Integer),
81
- ).returns(T::Hash[Symbol, String])
82
- end
67
+ #: (String title, (Array[RubyIndexer::Entry] | RubyIndexer::Entry) entries, ?Integer? max_entries) -> Hash[Symbol, String]
83
68
  def categorized_markdown_from_index_entries(title, entries, max_entries = nil)
84
69
  markdown_title = "```ruby\n#{title}\n```"
85
70
  definitions = []
@@ -112,14 +97,7 @@ module RubyLsp
112
97
  }
113
98
  end
114
99
 
115
- sig do
116
- params(
117
- title: String,
118
- entries: T.any(T::Array[RubyIndexer::Entry], RubyIndexer::Entry),
119
- max_entries: T.nilable(Integer),
120
- extra_links: T.nilable(String),
121
- ).returns(String)
122
- end
100
+ #: (String title, (Array[RubyIndexer::Entry] | RubyIndexer::Entry) entries, ?Integer? max_entries, ?extra_links: String?) -> String
123
101
  def markdown_from_index_entries(title, entries, max_entries = nil, extra_links: nil)
124
102
  categorized_markdown = categorized_markdown_from_index_entries(title, entries, max_entries)
125
103
 
@@ -135,22 +113,12 @@ module RubyLsp
135
113
  MARKDOWN
136
114
  end
137
115
 
138
- sig do
139
- params(
140
- node: T.any(
141
- Prism::ConstantPathNode,
142
- Prism::ConstantReadNode,
143
- Prism::ConstantPathTargetNode,
144
- Prism::CallNode,
145
- Prism::MissingNode,
146
- ),
147
- ).returns(T.nilable(String))
148
- end
116
+ #: ((Prism::ConstantPathNode | Prism::ConstantReadNode | Prism::ConstantPathTargetNode | Prism::CallNode | Prism::MissingNode) node) -> String?
149
117
  def constant_name(node)
150
118
  RubyIndexer::Index.constant_name(node)
151
119
  end
152
120
 
153
- sig { params(node: T.any(Prism::ModuleNode, Prism::ClassNode)).returns(T.nilable(String)) }
121
+ #: ((Prism::ModuleNode | Prism::ClassNode) node) -> String?
154
122
  def namespace_constant_name(node)
155
123
  path = node.constant_path
156
124
  case path
@@ -162,12 +130,7 @@ module RubyLsp
162
130
  # Iterates over each part of a constant path, so that we can easily push response items for each section of the
163
131
  # name. For example, for `Foo::Bar::Baz`, this method will invoke the block with `Foo`, then `Bar` and finally
164
132
  # `Baz`.
165
- sig do
166
- params(
167
- node: Prism::Node,
168
- block: T.proc.params(part: Prism::Node).void,
169
- ).void
170
- end
133
+ #: (Prism::Node node) { (Prism::Node part) -> void } -> void
171
134
  def each_constant_path_part(node, &block)
172
135
  current = T.let(node, T.nilable(Prism::Node))
173
136
 
@@ -177,7 +140,7 @@ module RubyLsp
177
140
  end
178
141
  end
179
142
 
180
- sig { params(entry: RubyIndexer::Entry).returns(T.nilable(Integer)) }
143
+ #: (RubyIndexer::Entry entry) -> Integer?
181
144
  def kind_for_entry(entry)
182
145
  case entry
183
146
  when RubyIndexer::Entry::Class
@@ -195,7 +158,7 @@ module RubyLsp
195
158
  end
196
159
  end
197
160
 
198
- sig { params(sorbet_level: RubyDocument::SorbetLevel).returns(T::Boolean) }
161
+ #: (RubyDocument::SorbetLevel sorbet_level) -> bool
199
162
  def sorbet_level_true_or_higher?(sorbet_level)
200
163
  sorbet_level == RubyDocument::SorbetLevel::True || sorbet_level == RubyDocument::SorbetLevel::Strict
201
164
  end
@@ -5,8 +5,6 @@ module RubyLsp
5
5
  module Requests
6
6
  module Support
7
7
  class RuboCopDiagnostic
8
- extend T::Sig
9
-
10
8
  RUBOCOP_TO_LSP_SEVERITY = T.let(
11
9
  {
12
10
  info: Constant::DiagnosticSeverity::HINT,
@@ -31,14 +29,14 @@ module RubyLsp
31
29
 
32
30
  # TODO: avoid passing document once we have alternative ways to get at
33
31
  # encoding and file source
34
- sig { params(document: RubyDocument, offense: ::RuboCop::Cop::Offense, uri: URI::Generic).void }
32
+ #: (RubyDocument document, ::RuboCop::Cop::Offense offense, URI::Generic uri) -> void
35
33
  def initialize(document, offense, uri)
36
34
  @document = document
37
35
  @offense = offense
38
36
  @uri = uri
39
37
  end
40
38
 
41
- sig { returns(T::Array[Interface::CodeAction]) }
39
+ #: -> Array[Interface::CodeAction]
42
40
  def to_lsp_code_actions
43
41
  code_actions = []
44
42
 
@@ -48,7 +46,7 @@ module RubyLsp
48
46
  code_actions
49
47
  end
50
48
 
51
- sig { params(config: ::RuboCop::Config).returns(Interface::Diagnostic) }
49
+ #: (::RuboCop::Config config) -> Interface::Diagnostic
52
50
  def to_lsp_diagnostic(config)
53
51
  # highlighted_area contains the begin and end position of the first line
54
52
  # This ensures that multiline offenses don't clutter the editor
@@ -78,19 +76,19 @@ module RubyLsp
78
76
 
79
77
  private
80
78
 
81
- sig { returns(String) }
79
+ #: -> String
82
80
  def message
83
81
  message = @offense.message
84
82
  message += "\n\nThis offense is not auto-correctable.\n" unless correctable?
85
83
  message
86
84
  end
87
85
 
88
- sig { returns(T.nilable(Integer)) }
86
+ #: -> Integer?
89
87
  def severity
90
88
  RUBOCOP_TO_LSP_SEVERITY[@offense.severity.name]
91
89
  end
92
90
 
93
- sig { params(config: ::RuboCop::Config).returns(T.nilable(Interface::CodeDescription)) }
91
+ #: (::RuboCop::Config config) -> Interface::CodeDescription?
94
92
  def code_description(config)
95
93
  cop = RuboCopRunner.find_cop_by_name(@offense.cop_name)
96
94
  return unless cop
@@ -103,7 +101,7 @@ module RubyLsp
103
101
  Interface::CodeDescription.new(href: doc_url) if doc_url
104
102
  end
105
103
 
106
- sig { returns(Interface::CodeAction) }
104
+ #: -> Interface::CodeAction
107
105
  def autocorrect_action
108
106
  Interface::CodeAction.new(
109
107
  title: "Autocorrect #{@offense.cop_name}",
@@ -123,7 +121,7 @@ module RubyLsp
123
121
  )
124
122
  end
125
123
 
126
- sig { returns(T::Array[Interface::TextEdit]) }
124
+ #: -> Array[Interface::TextEdit]
127
125
  def offense_replacements
128
126
  @offense.corrector.as_replacements.map do |range, replacement|
129
127
  Interface::TextEdit.new(
@@ -136,7 +134,7 @@ module RubyLsp
136
134
  end
137
135
  end
138
136
 
139
- sig { returns(Interface::CodeAction) }
137
+ #: -> Interface::CodeAction
140
138
  def disable_line_action
141
139
  Interface::CodeAction.new(
142
140
  title: "Disable #{@offense.cop_name} for this line",
@@ -155,7 +153,7 @@ module RubyLsp
155
153
  )
156
154
  end
157
155
 
158
- sig { returns(T::Array[Interface::TextEdit]) }
156
+ #: -> Array[Interface::TextEdit]
159
157
  def line_disable_comment
160
158
  new_text = if @offense.source_line.include?(" # rubocop:disable ")
161
159
  ",#{@offense.cop_name}"
@@ -178,7 +176,7 @@ module RubyLsp
178
176
  [inline_comment]
179
177
  end
180
178
 
181
- sig { params(line: String).returns(Integer) }
179
+ #: (String line) -> Integer
182
180
  def length_of_line(line)
183
181
  if @document.encoding == Encoding::UTF_16LE
184
182
  line_length = 0
@@ -197,7 +195,7 @@ module RubyLsp
197
195
  # When `RuboCop::LSP.enable` is called, contextual autocorrect will not offer itself
198
196
  # as `correctable?` to prevent annoying changes while typing. Instead check if
199
197
  # a corrector is present. If it is, then that means some code transformation can be applied.
200
- sig { returns(T::Boolean) }
198
+ #: -> bool
201
199
  def correctable?
202
200
  !@offense.corrector.nil?
203
201
  end
@@ -9,17 +9,17 @@ module RubyLsp
9
9
  module Requests
10
10
  module Support
11
11
  class RuboCopFormatter
12
- extend T::Sig
13
12
  include Formatter
14
13
 
15
- sig { void }
14
+ #: -> void
16
15
  def initialize
17
16
  @diagnostic_runner = T.let(RuboCopRunner.new, RuboCopRunner)
18
17
  # -a is for "--auto-correct" (or "--autocorrect" on newer versions of RuboCop)
19
18
  @format_runner = T.let(RuboCopRunner.new("-a"), RuboCopRunner)
20
19
  end
21
20
 
22
- sig { override.params(uri: URI::Generic, document: RubyDocument).returns(T.nilable(String)) }
21
+ # @override
22
+ #: (URI::Generic uri, RubyDocument document) -> String?
23
23
  def run_formatting(uri, document)
24
24
  filename = T.must(uri.to_standardized_path || uri.opaque)
25
25
 
@@ -29,17 +29,14 @@ module RubyLsp
29
29
  end
30
30
 
31
31
  # RuboCop does not support range formatting
32
- sig { override.params(uri: URI::Generic, source: String, base_indentation: Integer).returns(T.nilable(String)) }
32
+ # @override
33
+ #: (URI::Generic uri, String source, Integer base_indentation) -> String?
33
34
  def run_range_formatting(uri, source, base_indentation)
34
35
  nil
35
36
  end
36
37
 
37
- sig do
38
- override.params(
39
- uri: URI::Generic,
40
- document: RubyDocument,
41
- ).returns(T.nilable(T::Array[Interface::Diagnostic]))
42
- end
38
+ # @override
39
+ #: (URI::Generic uri, RubyDocument document) -> Array[Interface::Diagnostic]?
43
40
  def run_diagnostic(uri, document)
44
41
  filename = T.must(uri.to_standardized_path || uri.opaque)
45
42
  # Invoke RuboCop with just this file in `paths`
@@ -32,15 +32,13 @@ module RubyLsp
32
32
  module Requests
33
33
  module Support
34
34
  class InternalRuboCopError < StandardError
35
- extend T::Sig
36
-
37
35
  MESSAGE = <<~EOS
38
36
  An internal error occurred %s.
39
37
  Updating to a newer version of RuboCop may solve this.
40
38
  For more details, run RuboCop on the command line.
41
39
  EOS
42
40
 
43
- sig { params(rubocop_error: T.any(::RuboCop::ErrorWithAnalyzedFileLocation, StandardError)).void }
41
+ #: ((::RuboCop::ErrorWithAnalyzedFileLocation | StandardError) rubocop_error) -> void
44
42
  def initialize(rubocop_error)
45
43
  message = case rubocop_error
46
44
  when ::RuboCop::ErrorWithAnalyzedFileLocation
@@ -54,8 +52,6 @@ module RubyLsp
54
52
 
55
53
  # :nodoc:
56
54
  class RuboCopRunner < ::RuboCop::Runner
57
- extend T::Sig
58
-
59
55
  class ConfigurationError < StandardError; end
60
56
 
61
57
  DEFAULT_ARGS = T.let(
@@ -68,10 +64,10 @@ module RubyLsp
68
64
  T::Array[String],
69
65
  )
70
66
 
71
- sig { returns(T::Array[::RuboCop::Cop::Offense]) }
67
+ #: Array[::RuboCop::Cop::Offense]
72
68
  attr_reader :offenses
73
69
 
74
- sig { returns(::RuboCop::Config) }
70
+ #: ::RuboCop::Config
75
71
  attr_reader :config_for_working_directory
76
72
 
77
73
  begin
@@ -82,7 +78,7 @@ module RubyLsp
82
78
  end
83
79
  DEFAULT_ARGS.freeze
84
80
 
85
- sig { params(args: String).void }
81
+ #: (*String args) -> void
86
82
  def initialize(*args)
87
83
  @options = T.let({}, T::Hash[Symbol, T.untyped])
88
84
  @offenses = T.let([], T::Array[::RuboCop::Cop::Offense])
@@ -99,7 +95,7 @@ module RubyLsp
99
95
  super(rubocop_options, config_store)
100
96
  end
101
97
 
102
- sig { params(path: String, contents: String).void }
98
+ #: (String path, String contents) -> void
103
99
  def run(path, contents)
104
100
  # Clear Runner state between runs since we get a single instance of this class
105
101
  # on every use site.
@@ -121,22 +117,20 @@ module RubyLsp
121
117
  raise InternalRuboCopError, error
122
118
  end
123
119
 
124
- sig { returns(String) }
120
+ #: -> String
125
121
  def formatted_source
126
122
  @options[:stdin]
127
123
  end
128
124
 
129
125
  class << self
130
- extend T::Sig
131
-
132
- sig { params(cop_name: String).returns(T.nilable(T.class_of(::RuboCop::Cop::Base))) }
126
+ #: (String cop_name) -> singleton(::RuboCop::Cop::Base)?
133
127
  def find_cop_by_name(cop_name)
134
128
  cop_registry[cop_name]&.first
135
129
  end
136
130
 
137
131
  private
138
132
 
139
- sig { returns(T::Hash[String, [T.class_of(::RuboCop::Cop::Base)]]) }
133
+ #: -> Hash[String, [singleton(::RuboCop::Cop::Base)]]
140
134
  def cop_registry
141
135
  @cop_registry ||= T.let(
142
136
  ::RuboCop::Cop::Registry.global.to_h,
@@ -147,7 +141,7 @@ module RubyLsp
147
141
 
148
142
  private
149
143
 
150
- sig { params(_file: String, offenses: T::Array[::RuboCop::Cop::Offense]).void }
144
+ #: (String _file, Array[::RuboCop::Cop::Offense] offenses) -> void
151
145
  def file_finished(_file, offenses)
152
146
  @offenses = offenses
153
147
  end
@@ -5,9 +5,7 @@ module RubyLsp
5
5
  module Requests
6
6
  module Support
7
7
  class SelectionRange < Interface::SelectionRange
8
- extend T::Sig
9
-
10
- sig { params(position: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
8
+ #: (Hash[Symbol, untyped] position) -> bool
11
9
  def cover?(position)
12
10
  start_covered = range.start.line < position[:line] ||
13
11
  (range.start.line == position[:line] && range.start.character <= position[:character])
@@ -6,8 +6,6 @@ module RubyLsp
6
6
  module Support
7
7
  class Sorbet
8
8
  class << self
9
- extend T::Sig
10
-
11
9
  ANNOTATIONS = T.let(
12
10
  {
13
11
  abstract!: Annotation.new(arity: 0),
@@ -40,11 +38,7 @@ module RubyLsp
40
38
  T::Hash[Symbol, Annotation],
41
39
  )
42
40
 
43
- sig do
44
- params(
45
- node: Prism::CallNode,
46
- ).returns(T::Boolean)
47
- end
41
+ #: (Prism::CallNode node) -> bool
48
42
  def annotation?(node)
49
43
  !!ANNOTATIONS[node.name]&.match?(node)
50
44
  end
@@ -6,8 +6,6 @@ require "uri/file"
6
6
  module URI
7
7
  # Must be kept in sync with the one in Tapioca
8
8
  class Source < URI::File
9
- extend T::Sig
10
-
11
9
  COMPONENT = T.let(
12
10
  [
13
11
  :scheme,
@@ -29,20 +27,11 @@ module URI
29
27
  T.unsafe(self).alias_method(:gem_name, :host)
30
28
  T.unsafe(self).alias_method(:line_number, :fragment)
31
29
 
32
- sig { returns(T.nilable(String)) }
30
+ #: String?
33
31
  attr_reader :gem_version
34
32
 
35
33
  class << self
36
- extend T::Sig
37
-
38
- sig do
39
- params(
40
- gem_name: String,
41
- gem_version: T.nilable(String),
42
- path: String,
43
- line_number: T.nilable(String),
44
- ).returns(URI::Source)
45
- end
34
+ #: (gem_name: String, gem_version: String?, path: String, line_number: String?) -> URI::Source
46
35
  def build(gem_name:, gem_version:, path:, line_number:)
47
36
  super(
48
37
  {
@@ -55,7 +44,7 @@ module URI
55
44
  end
56
45
  end
57
46
 
58
- sig { params(v: T.nilable(String)).void }
47
+ #: (String? v) -> void
59
48
  def set_path(v) # rubocop:disable Naming/AccessorMethodName
60
49
  return if v.nil?
61
50
 
@@ -65,7 +54,7 @@ module URI
65
54
  @path = T.let(path, T.nilable(String))
66
55
  end
67
56
 
68
- sig { params(v: T.nilable(String)).returns(T::Boolean) }
57
+ #: (String? v) -> bool
69
58
  def check_host(v)
70
59
  return true unless v
71
60
 
@@ -77,7 +66,7 @@ module URI
77
66
  true
78
67
  end
79
68
 
80
- sig { returns(String) }
69
+ #: -> String
81
70
  def to_s
82
71
  "source://#{gem_name}/#{gem_version}#{path}##{line_number}"
83
72
  end
@@ -13,10 +13,9 @@ module RubyLsp
13
13
  module Support
14
14
  # :nodoc:
15
15
  class SyntaxTreeFormatter
16
- extend T::Sig
17
16
  include Support::Formatter
18
17
 
19
- sig { void }
18
+ #: -> void
20
19
  def initialize
21
20
  @options =
22
21
  T.let(
@@ -29,7 +28,8 @@ module RubyLsp
29
28
  )
30
29
  end
31
30
 
32
- sig { override.params(uri: URI::Generic, document: RubyDocument).returns(T.nilable(String)) }
31
+ # @override
32
+ #: (URI::Generic uri, RubyDocument document) -> String?
33
33
  def run_formatting(uri, document)
34
34
  path = uri.to_standardized_path
35
35
  return if path && @options.ignore_files.any? { |pattern| File.fnmatch?("*/#{pattern}", path) }
@@ -37,7 +37,8 @@ module RubyLsp
37
37
  SyntaxTree.format(document.source, @options.print_width, options: @options.formatter_options)
38
38
  end
39
39
 
40
- sig { override.params(uri: URI::Generic, source: String, base_indentation: Integer).returns(T.nilable(String)) }
40
+ # @override
41
+ #: (URI::Generic uri, String source, Integer base_indentation) -> String?
41
42
  def run_range_formatting(uri, source, base_indentation)
42
43
  path = uri.to_standardized_path
43
44
  return if path && @options.ignore_files.any? { |pattern| File.fnmatch?("*/#{pattern}", path) }
@@ -45,12 +46,8 @@ module RubyLsp
45
46
  SyntaxTree.format(source, @options.print_width, base_indentation, options: @options.formatter_options)
46
47
  end
47
48
 
48
- sig do
49
- override.params(
50
- uri: URI::Generic,
51
- document: RubyDocument,
52
- ).returns(T.nilable(T::Array[Interface::Diagnostic]))
53
- end
49
+ # @override
50
+ #: (URI::Generic uri, RubyDocument document) -> Array[Interface::Diagnostic]?
54
51
  def run_diagnostic(uri, document)
55
52
  nil
56
53
  end
@@ -10,46 +10,47 @@ module RubyLsp
10
10
  # Note: this test item object can only represent test groups or examples discovered inside files. It cannot be
11
11
  # used to represent test files, directories or workspaces
12
12
  class TestItem
13
- extend T::Sig
14
-
15
- sig { returns(String) }
13
+ #: String
16
14
  attr_reader :id, :label
17
15
 
18
- sig { params(id: String, label: String, uri: URI::Generic, range: Interface::Range).void }
19
- def initialize(id, label, uri, range)
16
+ #: (String id, String label, URI::Generic uri, Interface::Range range, Array[Symbol] tags) -> void
17
+ def initialize(id, label, uri, range, tags: [])
20
18
  @id = id
21
19
  @label = label
22
20
  @uri = uri
23
21
  @range = range
22
+ @tags = tags
24
23
  @children = T.let({}, T::Hash[String, TestItem])
25
24
  end
26
25
 
27
- sig { params(item: TestItem).void }
26
+ #: (TestItem item) -> void
28
27
  def add(item)
29
- if @children.key?(item.id)
30
- raise ResponseBuilders::TestCollection::DuplicateIdError, "TestItem ID is already in use"
31
- end
32
-
33
28
  @children[item.id] = item
34
29
  end
35
30
 
36
- sig { params(id: String).returns(T.nilable(TestItem)) }
31
+ #: (String id) -> TestItem?
37
32
  def [](id)
38
33
  @children[id]
39
34
  end
40
35
 
41
- sig { returns(T::Array[TestItem]) }
36
+ #: -> Array[TestItem]
42
37
  def children
43
38
  @children.values
44
39
  end
45
40
 
46
- sig { returns(T::Hash[Symbol, T.untyped]) }
41
+ #: (Symbol) -> bool
42
+ def tag?(tag)
43
+ @tags.include?(tag)
44
+ end
45
+
46
+ #: -> Hash[Symbol, untyped]
47
47
  def to_hash
48
48
  {
49
49
  id: @id,
50
50
  label: @label,
51
51
  uri: @uri,
52
52
  range: @range,
53
+ tags: @tags,
53
54
  children: children.map(&:to_hash),
54
55
  }
55
56
  end
@@ -7,11 +7,9 @@ module RubyLsp
7
7
  # request](https://microsoft.github.io/language-server-protocol/specification#typeHierarchy_supertypes)
8
8
  # displays the list of ancestors (supertypes) for the selected type.
9
9
  class TypeHierarchySupertypes < Request
10
- extend T::Sig
11
-
12
10
  include Support::Common
13
11
 
14
- sig { params(index: RubyIndexer::Index, item: T::Hash[Symbol, T.untyped]).void }
12
+ #: (RubyIndexer::Index index, Hash[Symbol, untyped] item) -> void
15
13
  def initialize(index, item)
16
14
  super()
17
15
 
@@ -19,7 +17,8 @@ module RubyLsp
19
17
  @item = item
20
18
  end
21
19
 
22
- sig { override.returns(T.nilable(T::Array[Interface::TypeHierarchyItem])) }
20
+ # @override
21
+ #: -> Array[Interface::TypeHierarchyItem]?
23
22
  def perform
24
23
  name = @item[:name]
25
24
  entries = @index[name]
@@ -60,7 +59,7 @@ module RubyLsp
60
59
 
61
60
  private
62
61
 
63
- sig { params(entry: RubyIndexer::Entry).returns(Interface::TypeHierarchyItem) }
62
+ #: (RubyIndexer::Entry entry) -> Interface::TypeHierarchyItem
64
63
  def hierarchy_item(entry)
65
64
  Interface::TypeHierarchyItem.new(
66
65
  name: entry.name,
@@ -7,10 +7,9 @@ module RubyLsp
7
7
  # request allows fuzzy searching declarations in the entire project. On VS Code, use CTRL/CMD + T to search for
8
8
  # symbols.
9
9
  class WorkspaceSymbol < Request
10
- extend T::Sig
11
10
  include Support::Common
12
11
 
13
- sig { params(global_state: GlobalState, query: T.nilable(String)).void }
12
+ #: (GlobalState global_state, String? query) -> void
14
13
  def initialize(global_state, query)
15
14
  super()
16
15
  @global_state = global_state
@@ -18,7 +17,8 @@ module RubyLsp
18
17
  @index = T.let(global_state.index, RubyIndexer::Index)
19
18
  end
20
19
 
21
- sig { override.returns(T::Array[Interface::WorkspaceSymbol]) }
20
+ # @override
21
+ #: -> Array[Interface::WorkspaceSymbol]
22
22
  def perform
23
23
  @index.fuzzy_search(@query).filter_map do |entry|
24
24
  uri = entry.uri
@@ -4,23 +4,23 @@
4
4
  module RubyLsp
5
5
  module ResponseBuilders
6
6
  class CollectionResponseBuilder < ResponseBuilder
7
- extend T::Sig
8
7
  extend T::Generic
9
8
 
10
9
  ResponseType = type_member { { upper: Object } }
11
10
 
12
- sig { void }
11
+ #: -> void
13
12
  def initialize
14
13
  super
15
14
  @items = T.let([], T::Array[ResponseType])
16
15
  end
17
16
 
18
- sig { params(item: ResponseType).void }
17
+ #: (ResponseType item) -> void
19
18
  def <<(item)
20
19
  @items << item
21
20
  end
22
21
 
23
- sig { override.returns(T::Array[ResponseType]) }
22
+ # @override
23
+ #: -> Array[ResponseType]
24
24
  def response
25
25
  @items
26
26
  end