Skip to content

Commit cba97f8

Browse files
authored
Update for changes to index enhancements API (#529)
* Temporarily point to branch * Update for changes to enhancements API * Update shim
1 parent a60d7e0 commit cba97f8

File tree

10 files changed

+356
-2907
lines changed

10 files changed

+356
-2907
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.26)
5-
ruby-lsp (>= 0.21.2, < 0.22.0)
5+
ruby-lsp (>= 0.22.0, < 0.23.0)
66

77
GEM
88
remote: https://rubygems.org/
@@ -214,7 +214,7 @@ GEM
214214
rubocop (~> 1.51)
215215
rubocop-sorbet (0.8.7)
216216
rubocop (>= 1)
217-
ruby-lsp (0.21.2)
217+
ruby-lsp (0.22.0)
218218
language_server-protocol (~> 3.17.0)
219219
prism (>= 1.2, < 2.0)
220220
rbs (>= 3, < 4)

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def activate(global_state, outgoing_queue)
5656
@outgoing_queue << Notification.window_log_message("Activating Ruby LSP Rails add-on v#{VERSION}")
5757

5858
register_additional_file_watchers(global_state: global_state, outgoing_queue: outgoing_queue)
59-
@global_state.index.register_enhancement(IndexingEnhancement.new(@global_state.index))
6059

6160
# Start booting the real client in a background thread. Until this completes, the client will be a NullClient
6261
@client_mutex.unlock

lib/ruby_lsp/ruby_lsp_rails/indexing_enhancement.rb

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,18 @@ class IndexingEnhancement < RubyIndexer::Enhancement
88

99
sig do
1010
override.params(
11-
owner: T.nilable(RubyIndexer::Entry::Namespace),
12-
node: Prism::CallNode,
13-
file_path: String,
14-
code_units_cache: T.any(
15-
T.proc.params(arg0: Integer).returns(Integer),
16-
Prism::CodeUnitsCache,
17-
),
11+
call_node: Prism::CallNode,
1812
).void
1913
end
20-
def on_call_node_enter(owner, node, file_path, code_units_cache)
14+
def on_call_node_enter(call_node)
15+
owner = @listener.current_owner
2116
return unless owner
2217

23-
name = node.name
24-
25-
case name
18+
case call_node.name
2619
when :extend
27-
handle_concern_extend(owner, node)
20+
handle_concern_extend(owner, call_node)
2821
when :has_one, :has_many, :belongs_to, :has_and_belongs_to_many
29-
handle_association(owner, node, file_path, code_units_cache)
22+
handle_association(owner, call_node)
3023
end
3124
end
3225

@@ -35,16 +28,11 @@ def on_call_node_enter(owner, node, file_path, code_units_cache)
3528
sig do
3629
params(
3730
owner: RubyIndexer::Entry::Namespace,
38-
node: Prism::CallNode,
39-
file_path: String,
40-
code_units_cache: T.any(
41-
T.proc.params(arg0: Integer).returns(Integer),
42-
Prism::CodeUnitsCache,
43-
),
31+
call_node: Prism::CallNode,
4432
).void
4533
end
46-
def handle_association(owner, node, file_path, code_units_cache)
47-
arguments = node.arguments&.arguments
34+
def handle_association(owner, call_node)
35+
arguments = call_node.arguments&.arguments
4836
return unless arguments
4937

5038
name_arg = arguments.first
@@ -58,41 +46,22 @@ def handle_association(owner, node, file_path, code_units_cache)
5846

5947
return unless name
6048

61-
loc = RubyIndexer::Location.from_prism_location(name_arg.location, code_units_cache)
49+
loc = name_arg.location
6250

6351
# Reader
64-
@index.add(RubyIndexer::Entry::Method.new(
65-
name,
66-
file_path,
67-
loc,
68-
loc,
69-
nil,
70-
[RubyIndexer::Entry::Signature.new([])],
71-
RubyIndexer::Entry::Visibility::PUBLIC,
72-
owner,
73-
))
52+
reader_signatures = [RubyIndexer::Entry::Signature.new([])]
53+
@listener.add_method(name, loc, reader_signatures)
7454

7555
# Writer
76-
@index.add(RubyIndexer::Entry::Method.new(
77-
"#{name}=",
78-
file_path,
79-
loc,
80-
loc,
81-
nil,
82-
[RubyIndexer::Entry::Signature.new([RubyIndexer::Entry::RequiredParameter.new(name: name.to_sym)])],
83-
RubyIndexer::Entry::Visibility::PUBLIC,
84-
owner,
85-
))
56+
writer_signatures = [
57+
RubyIndexer::Entry::Signature.new([RubyIndexer::Entry::RequiredParameter.new(name: name.to_sym)]),
58+
]
59+
@listener.add_method("#{name}=", loc, writer_signatures)
8660
end
8761

88-
sig do
89-
params(
90-
owner: RubyIndexer::Entry::Namespace,
91-
node: Prism::CallNode,
92-
).void
93-
end
94-
def handle_concern_extend(owner, node)
95-
arguments = node.arguments&.arguments
62+
sig { params(owner: RubyIndexer::Entry::Namespace, call_node: Prism::CallNode).void }
63+
def handle_concern_extend(owner, call_node)
64+
arguments = call_node.arguments&.arguments
9665
return unless arguments
9766

9867
arguments.each do |node|
@@ -101,7 +70,7 @@ def handle_concern_extend(owner, node)
10170
module_name = node.full_name
10271
next unless module_name == "ActiveSupport::Concern"
10372

104-
@index.register_included_hook(owner.name) do |index, base|
73+
@listener.register_included_hook do |index, base|
10574
class_methods_name = "#{owner.name}::ClassMethods"
10675

10776
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.21.2", "< 0.22.0")
27+
spec.add_dependency("ruby-lsp", ">= 0.22.0", "< 0.23.0")
2828
end

0 commit comments

Comments
 (0)