ruby-lsp-rails 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/ruby_lsp/ruby_lsp_rails/addon.rb +59 -68
- data/lib/ruby_lsp/ruby_lsp_rails/code_lens.rb +23 -30
- data/lib/ruby_lsp/ruby_lsp_rails/completion.rb +7 -15
- data/lib/ruby_lsp/ruby_lsp_rails/definition.rb +13 -22
- data/lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb +24 -30
- data/lib/ruby_lsp/ruby_lsp_rails/hover.rb +41 -29
- data/lib/ruby_lsp/ruby_lsp_rails/indexing_enhancement.rb +7 -20
- data/lib/ruby_lsp/ruby_lsp_rails/rails_test_style.rb +150 -0
- data/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb +64 -79
- data/lib/ruby_lsp/ruby_lsp_rails/server.rb +117 -31
- data/lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb +3 -4
- data/lib/ruby_lsp/ruby_lsp_rails/support/associations.rb +6 -9
- data/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb +48 -57
- data/lib/ruby_lsp/ruby_lsp_rails/support/location_builder.rb +1 -3
- data/lib/ruby_lsp_rails/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76155fcaf046652d4e13655bf8f1d38764a0a755cd4e090a70a7e551e77dc598
|
4
|
+
data.tar.gz: d417e7a57d97dbd0a7b1b2aa2ec999793ef6a8fb3ada39a0c1ad06688af8fd3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f53d2aebe48cb0ce755541d4af87e564d2ca5dcdd70f411390c4d685890f6d398da400f223a77678c56e915b6a34ea6330b4495a02f407967040c07d9a5a164
|
7
|
+
data.tar.gz: 063117bc235a4bf99f148d65c8170601a35b58b7d95ad8098114ccd213c930f0d9a8ea12f51b12022c7ad6284672209ae0eafbd475f079c325ff8bc236c08688
|
data/Rakefile
CHANGED
@@ -13,52 +13,53 @@ require_relative "hover"
|
|
13
13
|
require_relative "code_lens"
|
14
14
|
require_relative "document_symbol"
|
15
15
|
require_relative "definition"
|
16
|
+
require_relative "rails_test_style"
|
16
17
|
require_relative "completion"
|
17
18
|
require_relative "indexing_enhancement"
|
18
19
|
|
19
20
|
module RubyLsp
|
20
21
|
module Rails
|
21
22
|
class Addon < ::RubyLsp::Addon
|
22
|
-
extend T::Sig
|
23
|
-
|
24
23
|
RUN_MIGRATIONS_TITLE = "Run Migrations"
|
25
24
|
|
26
|
-
|
25
|
+
#: -> void
|
27
26
|
def initialize
|
28
27
|
super
|
29
28
|
|
30
29
|
# We first initialize the client as a NullClient, so that we can start the server in a background thread. Until
|
31
30
|
# the real client is initialized, features that depend on it will not be blocked by using the NullClient
|
32
|
-
@rails_runner_client =
|
33
|
-
@global_state =
|
34
|
-
@outgoing_queue =
|
35
|
-
@settings =
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@addon_mutex = T.let(Mutex.new, Mutex)
|
42
|
-
@client_mutex = T.let(Mutex.new, Mutex)
|
31
|
+
@rails_runner_client = NullClient.new #: RunnerClient
|
32
|
+
@global_state = nil #: GlobalState?
|
33
|
+
@outgoing_queue = nil #: Thread::Queue?
|
34
|
+
@settings = {
|
35
|
+
enablePendingMigrationsPrompt: true,
|
36
|
+
} #: Hash[Symbol, untyped],
|
37
|
+
|
38
|
+
@addon_mutex = Mutex.new #: Mutex
|
39
|
+
@client_mutex = Mutex.new #: Mutex
|
43
40
|
@client_mutex.lock
|
44
41
|
|
45
42
|
Thread.new do
|
46
43
|
@addon_mutex.synchronize do
|
47
44
|
# We need to ensure the Rails client is fully loaded before we activate the server addons
|
48
45
|
@client_mutex.synchronize do
|
49
|
-
@rails_runner_client = RunnerClient.create_client(
|
46
|
+
@rails_runner_client = RunnerClient.create_client(
|
47
|
+
@outgoing_queue, #: as !nil
|
48
|
+
@global_state, #: as !nil
|
49
|
+
)
|
50
50
|
end
|
51
51
|
offer_to_run_pending_migrations
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
#: -> RunnerClient
|
57
57
|
def rails_runner_client
|
58
58
|
@addon_mutex.synchronize { @rails_runner_client }
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
# @override
|
62
|
+
#: (GlobalState global_state, Thread::Queue outgoing_queue) -> void
|
62
63
|
def activate(global_state, outgoing_queue)
|
63
64
|
@global_state = global_state
|
64
65
|
@outgoing_queue = outgoing_queue
|
@@ -73,82 +74,70 @@ module RubyLsp
|
|
73
74
|
@client_mutex.unlock
|
74
75
|
end
|
75
76
|
|
76
|
-
|
77
|
+
# @override
|
78
|
+
#: -> void
|
77
79
|
def deactivate
|
78
80
|
@rails_runner_client.shutdown
|
79
81
|
end
|
80
82
|
|
81
|
-
|
83
|
+
# @override
|
84
|
+
#: -> String
|
82
85
|
def version
|
83
86
|
VERSION
|
84
87
|
end
|
85
88
|
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
).void
|
89
|
+
# @override
|
90
|
+
#: (ResponseBuilders::TestCollection response_builder, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
|
91
|
+
def create_discover_tests_listener(response_builder, dispatcher, uri)
|
92
|
+
return unless @global_state
|
93
|
+
|
94
|
+
RailsTestStyle.new(@rails_runner_client, response_builder, @global_state, dispatcher, uri)
|
93
95
|
end
|
96
|
+
|
97
|
+
# @override
|
98
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[String]
|
99
|
+
def resolve_test_commands(items)
|
100
|
+
RailsTestStyle.resolve_test_commands(items)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Creates a new CodeLens listener. This method is invoked on every CodeLens request
|
104
|
+
# @override
|
105
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
94
106
|
def create_code_lens_listener(response_builder, uri, dispatcher)
|
95
107
|
return unless @global_state
|
96
108
|
|
97
109
|
CodeLens.new(@rails_runner_client, @global_state, response_builder, uri, dispatcher)
|
98
110
|
end
|
99
111
|
|
100
|
-
|
101
|
-
|
102
|
-
response_builder: ResponseBuilders::Hover,
|
103
|
-
node_context: NodeContext,
|
104
|
-
dispatcher: Prism::Dispatcher,
|
105
|
-
).void
|
106
|
-
end
|
112
|
+
# @override
|
113
|
+
#: (ResponseBuilders::Hover response_builder, NodeContext node_context, Prism::Dispatcher dispatcher) -> void
|
107
114
|
def create_hover_listener(response_builder, node_context, dispatcher)
|
108
115
|
return unless @global_state
|
109
116
|
|
110
117
|
Hover.new(@rails_runner_client, response_builder, node_context, @global_state, dispatcher)
|
111
118
|
end
|
112
119
|
|
113
|
-
|
114
|
-
|
115
|
-
response_builder: ResponseBuilders::DocumentSymbol,
|
116
|
-
dispatcher: Prism::Dispatcher,
|
117
|
-
).returns(Object)
|
118
|
-
end
|
120
|
+
# @override
|
121
|
+
#: (ResponseBuilders::DocumentSymbol response_builder, Prism::Dispatcher dispatcher) -> Object
|
119
122
|
def create_document_symbol_listener(response_builder, dispatcher)
|
120
123
|
DocumentSymbol.new(response_builder, dispatcher)
|
121
124
|
end
|
122
125
|
|
123
|
-
|
124
|
-
|
125
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[T.any(
|
126
|
-
Interface::Location, Interface::LocationLink
|
127
|
-
)],
|
128
|
-
uri: URI::Generic,
|
129
|
-
node_context: NodeContext,
|
130
|
-
dispatcher: Prism::Dispatcher,
|
131
|
-
).void
|
132
|
-
end
|
126
|
+
# @override
|
127
|
+
#: (ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)] response_builder, URI::Generic uri, NodeContext node_context, Prism::Dispatcher dispatcher) -> void
|
133
128
|
def create_definition_listener(response_builder, uri, node_context, dispatcher)
|
134
129
|
return unless @global_state
|
135
130
|
|
136
131
|
Definition.new(@rails_runner_client, response_builder, node_context, @global_state.index, dispatcher)
|
137
132
|
end
|
138
133
|
|
139
|
-
|
140
|
-
|
141
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem],
|
142
|
-
node_context: NodeContext,
|
143
|
-
dispatcher: Prism::Dispatcher,
|
144
|
-
uri: URI::Generic,
|
145
|
-
).void
|
146
|
-
end
|
134
|
+
# @override
|
135
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem] response_builder, NodeContext node_context, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
|
147
136
|
def create_completion_listener(response_builder, node_context, dispatcher, uri)
|
148
137
|
Completion.new(@rails_runner_client, response_builder, node_context, dispatcher, uri)
|
149
138
|
end
|
150
139
|
|
151
|
-
|
140
|
+
#: (Array[{uri: String, type: Integer}] changes) -> void
|
152
141
|
def workspace_did_change_watched_files(changes)
|
153
142
|
if changes.any? { |c| c[:uri].end_with?("db/schema.rb") || c[:uri].end_with?("structure.sql") }
|
154
143
|
@rails_runner_client.trigger_reload
|
@@ -162,12 +151,14 @@ module RubyLsp
|
|
162
151
|
end
|
163
152
|
end
|
164
153
|
|
165
|
-
|
154
|
+
# @override
|
155
|
+
#: -> String
|
166
156
|
def name
|
167
157
|
"Ruby LSP Rails"
|
168
158
|
end
|
169
159
|
|
170
|
-
|
160
|
+
# @override
|
161
|
+
#: (String title) -> void
|
171
162
|
def handle_window_show_message_response(title)
|
172
163
|
if title == RUN_MIGRATIONS_TITLE
|
173
164
|
|
@@ -194,7 +185,7 @@ module RubyLsp
|
|
194
185
|
|
195
186
|
private
|
196
187
|
|
197
|
-
|
188
|
+
#: (String id, String title, ?percentage: Integer?, ?message: String?) -> void
|
198
189
|
def begin_progress(id, title, percentage: nil, message: nil)
|
199
190
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
200
191
|
|
@@ -212,21 +203,21 @@ module RubyLsp
|
|
212
203
|
)
|
213
204
|
end
|
214
205
|
|
215
|
-
|
216
|
-
def report_progress(id,
|
206
|
+
#: (String id, ?percentage: Integer?, ?message: String?) -> void
|
207
|
+
def report_progress(id, percentage: nil, message: nil)
|
217
208
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
218
209
|
|
219
210
|
@outgoing_queue << Notification.progress_report(id, percentage: percentage, message: message)
|
220
211
|
end
|
221
212
|
|
222
|
-
|
213
|
+
#: (String id) -> void
|
223
214
|
def end_progress(id)
|
224
215
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
225
216
|
|
226
217
|
@outgoing_queue << Notification.progress_end(id)
|
227
218
|
end
|
228
219
|
|
229
|
-
|
220
|
+
#: (global_state: GlobalState, outgoing_queue: Thread::Queue) -> void
|
230
221
|
def register_additional_file_watchers(global_state:, outgoing_queue:)
|
231
222
|
return unless global_state.client_capabilities.supports_watching_files
|
232
223
|
|
@@ -247,7 +238,7 @@ module RubyLsp
|
|
247
238
|
)
|
248
239
|
end
|
249
240
|
|
250
|
-
|
241
|
+
#: -> Interface::FileSystemWatcher
|
251
242
|
def structure_sql_file_watcher
|
252
243
|
Interface::FileSystemWatcher.new(
|
253
244
|
glob_pattern: "**/*structure.sql",
|
@@ -255,7 +246,7 @@ module RubyLsp
|
|
255
246
|
)
|
256
247
|
end
|
257
248
|
|
258
|
-
|
249
|
+
#: -> Interface::FileSystemWatcher
|
259
250
|
def fixture_file_watcher
|
260
251
|
Interface::FileSystemWatcher.new(
|
261
252
|
glob_pattern: "**/fixtures/**/*.{yml,yaml,yml.erb,yaml.erb}",
|
@@ -263,7 +254,7 @@ module RubyLsp
|
|
263
254
|
)
|
264
255
|
end
|
265
256
|
|
266
|
-
|
257
|
+
#: -> void
|
267
258
|
def offer_to_run_pending_migrations
|
268
259
|
return unless @outgoing_queue
|
269
260
|
return unless @global_state&.client_capabilities&.window_show_message_supports_extra_properties
|
@@ -72,27 +72,18 @@ module RubyLsp
|
|
72
72
|
# Note: Complex routing configurations may not be supported.
|
73
73
|
#
|
74
74
|
class CodeLens
|
75
|
-
extend T::Sig
|
76
75
|
include Requests::Support::Common
|
77
76
|
include ActiveSupportTestCaseHelper
|
78
77
|
|
79
|
-
|
80
|
-
params(
|
81
|
-
client: RunnerClient,
|
82
|
-
global_state: GlobalState,
|
83
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens],
|
84
|
-
uri: URI::Generic,
|
85
|
-
dispatcher: Prism::Dispatcher,
|
86
|
-
).void
|
87
|
-
end
|
78
|
+
#: (RunnerClient client, GlobalState global_state, ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
88
79
|
def initialize(client, global_state, response_builder, uri, dispatcher)
|
89
80
|
@client = client
|
90
81
|
@global_state = global_state
|
91
82
|
@response_builder = response_builder
|
92
|
-
@path =
|
93
|
-
@group_id =
|
94
|
-
@group_id_stack =
|
95
|
-
@constant_name_stack =
|
83
|
+
@path = uri.to_standardized_path #: String?
|
84
|
+
@group_id = 1 #: Integer
|
85
|
+
@group_id_stack = [] #: Array[Integer]
|
86
|
+
@constant_name_stack = [] #: Array[[String, String?]]
|
96
87
|
|
97
88
|
dispatcher.register(
|
98
89
|
self,
|
@@ -105,7 +96,7 @@ module RubyLsp
|
|
105
96
|
)
|
106
97
|
end
|
107
98
|
|
108
|
-
|
99
|
+
#: (Prism::CallNode node) -> void
|
109
100
|
def on_call_node_enter(node)
|
110
101
|
content = extract_test_case_name(node)
|
111
102
|
|
@@ -117,7 +108,7 @@ module RubyLsp
|
|
117
108
|
end
|
118
109
|
|
119
110
|
# Although uncommon, Rails tests can be written with the classic "def test_name" syntax.
|
120
|
-
|
111
|
+
#: (Prism::DefNode node) -> void
|
121
112
|
def on_def_node_enter(node)
|
122
113
|
method_name = node.name.to_s
|
123
114
|
|
@@ -133,7 +124,7 @@ module RubyLsp
|
|
133
124
|
end
|
134
125
|
end
|
135
126
|
|
136
|
-
|
127
|
+
#: (Prism::ClassNode node) -> void
|
137
128
|
def on_class_node_enter(node)
|
138
129
|
class_name = node.constant_path.slice
|
139
130
|
superclass_name = node.superclass&.slice
|
@@ -157,7 +148,7 @@ module RubyLsp
|
|
157
148
|
end
|
158
149
|
end
|
159
150
|
|
160
|
-
|
151
|
+
#: (Prism::ClassNode node) -> void
|
161
152
|
def on_class_node_leave(node)
|
162
153
|
class_name = node.constant_path.slice
|
163
154
|
|
@@ -168,19 +159,19 @@ module RubyLsp
|
|
168
159
|
@constant_name_stack.pop
|
169
160
|
end
|
170
161
|
|
171
|
-
|
162
|
+
#: (Prism::ModuleNode node) -> void
|
172
163
|
def on_module_node_enter(node)
|
173
164
|
@constant_name_stack << [node.constant_path.slice, nil]
|
174
165
|
end
|
175
166
|
|
176
|
-
|
167
|
+
#: (Prism::ModuleNode node) -> void
|
177
168
|
def on_module_node_leave(node)
|
178
169
|
@constant_name_stack.pop
|
179
170
|
end
|
180
171
|
|
181
172
|
private
|
182
173
|
|
183
|
-
|
174
|
+
#: -> bool?
|
184
175
|
def controller?
|
185
176
|
class_name, superclass_name = @constant_name_stack.last
|
186
177
|
return false unless class_name && superclass_name
|
@@ -188,7 +179,7 @@ module RubyLsp
|
|
188
179
|
class_name.end_with?("Controller") && superclass_name.end_with?("Controller")
|
189
180
|
end
|
190
181
|
|
191
|
-
|
182
|
+
#: (Prism::DefNode node) -> void
|
192
183
|
def add_jump_to_view(node)
|
193
184
|
class_name = @constant_name_stack.map(&:first).join("::")
|
194
185
|
action_name = node.name
|
@@ -216,9 +207,9 @@ module RubyLsp
|
|
216
207
|
)
|
217
208
|
end
|
218
209
|
|
219
|
-
|
210
|
+
#: (Prism::DefNode node) -> void
|
220
211
|
def add_route_code_lens_to_action(node)
|
221
|
-
class_name, _ =
|
212
|
+
class_name, _ = @constant_name_stack.last #: as !nil
|
222
213
|
route = @client.route(controller: class_name, action: node.name.to_s)
|
223
214
|
return unless route
|
224
215
|
|
@@ -233,22 +224,24 @@ module RubyLsp
|
|
233
224
|
)
|
234
225
|
end
|
235
226
|
|
236
|
-
|
227
|
+
#: -> String
|
237
228
|
def test_command
|
238
229
|
"#{RbConfig.ruby} bin/rails test"
|
239
230
|
end
|
240
231
|
|
241
|
-
|
232
|
+
#: -> String
|
242
233
|
def migrate_command
|
243
234
|
"#{RbConfig.ruby} bin/rails db:migrate"
|
244
235
|
end
|
245
236
|
|
246
|
-
|
237
|
+
#: -> String?
|
247
238
|
def migration_version
|
248
|
-
File.basename(
|
239
|
+
File.basename(
|
240
|
+
@path, #: as !nil
|
241
|
+
).split("_").first
|
249
242
|
end
|
250
243
|
|
251
|
-
|
244
|
+
#: (Prism::Node node, name: String, command: String) -> void
|
252
245
|
def add_migrate_code_lens(node, name:, command:)
|
253
246
|
return unless @path
|
254
247
|
|
@@ -261,7 +254,7 @@ module RubyLsp
|
|
261
254
|
)
|
262
255
|
end
|
263
256
|
|
264
|
-
|
257
|
+
#: (Prism::Node node, name: String, command: String, kind: Symbol) -> void
|
265
258
|
def add_test_code_lens(node, name:, command:, kind:)
|
266
259
|
return unless @path
|
267
260
|
return unless @global_state.test_library == "rails"
|
@@ -4,18 +4,10 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module Rails
|
6
6
|
class Completion
|
7
|
-
extend T::Sig
|
8
7
|
include Requests::Support::Common
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
client: RunnerClient,
|
13
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem],
|
14
|
-
node_context: NodeContext,
|
15
|
-
dispatcher: Prism::Dispatcher,
|
16
|
-
uri: URI::Generic,
|
17
|
-
).void
|
18
|
-
end
|
9
|
+
# @override
|
10
|
+
#: (RunnerClient client, ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem] response_builder, NodeContext node_context, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
|
19
11
|
def initialize(client, response_builder, node_context, dispatcher, uri)
|
20
12
|
@response_builder = response_builder
|
21
13
|
@client = client
|
@@ -26,7 +18,7 @@ module RubyLsp
|
|
26
18
|
)
|
27
19
|
end
|
28
20
|
|
29
|
-
|
21
|
+
#: (Prism::CallNode node) -> void
|
30
22
|
def on_call_node_enter(node)
|
31
23
|
call_node = @node_context.call_node
|
32
24
|
return unless call_node
|
@@ -39,13 +31,13 @@ module RubyLsp
|
|
39
31
|
|
40
32
|
private
|
41
33
|
|
42
|
-
|
34
|
+
#: (node: Prism::CallNode, receiver: Prism::ConstantReadNode) -> void
|
43
35
|
def handle_active_record_where_completions(node:, receiver:)
|
44
36
|
resolved_class = @client.model(receiver.name.to_s)
|
45
37
|
return if resolved_class.nil?
|
46
38
|
|
47
|
-
arguments =
|
48
|
-
indexed_call_node_args =
|
39
|
+
arguments = @node_context.call_node.arguments&.arguments
|
40
|
+
indexed_call_node_args = {} #: Hash[String, Prism::Node]
|
49
41
|
|
50
42
|
if arguments
|
51
43
|
indexed_call_node_args = index_call_node_args(arguments: arguments)
|
@@ -70,7 +62,7 @@ module RubyLsp
|
|
70
62
|
end
|
71
63
|
end
|
72
64
|
|
73
|
-
|
65
|
+
#: (arguments: Array[Prism::Node]) -> Hash[String, Prism::Node]
|
74
66
|
def index_call_node_args(arguments:)
|
75
67
|
indexed_call_node_args = {}
|
76
68
|
arguments.each do |argument|
|
@@ -28,41 +28,30 @@ module RubyLsp
|
|
28
28
|
# - If using `constraints`, the route can only be found if the constraints are met.
|
29
29
|
# - Changes to routes won't be picked up until the server is restarted.
|
30
30
|
class Definition
|
31
|
-
extend T::Sig
|
32
31
|
include Requests::Support::Common
|
33
32
|
|
34
|
-
|
35
|
-
params(
|
36
|
-
client: RunnerClient,
|
37
|
-
response_builder: RubyLsp::ResponseBuilders::CollectionResponseBuilder[T.any(
|
38
|
-
Interface::Location, Interface::LocationLink
|
39
|
-
)],
|
40
|
-
node_context: NodeContext,
|
41
|
-
index: RubyIndexer::Index,
|
42
|
-
dispatcher: Prism::Dispatcher,
|
43
|
-
).void
|
44
|
-
end
|
33
|
+
#: (RunnerClient client, RubyLsp::ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)] response_builder, NodeContext node_context, RubyIndexer::Index index, Prism::Dispatcher dispatcher) -> void
|
45
34
|
def initialize(client, response_builder, node_context, index, dispatcher)
|
46
35
|
@client = client
|
47
36
|
@response_builder = response_builder
|
48
37
|
@node_context = node_context
|
49
|
-
@nesting =
|
38
|
+
@nesting = node_context.nesting #: Array[String]
|
50
39
|
@index = index
|
51
40
|
|
52
41
|
dispatcher.register(self, :on_call_node_enter, :on_symbol_node_enter, :on_string_node_enter)
|
53
42
|
end
|
54
43
|
|
55
|
-
|
44
|
+
#: (Prism::SymbolNode node) -> void
|
56
45
|
def on_symbol_node_enter(node)
|
57
46
|
handle_possible_dsl(node)
|
58
47
|
end
|
59
48
|
|
60
|
-
|
49
|
+
#: (Prism::StringNode node) -> void
|
61
50
|
def on_string_node_enter(node)
|
62
51
|
handle_possible_dsl(node)
|
63
52
|
end
|
64
53
|
|
65
|
-
|
54
|
+
#: ((Prism::SymbolNode | Prism::StringNode) node) -> void
|
66
55
|
def handle_possible_dsl(node)
|
67
56
|
node = @node_context.call_node
|
68
57
|
return unless node
|
@@ -79,7 +68,7 @@ module RubyLsp
|
|
79
68
|
end
|
80
69
|
end
|
81
70
|
|
82
|
-
|
71
|
+
#: (Prism::CallNode node) -> void
|
83
72
|
def on_call_node_enter(node)
|
84
73
|
return unless self_receiver?(node)
|
85
74
|
|
@@ -94,7 +83,7 @@ module RubyLsp
|
|
94
83
|
|
95
84
|
private
|
96
85
|
|
97
|
-
|
86
|
+
#: (Prism::CallNode node) -> void
|
98
87
|
def handle_callback(node)
|
99
88
|
arguments = node.arguments&.arguments
|
100
89
|
return unless arguments&.any?
|
@@ -113,7 +102,7 @@ module RubyLsp
|
|
113
102
|
end
|
114
103
|
end
|
115
104
|
|
116
|
-
|
105
|
+
#: (Prism::CallNode node) -> void
|
117
106
|
def handle_association(node)
|
118
107
|
first_argument = node.arguments&.arguments&.first
|
119
108
|
return unless first_argument.is_a?(Prism::SymbolNode)
|
@@ -130,15 +119,17 @@ module RubyLsp
|
|
130
119
|
@response_builder << Support::LocationBuilder.line_location_from_s(result.fetch(:location))
|
131
120
|
end
|
132
121
|
|
133
|
-
|
122
|
+
#: (Prism::CallNode node) -> void
|
134
123
|
def handle_route(node)
|
135
|
-
result = @client.route_location(
|
124
|
+
result = @client.route_location(
|
125
|
+
node.message, #: as !nil
|
126
|
+
)
|
136
127
|
return unless result
|
137
128
|
|
138
129
|
@response_builder << Support::LocationBuilder.line_location_from_s(result.fetch(:location))
|
139
130
|
end
|
140
131
|
|
141
|
-
|
132
|
+
#: (String name) -> void
|
142
133
|
def collect_definitions(name)
|
143
134
|
methods = @index.resolve_method(name, @nesting.join("::"))
|
144
135
|
return unless methods
|