Skip to content

Commit e59a1ee

Browse files
committed
Add concern indexing augmentation
1 parent 8e5951d commit e59a1ee

File tree

7 files changed

+972
-460
lines changed

7 files changed

+972
-460
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ gem "tapioca", "~> 0.13", require: false, platforms: :ruby
2020
gem "psych", "~> 5.1", require: false
2121
gem "rails"
2222
gem "webmock"
23+
gem "ruby-lsp", github: "Shopify/ruby-lsp", branch: "vs-indexing-augmentations"
2324

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

Gemfile.lock

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ GIT
66
rdoc (6.6.3.1)
77
psych (>= 4.0.0)
88

9+
GIT
10+
remote: https://github.com/Shopify/ruby-lsp.git
11+
revision: c83da98b4a7286c74f976309a84293b05817affc
12+
branch: vs-indexing-augmentations
13+
specs:
14+
ruby-lsp (0.17.10)
15+
language_server-protocol (~> 3.17.0)
16+
prism (>= 0.29.0, < 0.31)
17+
rbs (>= 3, < 4)
18+
sorbet-runtime (>= 0.5.10782)
19+
920
PATH
1021
remote: .
1122
specs:
@@ -146,8 +157,6 @@ GEM
146157
nio4r (2.7.3)
147158
nokogiri (1.16.5-arm64-darwin)
148159
racc (~> 1.4)
149-
nokogiri (1.16.5-x64-mingw-ucrt)
150-
racc (~> 1.4)
151160
nokogiri (1.16.5-x86_64-darwin)
152161
racc (~> 1.4)
153162
nokogiri (1.16.5-x86_64-linux)
@@ -234,11 +243,6 @@ GEM
234243
rubocop (~> 1.51)
235244
rubocop-sorbet (0.8.3)
236245
rubocop (>= 0.90.0)
237-
ruby-lsp (0.17.9)
238-
language_server-protocol (~> 3.17.0)
239-
prism (>= 0.29.0, < 0.31)
240-
rbs (>= 3, < 4)
241-
sorbet-runtime (>= 0.5.10782)
242246
ruby-progressbar (1.13.0)
243247
ruby2_keywords (0.0.5)
244248
sorbet (0.5.11406)
@@ -255,7 +259,6 @@ GEM
255259
sorbet-static-and-runtime (>= 0.5.10187)
256260
thor (>= 0.19.2)
257261
sqlite3 (1.7.3-arm64-darwin)
258-
sqlite3 (1.7.3-x64-mingw-ucrt)
259262
sqlite3 (1.7.3-x86_64-darwin)
260263
sqlite3 (1.7.3-x86_64-linux)
261264
stringio (3.1.0)
@@ -273,8 +276,6 @@ GEM
273276
timeout (0.4.1)
274277
tzinfo (2.0.6)
275278
concurrent-ruby (~> 1.0)
276-
tzinfo-data (1.2024.1)
277-
tzinfo (>= 1.0.0)
278279
unicode-display_width (2.5.0)
279280
webmock (3.23.1)
280281
addressable (>= 2.8.0)
@@ -292,7 +293,6 @@ GEM
292293

293294
PLATFORMS
294295
arm64-darwin
295-
x64-mingw-ucrt
296296
x86_64-darwin
297297
x86_64-linux
298298

@@ -307,6 +307,7 @@ DEPENDENCIES
307307
rubocop-rake (~> 0.6.0)
308308
rubocop-shopify (~> 2.15)
309309
rubocop-sorbet (~> 0.8)
310+
ruby-lsp!
310311
ruby-lsp-rails!
311312
sorbet-static-and-runtime
312313
sqlite3 (< 2)

lib/ruby_lsp/ruby_lsp_rails/addon.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
require_relative "code_lens"
1414
require_relative "document_symbol"
1515
require_relative "definition"
16+
require_relative "indexing_augmentation"
1617

1718
module RubyLsp
1819
module Rails
@@ -35,6 +36,8 @@ def activate(global_state, message_queue)
3536
# Start booting the real client in a background thread. Until this completes, the client will be a NullClient
3637
Thread.new { @client = RunnerClient.create_client }
3738
register_additional_file_watchers(global_state: global_state, message_queue: message_queue)
39+
40+
T.must(@global_state).index.register_augmentation(IndexingAugmentation.new)
3841
end
3942

4043
sig { override.void }
@@ -77,7 +80,10 @@ def create_document_symbol_listener(response_builder, dispatcher)
7780

7881
sig do
7982
override.params(
80-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::Location],
83+
response_builder: ResponseBuilders::CollectionResponseBuilder[T.any(
84+
Interface::Location,
85+
Interface::LocationLink,
86+
)],
8187
uri: URI::Generic,
8288
node_context: NodeContext,
8389
dispatcher: Prism::Dispatcher,

lib/ruby_lsp/ruby_lsp_rails/definition.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class Definition
3434
sig do
3535
params(
3636
client: RunnerClient,
37-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::Location],
37+
response_builder: ResponseBuilders::CollectionResponseBuilder[T.any(
38+
Interface::Location,
39+
Interface::LocationLink,
40+
)],
3841
node_context: NodeContext,
3942
index: RubyIndexer::Index,
4043
dispatcher: Prism::Dispatcher,
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module RubyLsp
5+
module Rails
6+
class IndexingAugmentation
7+
extend T::Sig
8+
include RubyIndexer::Augmentation
9+
10+
sig do
11+
override.params(
12+
index: RubyIndexer::Index,
13+
owner: T.nilable(RubyIndexer::Entry::Namespace),
14+
node: Prism::CallNode,
15+
file_path: String,
16+
).void
17+
end
18+
def on_call_node(index, owner, node, file_path)
19+
return unless owner
20+
21+
name = node.name
22+
23+
case name
24+
when :extend
25+
handle_concern_extend(index, owner, node)
26+
end
27+
end
28+
29+
private
30+
31+
sig do
32+
params(
33+
index: RubyIndexer::Index,
34+
owner: RubyIndexer::Entry::Namespace,
35+
node: Prism::CallNode,
36+
).void
37+
end
38+
def handle_concern_extend(index, owner, node)
39+
arguments = node.arguments&.arguments
40+
return unless arguments
41+
42+
arguments.each do |node|
43+
next unless node.is_a?(Prism::ConstantReadNode) || node.is_a?(Prism::ConstantPathNode)
44+
45+
module_name = node.full_name
46+
next unless module_name == "ActiveSupport::Concern"
47+
48+
index.register_included_hook(owner.name) do |index, base|
49+
class_methods_name = "#{owner.name}::ClassMethods"
50+
51+
if index.indexed?(class_methods_name)
52+
singleton = index.existing_or_new_singleton_class(base.name)
53+
singleton.mixin_operations << RubyIndexer::Entry::Include.new(class_methods_name)
54+
end
55+
end
56+
rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError,
57+
Prism::ConstantPathNode::MissingNodesInConstantPathError
58+
# Do nothing
59+
end
60+
end
61+
end
62+
end
63+
end

0 commit comments

Comments
 (0)