Skip to content

Commit 5b0ef46

Browse files
committed
Migrate abstract methods to RBS syntax
1 parent 23a7084 commit 5b0ef46

File tree

14 files changed

+52
-103
lines changed

14 files changed

+52
-103
lines changed

lib/ruby_indexer/lib/ruby_indexer/enhancement.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
# frozen_string_literal: true
33

44
module RubyIndexer
5+
# @abstract
56
class Enhancement
6-
extend T::Helpers
7-
8-
abstract!
9-
107
@enhancements = [] #: Array[Class[Enhancement]]
118

129
class << self

lib/ruby_indexer/lib/ruby_indexer/entry.rb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,8 @@ def comments
9898
end
9999
end
100100

101+
# @abstract
101102
class ModuleOperation
102-
extend T::Helpers
103-
104-
abstract!
105-
106103
#: String
107104
attr_reader :module_name
108105

@@ -115,11 +112,8 @@ def initialize(module_name)
115112
class Include < ModuleOperation; end
116113
class Prepend < ModuleOperation; end
117114

115+
# @abstract
118116
class Namespace < Entry
119-
extend T::Helpers
120-
121-
abstract!
122-
123117
#: Array[String]
124118
attr_reader :nesting
125119

@@ -191,11 +185,8 @@ def update_singleton_information(location, name_location, comments)
191185
class Constant < Entry
192186
end
193187

188+
# @abstract
194189
class Parameter
195-
extend T::Helpers
196-
197-
abstract!
198-
199190
# Name includes just the name of the parameter, excluding symbols like splats
200191
#: Symbol
201192
attr_reader :name
@@ -289,12 +280,8 @@ def initialize
289280
end
290281
end
291282

283+
# @abstract
292284
class Member < Entry
293-
extend T::Sig
294-
extend T::Helpers
295-
296-
abstract!
297-
298285
#: Entry::Namespace?
299286
attr_reader :owner
300287

@@ -305,7 +292,8 @@ def initialize(name, uri, location, comments, visibility, owner) # rubocop:disab
305292
@owner = owner
306293
end
307294

308-
sig { abstract.returns(T::Array[Entry::Signature]) }
295+
# @abstract
296+
#: -> Array[Signature]
309297
def signatures; end
310298

311299
#: -> String

lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33

44
module RubyIndexer
55
class ReferenceFinder
6-
class Target
7-
extend T::Helpers
8-
9-
abstract!
10-
end
6+
# @abstract
7+
class Target; end
118

129
class ConstTarget < Target
1310
#: String

lib/ruby_lsp/addon.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@ module RubyLsp
1919
# end
2020
# end
2121
# ```
22+
# @abstract
2223
class Addon
23-
extend T::Sig
24-
extend T::Helpers
25-
26-
abstract!
27-
2824
@addons = [] #: Array[Addon]
2925
@addon_classes = [] #: Array[singleton(Addon)]
3026
# Add-on instances that have declared a handler to accept file watcher events
@@ -178,21 +174,25 @@ def errors_details
178174

179175
# Each add-on should implement `MyAddon#activate` and use to perform any sort of initialization, such as
180176
# reading information into memory or even spawning a separate process
181-
sig { abstract.params(global_state: GlobalState, outgoing_queue: Thread::Queue).void }
177+
# @abstract
178+
#: (GlobalState, Thread::Queue) -> void
182179
def activate(global_state, outgoing_queue); end
183180

184181
# Each add-on should implement `MyAddon#deactivate` and use to perform any clean up, like shutting down a
185182
# child process
186-
sig { abstract.void }
183+
# @abstract
184+
#: -> void
187185
def deactivate; end
188186

189187
# Add-ons should override the `name` method to return the add-on name
190-
sig { abstract.returns(String) }
188+
# @abstract
189+
#: -> String
191190
def name; end
192191

193192
# Add-ons should override the `version` method to return a semantic version string representing the add-on's
194193
# version. This is used for compatibility checks
195-
sig { abstract.returns(String) }
194+
# @abstract
195+
#: -> String
196196
def version; end
197197

198198
# Handle a response from a window/showMessageRequest request. Add-ons must include the addon_name as part of the

lib/ruby_lsp/base_server.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
# frozen_string_literal: true
33

44
module RubyLsp
5+
# @abstract
56
class BaseServer
6-
extend T::Sig
7-
extend T::Helpers
8-
9-
abstract!
10-
117
#: (**untyped options) -> void
128
def initialize(**options)
139
@test_mode = options[:test_mode] #: bool?
@@ -130,10 +126,12 @@ def push_message(message)
130126
@incoming_queue << message
131127
end
132128

