ruby-lsp-rails 0.3.31 → 0.4.1
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 +11 -2
- data/lib/ruby_lsp/ruby_lsp_rails/addon.rb +68 -61
- data/lib/ruby_lsp/ruby_lsp_rails/code_lens.rb +15 -24
- data/lib/ruby_lsp/ruby_lsp_rails/completion.rb +6 -14
- data/lib/ruby_lsp/ruby_lsp_rails/definition.rb +9 -20
- data/lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb +12 -24
- data/lib/ruby_lsp/ruby_lsp_rails/hover.rb +39 -27
- 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 +90 -59
- data/lib/ruby_lsp/ruby_lsp_rails/server.rb +174 -17
- data/lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb +1 -3
- 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: ea71850cee42d73b31e37c68aa3438a7d59c4c610fef1e2e20a157ff7c7bd92d
|
4
|
+
data.tar.gz: 5d4506c255005cc442fbe95fc73bfe58220a70155313b4451b8a3e549feef9de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8538d6e4330168cc5d480ca157cb0c57e178ff3b24429f1a456986e3f91f471a830b3d6ab04b943dd5d18f4d9116ff25ccf94da91db28e8c9c4ad850a488532
|
7
|
+
data.tar.gz: d527c41fcffc45935bab4a5b6332d940c07fdcbaaec189a223bbba5db46459d2f5fb033a3a4809f7ffc74aa1bf1cdcb0ed228cc6f244db4b25ff2ea57aa57421
|
data/Rakefile
CHANGED
@@ -10,10 +10,19 @@ load "rails/tasks/statistics.rake"
|
|
10
10
|
require "bundler/gem_tasks"
|
11
11
|
require "rake/testtask"
|
12
12
|
|
13
|
+
# Since `server.rb` runs within the host Rails application, we want to ensure
|
14
|
+
# we don't accidentally depend on sorbet-runtime. `server_test` intentionally doesn't use `test_helper`.
|
15
|
+
# We run `server_test` in a seperate Rake task.
|
13
16
|
Rake::TestTask.new(:test) do |t|
|
14
17
|
t.libs << "test"
|
15
18
|
t.libs << "lib"
|
16
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
19
|
+
t.test_files = FileList["test/**/*_test.rb"] - ["test/ruby_lsp_rails/server_test.rb"]
|
17
20
|
end
|
18
21
|
|
19
|
-
|
22
|
+
Rake::TestTask.new(:server_test) do |t|
|
23
|
+
t.libs << "test"
|
24
|
+
t.libs << "lib"
|
25
|
+
t.test_files = ["test/ruby_lsp_rails/server_test.rb"]
|
26
|
+
end
|
27
|
+
|
28
|
+
task default: [:"db:setup", :test, :server_test]
|
@@ -13,17 +13,16 @@ 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
|
|
@@ -32,6 +31,12 @@ module RubyLsp
|
|
32
31
|
@rails_runner_client = T.let(NullClient.new, RunnerClient)
|
33
32
|
@global_state = T.let(nil, T.nilable(GlobalState))
|
34
33
|
@outgoing_queue = T.let(nil, T.nilable(Thread::Queue))
|
34
|
+
@settings = T.let(
|
35
|
+
{
|
36
|
+
enablePendingMigrationsPrompt: true,
|
37
|
+
},
|
38
|
+
T::Hash[Symbol, T.untyped],
|
39
|
+
)
|
35
40
|
@addon_mutex = T.let(Mutex.new, Mutex)
|
36
41
|
@client_mutex = T.let(Mutex.new, Mutex)
|
37
42
|
@client_mutex.lock
|
@@ -39,100 +44,99 @@ module RubyLsp
|
|
39
44
|
Thread.new do
|
40
45
|
@addon_mutex.synchronize do
|
41
46
|
# We need to ensure the Rails client is fully loaded before we activate the server addons
|
42
|
-
@client_mutex.synchronize
|
47
|
+
@client_mutex.synchronize do
|
48
|
+
@rails_runner_client = RunnerClient.create_client(T.must(@outgoing_queue), T.must(@global_state))
|
49
|
+
end
|
43
50
|
offer_to_run_pending_migrations
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
48
|
-
|
55
|
+
#: -> RunnerClient
|
49
56
|
def rails_runner_client
|
50
57
|
@addon_mutex.synchronize { @rails_runner_client }
|
51
58
|
end
|
52
59
|
|
53
|
-
|
60
|
+
# @override
|
61
|
+
#: (GlobalState global_state, Thread::Queue outgoing_queue) -> void
|
54
62
|
def activate(global_state, outgoing_queue)
|
55
63
|
@global_state = global_state
|
56
64
|
@outgoing_queue = outgoing_queue
|
57
65
|
@outgoing_queue << Notification.window_log_message("Activating Ruby LSP Rails add-on v#{VERSION}")
|
58
66
|
|
67
|
+
addon_settings = @global_state.settings_for_addon(name)
|
68
|
+
@settings.merge!(addon_settings) if addon_settings
|
69
|
+
|
59
70
|
register_additional_file_watchers(global_state: global_state, outgoing_queue: outgoing_queue)
|
60
71
|
|
61
72
|
# Start booting the real client in a background thread. Until this completes, the client will be a NullClient
|
62
73
|
@client_mutex.unlock
|
63
74
|
end
|
64
75
|
|
65
|
-
|
76
|
+
# @override
|
77
|
+
#: -> void
|
66
78
|
def deactivate
|
67
79
|
@rails_runner_client.shutdown
|
68
80
|
end
|
69
81
|
|
70
|
-
|
82
|
+
# @override
|
83
|
+
#: -> String
|
71
84
|
def version
|
72
85
|
VERSION
|
73
86
|
end
|
74
87
|
|
75
|
-
#
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
).void
|
88
|
+
# @override
|
89
|
+
#: (ResponseBuilders::TestCollection response_builder, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
|
90
|
+
def create_discover_tests_listener(response_builder, dispatcher, uri)
|
91
|
+
return unless @global_state
|
92
|
+
|
93
|
+
RailsTestStyle.new(@rails_runner_client, response_builder, @global_state, dispatcher, uri)
|
82
94
|
end
|
83
|
-
|
84
|
-
|
95
|
+
|
96
|
+
# @override
|
97
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[String]
|
98
|
+
def resolve_test_commands(items)
|
99
|
+
RailsTestStyle.resolve_test_commands(items)
|
85
100
|
end
|
86
101
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
102
|
+
# Creates a new CodeLens listener. This method is invoked on every CodeLens request
|
103
|
+
# @override
|
104
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
|
105
|
+
def create_code_lens_listener(response_builder, uri, dispatcher)
|
106
|
+
return unless @global_state
|
107
|
+
|
108
|
+
CodeLens.new(@rails_runner_client, @global_state, response_builder, uri, dispatcher)
|
93
109
|
end
|
110
|
+
|
111
|
+
# @override
|
112
|
+
#: (ResponseBuilders::Hover response_builder, NodeContext node_context, Prism::Dispatcher dispatcher) -> void
|
94
113
|
def create_hover_listener(response_builder, node_context, dispatcher)
|
95
|
-
|
96
|
-
end
|
114
|
+
return unless @global_state
|
97
115
|
|
98
|
-
|
99
|
-
override.params(
|
100
|
-
response_builder: ResponseBuilders::DocumentSymbol,
|
101
|
-
dispatcher: Prism::Dispatcher,
|
102
|
-
).returns(Object)
|
116
|
+
Hover.new(@rails_runner_client, response_builder, node_context, @global_state, dispatcher)
|
103
117
|
end
|
118
|
+
|
119
|
+
# @override
|
120
|
+
#: (ResponseBuilders::DocumentSymbol response_builder, Prism::Dispatcher dispatcher) -> Object
|
104
121
|
def create_document_symbol_listener(response_builder, dispatcher)
|
105
122
|
DocumentSymbol.new(response_builder, dispatcher)
|
106
123
|
end
|
107
124
|
|
108
|
-
|
109
|
-
|
110
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[T.any(
|
111
|
-
Interface::Location, Interface::LocationLink
|
112
|
-
)],
|
113
|
-
uri: URI::Generic,
|
114
|
-
node_context: NodeContext,
|
115
|
-
dispatcher: Prism::Dispatcher,
|
116
|
-
).void
|
117
|
-
end
|
125
|
+
# @override
|
126
|
+
#: (ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)] response_builder, URI::Generic uri, NodeContext node_context, Prism::Dispatcher dispatcher) -> void
|
118
127
|
def create_definition_listener(response_builder, uri, node_context, dispatcher)
|
119
|
-
|
120
|
-
Definition.new(@rails_runner_client, response_builder, node_context, index, dispatcher)
|
121
|
-
end
|
128
|
+
return unless @global_state
|
122
129
|
|
123
|
-
|
124
|
-
override.params(
|
125
|
-
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem],
|
126
|
-
node_context: NodeContext,
|
127
|
-
dispatcher: Prism::Dispatcher,
|
128
|
-
uri: URI::Generic,
|
129
|
-
).void
|
130
|
+
Definition.new(@rails_runner_client, response_builder, node_context, @global_state.index, dispatcher)
|
130
131
|
end
|
132
|
+
|
133
|
+
# @override
|
134
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem] response_builder, NodeContext node_context, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
|
131
135
|
def create_completion_listener(response_builder, node_context, dispatcher, uri)
|
132
136
|
Completion.new(@rails_runner_client, response_builder, node_context, dispatcher, uri)
|
133
137
|
end
|
134
138
|
|
135
|
-
|
139
|
+
#: (Array[{uri: String, type: Integer}] changes) -> void
|
136
140
|
def workspace_did_change_watched_files(changes)
|
137
141
|
if changes.any? { |c| c[:uri].end_with?("db/schema.rb") || c[:uri].end_with?("structure.sql") }
|
138
142
|
@rails_runner_client.trigger_reload
|
@@ -146,12 +150,14 @@ module RubyLsp
|
|
146
150
|
end
|
147
151
|
end
|
148
152
|
|
149
|
-
|
153
|
+
# @override
|
154
|
+
#: -> String
|
150
155
|
def name
|
151
156
|
"Ruby LSP Rails"
|
152
157
|
end
|
153
158
|
|
154
|
-
|
159
|
+
# @override
|
160
|
+
#: (String title) -> void
|
155
161
|
def handle_window_show_message_response(title)
|
156
162
|
if title == RUN_MIGRATIONS_TITLE
|
157
163
|
|
@@ -178,7 +184,7 @@ module RubyLsp
|
|
178
184
|
|
179
185
|
private
|
180
186
|
|
181
|
-
|
187
|
+
#: (String id, String title, ?percentage: Integer?, ?message: String?) -> void
|
182
188
|
def begin_progress(id, title, percentage: nil, message: nil)
|
183
189
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
184
190
|
|
@@ -196,21 +202,21 @@ module RubyLsp
|
|
196
202
|
)
|
197
203
|
end
|
198
204
|
|
199
|
-
|
200
|
-
def report_progress(id,
|
205
|
+
#: (String id, ?percentage: Integer?, ?message: String?) -> void
|
206
|
+
def report_progress(id, percentage: nil, message: nil)
|
201
207
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
202
208
|
|
203
209
|
@outgoing_queue << Notification.progress_report(id, percentage: percentage, message: message)
|
204
210
|
end
|
205
211
|
|
206
|
-
|
212
|
+
#: (String id) -> void
|
207
213
|
def end_progress(id)
|
208
214
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
209
215
|
|
210
216
|
@outgoing_queue << Notification.progress_end(id)
|
211
217
|
end
|
212
218
|
|
213
|
-
|
219
|
+
#: (global_state: GlobalState, outgoing_queue: Thread::Queue) -> void
|
214
220
|
def register_additional_file_watchers(global_state:, outgoing_queue:)
|
215
221
|
return unless global_state.client_capabilities.supports_watching_files
|
216
222
|
|
@@ -231,7 +237,7 @@ module RubyLsp
|
|
231
237
|
)
|
232
238
|
end
|
233
239
|
|
234
|
-
|
240
|
+
#: -> Interface::FileSystemWatcher
|
235
241
|
def structure_sql_file_watcher
|
236
242
|
Interface::FileSystemWatcher.new(
|
237
243
|
glob_pattern: "**/*structure.sql",
|
@@ -239,7 +245,7 @@ module RubyLsp
|
|
239
245
|
)
|
240
246
|
end
|
241
247
|
|
242
|
-
|
248
|
+
#: -> Interface::FileSystemWatcher
|
243
249
|
def fixture_file_watcher
|
244
250
|
Interface::FileSystemWatcher.new(
|
245
251
|
glob_pattern: "**/fixtures/**/*.{yml,yaml,yml.erb,yaml.erb}",
|
@@ -247,10 +253,11 @@ module RubyLsp
|
|
247
253
|
)
|
248
254
|
end
|
249
255
|
|
250
|
-
|
256
|
+
#: -> void
|
251
257
|
def offer_to_run_pending_migrations
|
252
258
|
return unless @outgoing_queue
|
253
259
|
return unless @global_state&.client_capabilities&.window_show_message_supports_extra_properties
|
260
|
+
return unless @settings[:enablePendingMigrationsPrompt]
|
254
261
|
|
255
262
|
migration_message = @rails_runner_client.pending_migrations_message
|
256
263
|
return unless migration_message
|
@@ -72,19 +72,10 @@ 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
|
@@ -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,7 +207,7 @@ 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
212
|
class_name, _ = T.must(@constant_name_stack.last)
|
222
213
|
route = @client.route(controller: class_name, action: node.name.to_s)
|
@@ -233,22 +224,22 @@ 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
239
|
File.basename(T.must(@path)).split("_").first
|
249
240
|
end
|
250
241
|
|
251
|
-
|
242
|
+
#: (Prism::Node node, name: String, command: String) -> void
|
252
243
|
def add_migrate_code_lens(node, name:, command:)
|
253
244
|
return unless @path
|
254
245
|
|
@@ -261,7 +252,7 @@ module RubyLsp
|
|
261
252
|
)
|
262
253
|
end
|
263
254
|
|
264
|
-
|
255
|
+
#: (Prism::Node node, name: String, command: String, kind: Symbol) -> void
|
265
256
|
def add_test_code_lens(node, name:, command:, kind:)
|
266
257
|
return unless @path
|
267
258
|
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,12 +31,12 @@ 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 =
|
39
|
+
arguments = @node_context.call_node.arguments&.arguments
|
48
40
|
indexed_call_node_args = T.let({}, T::Hash[String, Prism::Node])
|
49
41
|
|
50
42
|
if 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,20 +28,9 @@ 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
|
@@ -52,17 +41,17 @@ module RubyLsp
|
|
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,7 +119,7 @@ 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
124
|
result = @client.route_location(T.must(node.message))
|
136
125
|
return unless result
|
@@ -138,7 +127,7 @@ module RubyLsp
|
|
138
127
|
@response_builder << Support::LocationBuilder.line_location_from_s(result.fetch(:location))
|
139
128
|
end
|
140
129
|
|
141
|
-
|
130
|
+
#: (String name) -> void
|
142
131
|
def collect_definitions(name)
|
143
132
|
methods = @index.resolve_method(name, @nesting.join("::"))
|
144
133
|
return unless methods
|
@@ -9,16 +9,10 @@ module RubyLsp
|
|
9
9
|
# request allows users to navigate between associations, validations, callbacks and ActiveSupport test cases with
|
10
10
|
# VS Code's "Go to Symbol" feature.
|
11
11
|
class DocumentSymbol
|
12
|
-
extend T::Sig
|
13
12
|
include Requests::Support::Common
|
14
13
|
include ActiveSupportTestCaseHelper
|
15
14
|
|
16
|
-
|
17
|
-
params(
|
18
|
-
response_builder: ResponseBuilders::DocumentSymbol,
|
19
|
-
dispatcher: Prism::Dispatcher,
|
20
|
-
).void
|
21
|
-
end
|
15
|
+
#: (ResponseBuilders::DocumentSymbol response_builder, Prism::Dispatcher dispatcher) -> void
|
22
16
|
def initialize(response_builder, dispatcher)
|
23
17
|
@response_builder = response_builder
|
24
18
|
@namespace_stack = T.let([], T::Array[String])
|
@@ -33,7 +27,7 @@ module RubyLsp
|
|
33
27
|
)
|
34
28
|
end
|
35
29
|
|
36
|
-
|
30
|
+
#: (Prism::CallNode node) -> void
|
37
31
|
def on_call_node_enter(node)
|
38
32
|
return if @namespace_stack.empty?
|
39
33
|
|
@@ -62,39 +56,39 @@ module RubyLsp
|
|
62
56
|
end
|
63
57
|
end
|
64
58
|
|
65
|
-
|
59
|
+
#: (Prism::ClassNode node) -> void
|
66
60
|
def on_class_node_enter(node)
|
67
61
|
add_to_namespace_stack(node)
|
68
62
|
end
|
69
63
|
|
70
|
-
|
64
|
+
#: (Prism::ClassNode node) -> void
|
71
65
|
def on_class_node_leave(node)
|
72
66
|
remove_from_namespace_stack(node)
|
73
67
|
end
|
74
68
|
|
75
|
-
|
69
|
+
#: (Prism::ModuleNode node) -> void
|
76
70
|
def on_module_node_enter(node)
|
77
71
|
add_to_namespace_stack(node)
|
78
72
|
end
|
79
73
|
|
80
|
-
|
74
|
+
#: (Prism::ModuleNode node) -> void
|
81
75
|
def on_module_node_leave(node)
|
82
76
|
remove_from_namespace_stack(node)
|
83
77
|
end
|
84
78
|
|
85
79
|
private
|
86
80
|
|
87
|
-
|
81
|
+
#: ((Prism::ClassNode | Prism::ModuleNode) node) -> void
|
88
82
|
def add_to_namespace_stack(node)
|
89
83
|
@namespace_stack << node.constant_path.slice
|
90
84
|
end
|
91
85
|
|
92
|
-
|
86
|
+
#: ((Prism::ClassNode | Prism::ModuleNode) node) -> void
|
93
87
|
def remove_from_namespace_stack(node)
|
94
88
|
@namespace_stack.delete(node.constant_path.slice)
|
95
89
|
end
|
96
90
|
|
97
|
-
|
91
|
+
#: (Prism::CallNode node, String message) -> void
|
98
92
|
def handle_all_arg_types(node, message)
|
99
93
|
block = node.block
|
100
94
|
|
@@ -164,7 +158,7 @@ module RubyLsp
|
|
164
158
|
end
|
165
159
|
end
|
166
160
|
|
167
|
-
|
161
|
+
#: (Prism::CallNode node, String message) -> void
|
168
162
|
def handle_symbol_and_string_arg_types(node, message)
|
169
163
|
arguments = node.arguments&.arguments
|
170
164
|
return unless arguments&.any?
|
@@ -193,7 +187,7 @@ module RubyLsp
|
|
193
187
|
end
|
194
188
|
end
|
195
189
|
|
196
|
-
|
190
|
+
#: (Prism::CallNode node, String message) -> void
|
197
191
|
def handle_class_arg_types(node, message)
|
198
192
|
arguments = node.arguments&.arguments
|
199
193
|
return unless arguments&.any?
|
@@ -213,13 +207,7 @@ module RubyLsp
|
|
213
207
|
end
|
214
208
|
end
|
215
209
|
|
216
|
-
|
217
|
-
params(
|
218
|
-
name: String,
|
219
|
-
range: RubyLsp::Interface::Range,
|
220
|
-
selection_range: RubyLsp::Interface::Range,
|
221
|
-
).void
|
222
|
-
end
|
210
|
+
#: (name: String, range: RubyLsp::Interface::Range, selection_range: RubyLsp::Interface::Range) -> void
|
223
211
|
def append_document_symbol(name:, range:, selection_range:)
|
224
212
|
@response_builder.last.children << RubyLsp::Interface::DocumentSymbol.new(
|
225
213
|
name: name,
|