Skip to content

Commit 026aa4b

Browse files
committed
Update index enhancement due to ruby-lsp changes
1 parent 6f47f23 commit 026aa4b

File tree

7 files changed

+332
-203
lines changed

7 files changed

+332
-203
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ gem "tapioca", "~> 0.13", require: false, platforms: :ruby
1919
gem "psych", "~> 5.1", require: false
2020
gem "rails"
2121
gem "webmock"
22+
gem "ruby-lsp", github: "Shopify/ruby-lsp", branch: "main"
2223

2324
platforms :mingw, :x64_mingw, :mswin, :jruby do
2425
gem "tzinfo"

Gemfile.lock

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
GIT
2+
remote: https://github.com/Shopify/ruby-lsp.git
3+
revision: 0baf62000453877023764b8dcbb56fa252538789
4+
branch: main
5+
specs:
6+
ruby-lsp (0.21.0)
7+
language_server-protocol (~> 3.17.0)
8+
prism (>= 1.2, < 2.0)
9+
rbs (>= 3, < 4)
10+
sorbet-runtime (>= 0.5.10782)
11+
112
PATH
213
remote: .
314
specs:
415
ruby-lsp-rails (0.3.21)
5-
ruby-lsp (>= 0.20.0, < 0.21.0)
16+
ruby-lsp (>= 0.21.0, < 0.22.0)
617

718
GEM
819
remote: https://rubygems.org/
@@ -227,11 +238,6 @@ GEM
227238
rubocop (~> 1.51)
228239
rubocop-sorbet (0.8.3)
229240
rubocop (>= 0.90.0)
230-
ruby-lsp (0.20.0)
231-
language_server-protocol (~> 3.17.0)
232-
prism (>= 1.2, < 2.0)
233-
rbs (>= 3, < 4)
234-
sorbet-runtime (>= 0.5.10782)
235241
ruby-progressbar (1.13.0)
236242
ruby2_keywords (0.0.5)
237243
sorbet (0.5.11577)
@@ -298,6 +304,7 @@ DEPENDENCIES
298304
rubocop-rake (~> 0.6.0)
299305
rubocop-shopify (~> 2.15)
300306
rubocop-sorbet (~> 0.8)
307+
ruby-lsp!
301308
ruby-lsp-rails!
302309
sorbet-static-and-runtime
303310
sqlite3 (< 2)

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 1 addition & 1 deletion
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

lib/ruby_lsp/ruby_lsp_rails/indexing_enhancement.rb

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

44
module RubyLsp
55
module Rails
6-
class IndexingEnhancement
6+
class IndexingEnhancement < RubyIndexer::Enhancement
77
extend T::Sig
8-
include RubyIndexer::Enhancement
8+
9+
sig { params(index: RubyIndexer::Index).void }
10+
def initialize(index)
11+
super
12+
@index = index
13+
end
914

1015
sig do
1116
override.params(
12-
index: RubyIndexer::Index,
1317
owner: T.nilable(RubyIndexer::Entry::Namespace),
1418
node: Prism::CallNode,
1519
file_path: String,
@@ -19,24 +23,23 @@ class IndexingEnhancement
1923
),
2024
).void
2125
end
22-
def on_call_node(index, owner, node, file_path, code_units_cache)
26+
def on_call_node_enter(owner, node, file_path, code_units_cache)
2327
return unless owner
2428

2529
name = node.name
2630

2731
case name
2832
when :extend
29-
handle_concern_extend(index, owner, node)
33+
handle_concern_extend(owner, node)
3034
when :has_one, :has_many, :belongs_to, :has_and_belongs_to_many
31-
handle_association(index, owner, node, file_path, code_units_cache)
35+
handle_association(owner, node, file_path, code_units_cache)
3236
end
3337
end
3438

3539
private
3640

3741
sig do
3842
params(
39-
index: RubyIndexer::Index,
4043
owner: RubyIndexer::Entry::Namespace,
4144
node: Prism::CallNode,
4245
file_path: String,
@@ -46,7 +49,7 @@ def on_call_node(index, owner, node, file_path, code_units_cache)
4649
),
4750
).void
4851
end
49-
def handle_association(index, owner, node, file_path, code_units_cache)
52+
def handle_association(owner, node, file_path, code_units_cache)
5053
arguments = node.arguments&.arguments
5154
return unless arguments
5255

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

6669
# Reader
67-
index.add(RubyIndexer::Entry::Method.new(
70+
@index.add(RubyIndexer::Entry::Method.new(
6871
name,
6972
file_path,
7073
loc,
@@ -76,7 +79,7 @@ def handle_association(index, owner, node, file_path, code_units_cache)
7679
))
7780

7881
# Writer
79-
index.add(RubyIndexer::Entry::Method.new(
82+
@index.add(RubyIndexer::Entry::Method.new(
8083
"#{name}=",
8184
file_path,
8285
loc,
@@ -90,12 +93,11 @@ def handle_association(index, owner, node, file_path, code_units_cache)
9093

9194
sig do
9295
params(
93-
index: RubyIndexer::Index,
9496
owner: RubyIndexer::Entry::Namespace,
9597
node: Prism::CallNode,
9698
).void
9799
end
98-
def handle_concern_extend(index, owner, node)
100+
def handle_concern_extend(owner, node)
99101
arguments = node.arguments&.arguments
100102
return unless arguments
101103

@@ -105,7 +107,7 @@ def handle_concern_extend(index, owner, node)
105107
module_name = node.full_name
106108
next unless module_name == "ActiveSupport::Concern"
107109

108-
index.register_included_hook(owner.name) do |index, base|
110+
@index.register_included_hook(owner.name) do |index, base|
109111
class_methods_name = "#{owner.name}::ClassMethods"
110112

111113
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

0 commit comments

Comments
 (0)