133-
sig { abstract.params(message: T::Hash[Symbol, T.untyped]).void }
129+
# @abstract
130+
#: (Hash[Symbol, untyped] message) -> void
134131
def process_message(message); end
135132

136-
sig { abstract.void }
133+
# @abstract
134+
#: -> void
137135
def shutdown; end
138136

139137
#: (Integer id, String message, ?type: Integer) -> void

lib/ruby_lsp/document.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
# frozen_string_literal: true
33

44
module RubyLsp
5+
# @abstract
56
#: [ParseResultType]
67
class Document
7-
extend T::Sig
8-
extend T::Helpers
98
extend T::Generic
109

1110
class LocationNotFoundError < StandardError; end
@@ -63,7 +62,8 @@ def ==(other)
6362
self.class == other.class && uri == other.uri && @source == other.source
6463
end
6564

66-
sig { abstract.returns(Symbol) }
65+
# @abstract
66+
#: -> Symbol
6767
def language_id; end
6868

6969
#: [T] (String request_name) { (Document[ParseResultType] document) -> T } -> T
@@ -122,10 +122,12 @@ def push_edits(edits, version:)
122122
end
123123

124124
# Returns `true` if the document was parsed and `false` if nothing needed parsing
125-
sig { abstract.returns(T::Boolean) }
125+
# @abstract
126+
#: -> bool
126127
def parse!; end
127128

128-
sig { abstract.returns(T::Boolean) }
129+
# @abstract
130+
#: -> bool
129131
def syntax_error?; end
130132

131133
#: -> bool
@@ -150,12 +152,8 @@ def create_scanner
150152
Scanner.new(@source, @encoding)
151153
end
152154

155+
# @abstract
153156
class Edit
154-
extend T::Sig
155-
extend T::Helpers
156-
157-
abstract!
158-
159157
#: Hash[Symbol, untyped]
160158
attr_reader :range
161159

lib/ruby_lsp/listeners/test_discovery.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33

44
module RubyLsp
55
module Listeners
6+
# @abstract
67
class TestDiscovery
7-
extend T::Helpers
8-
abstract!
9-
108
include Requests::Support::Common
119

1210
DYNAMIC_REFERENCE_MARKER = "<dynamic_reference>"

lib/ruby_lsp/requests/request.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33

44
module RubyLsp
55
module Requests
6+
# @abstract
67
class Request
7-
extend T::Helpers
8-
extend T::Sig
9-
108
class InvalidFormatter < StandardError; end
119

12-
abstract!
13-
14-
sig { abstract.returns(T.anything) }
10+
# @abstract
11+
#: -> untyped
1512
def perform; end
1613

1714
private

lib/ruby_lsp/requests/support/common.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
module RubyLsp
55
module Requests
66
module Support
7+
# @requires_ancestor: Kernel
78
module Common
89
# WARNING: Methods in this class may be used by Ruby LSP add-ons such as
910
# https://github.com/Shopify/ruby-lsp-rails, or add-ons by created by developers outside of Shopify, so be
1011
# cautious of changing anything.
11-
extend T::Helpers
12-
13-
requires_ancestor { Kernel }
1412

1513
#: (Prism::Node node) -> Interface::Range
1614
def range_from_node(node)

lib/ruby_lsp/requests/support/formatter.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,19 @@
44
module RubyLsp
55
module Requests
66
module Support
7+
# Empty module to avoid the runtime component. This is an interface defined in sorbet/rbi/shims/ruby_lsp.rbi
8+
# @interface
79
module Formatter
8-
extend T::Sig
9-
extend T::Helpers
10-
11-
interface!
12-
13-
sig { abstract.params(uri: URI::Generic, document: RubyDocument).returns(T.nilable(String)) }
10+
# @abstract
11+
#: (URI::Generic, RubyLsp::RubyDocument) -> String?
1412
def run_formatting(uri, document); end
1513

16-
sig { abstract.params(uri: URI::Generic, source: String, base_indentation: Integer).returns(T.nilable(String)) }
14+
# @abstract
15+
#: (URI::Generic, String, Integer) -> String?
1716
def run_range_formatting(uri, source, base_indentation); end
1817

19-
sig do
20-
abstract.params(
21-
uri: URI::Generic,
22-
document: RubyDocument,
23-
).returns(T.nilable(T::Array[Interface::Diagnostic]))
24-
end
18+
# @abstract
19+
#: (URI::Generic, RubyLsp::RubyDocument) -> Array[Interface::Diagnostic]?
2520
def run_diagnostic(uri, document); end
2621
end
2722
end

0 commit comments

Comments
 (0)