Skip to content

Commit 77650f0

Browse files
authored
Update index enhancement due to ruby-lsp changes (#495)
* Update ruby-lsp dependency * Add shim for @index
1 parent b5f4791 commit 77650f0

File tree

8 files changed

+447
-368
lines changed

8 files changed

+447
-368
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PATH
22
remote: .
33
specs:
44
ruby-lsp-rails (0.3.21)
5-
ruby-lsp (>= 0.20.0, < 0.21.0)
5+
ruby-lsp (>= 0.21.0, < 0.22.0)
66

77
GEM
88
remote: https://rubygems.org/
@@ -224,7 +224,7 @@ GEM
224224
rubocop (~> 1.51)
225225
rubocop-sorbet (0.8.3)
226226
rubocop (>= 0.90.0)
227-
ruby-lsp (0.20.0)
227+
ruby-lsp (0.21.0)
228228
language_server-protocol (~> 3.17.0)
229229
prism (>= 1.2, < 2.0)
230230
rbs (>= 3, < 4)

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def activate(global_state, outgoing_queue)
5353
@outgoing_queue << Notification.window_log_message("Activating Ruby LSP Rails add-on v#{VERSION}")
5454

5555
register_additional_file_watchers(global_state: global_state, outgoing_queue: outgoing_queue)
56-
@global_state.index.register_enhancement(IndexingEnhancement.new)
56+
@global_state.index.register_enhancement(IndexingEnhancement.new(@global_state.index))
5757

5858
# Start booting the real client in a background thread. Until this completes, the client will be a NullClient
5959
@client_mutex.unlock
@@ -128,7 +128,7 @@ def workspace_did_change_watched_files(changes)
128128

129129
sig { params(global_state: GlobalState, outgoing_queue: Thread::Queue).void }
130130
def register_additional_file_watchers(global_state:, outgoing_queue:)
131-
return unless global_state.supports_watching_files
131+
return unless global_state.client_capabilities.supports_watching_files
132132

133133
outgoing_queue << Request.new(
134134
id: "ruby-lsp-rails-file-watcher",

lib/ruby_lsp/ruby_lsp_rails/indexing_enhancement.rb

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33

44
module RubyLsp
55
module Rails
6-
class IndexingEnhancement
6+
class IndexingEnhancement < RubyIndexer::Enhancement
77
extend T::Sig
8-
include RubyIndexer::Enhancement
98

109
sig do
1110
override.params(
12-
index: RubyIndexer::Index,
1311
owner: T.nilable(RubyIndexer::Entry::Namespace),
1412
node: Prism::CallNode,
1513
file_path: String,
@@ -19,24 +17,23 @@ class IndexingEnhancement
1917
),
2018
).void
2119
end
22-
def on_call_node(index, owner, node, file_path, code_units_cache)
20+
def on_call_node_enter(owner, node, file_path, code_units_cache)
2321
return unless owner
2422

2523
name = node.name
2624

2725
case name
2826
when :extend
29-
handle_concern_extend(index, owner, node)
27+
handle_concern_extend(owner, node)
3028
when :has_one, :has_many, :belongs_to, :has_and_belongs_to_many
31-
handle_association(index, owner, node, file_path, code_units_cache)
29+
handle_association(owner, node, file_path, code_units_cache)
3230
end
3331
end
3432

3533
private
3634

3735
sig do
3836
params(
39-
index: RubyIndexer::Index,
4037
owner: RubyIndexer::Entry::Namespace,
4138
node: Prism::CallNode,
4239
file_path: String,
@@ -46,7 +43,7 @@ def on_call_node(index, owner, node, file_path, code_units_cache)
4643
),
4744
).void
4845
end
49-
def handle_association(index, owner, node, file_path, code_units_cache)
46+
def handle_association(owner, node, file_path, code_units_cache)
5047
arguments = node.arguments&.arguments
5148
return unless arguments
5249

@@ -64,7 +61,7 @@ def handle_association(index, owner, node, file_path, code_units_cache)
6461
loc = RubyIndexer::Location.from_prism_location(name_arg.location, code_units_cache)
6562

6663
# Reader
67-
index.add(RubyIndexer::Entry::Method.new(
64+
@index.add(RubyIndexer::Entry::Method.new(
6865
name,
6966
file_path,
7067
loc,
@@ -76,7 +73,7 @@ def handle_association(index, owner, node, file_path, code_units_cache)
7673
))
7774

7875
# Writer
79-
index.add(RubyIndexer::Entry::Method.new(
76+
@index.add(RubyIndexer::Entry::Method.new(
8077
"#{name}=",
8178
file_path,
8279
loc,
@@ -90,12 +87,11 @@ def handle_association(index, owner, node, file_path, code_units_cache)
9087

9188
sig do
9289
params(
93-
index: RubyIndexer::Index,
9490
owner: RubyIndexer::Entry::Namespace,
9591
node: Prism::CallNode,
9692
).void
9793
end
98-
def handle_concern_extend(index, owner, node)
94+
def handle_concern_extend(owner, node)
9995
arguments = node.arguments&.arguments
10096
return unless arguments
10197

@@ -105,7 +101,7 @@ def handle_concern_extend(index, owner, node)
105101
module_name = node.full_name
106102
next unless module_name == "ActiveSupport::Concern"
107103

108-
index.register_included_hook(owner.name) do |index, base|
104+
@index.register_included_hook(owner.name) do |index, base|
109105
class_methods_name = "#{owner.name}::ClassMethods"
110106

111107
if index.indexed?(class_methods_name)

ruby-lsp-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
2424
Dir["lib/**/*", "LICENSE.txt", "Rakefile", "README.md"]
2525
end
2626

27-
spec.add_dependency("ruby-lsp", ">= 0.20.0", "< 0.21.0")
27+
spec.add_dependency("ruby-lsp", ">= 0.21.0", "< 0.22.0")
2828
end

sorbet/rbi/gems/[email protected]

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)