ruby-lsp-rails 0.4.0 → 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 +46 -56
- 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 +40 -55
- data/lib/ruby_lsp/ruby_lsp_rails/server.rb +32 -0
- 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
|
|
@@ -53,12 +52,13 @@ module RubyLsp
|
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
|
-
|
55
|
+
#: -> RunnerClient
|
57
56
|
def rails_runner_client
|
58
57
|
@addon_mutex.synchronize { @rails_runner_client }
|
59
58
|
end
|
60
59
|
|
61
|
-
|
60
|
+
# @override
|
61
|
+
#: (GlobalState global_state, Thread::Queue outgoing_queue) -> void
|
62
62
|
def activate(global_state, outgoing_queue)
|
63
63
|
@global_state = global_state
|
64
64
|
@outgoing_queue = outgoing_queue
|
@@ -73,82 +73,70 @@ module RubyLsp
|
|
73
73
|
@client_mutex.unlock
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
# @override
|
77
|
+
#: -> void
|
77
78
|
def deactivate
|
78
79
|
@rails_runner_client.shutdown
|
79
80
|
end
|
80
81
|
|
81
|
-
|
82
|
+
# @override
|
83
|
+
#: -> String
|
82
84
|
def version
|
83
85
|
VERSION
|
84
86
|
end
|
85
87
|
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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)
|
94
|
+
end
|
95
|
+
|
96
|
+
# @override
|
97
|
+
#: (Array[Hash[Symbol, untyped]]) -> Array[String]
|
98
|
+
def resolve_test_commands(items)
|
99
|
+
RailsTestStyle.resolve_test_commands(items)
|
93
100
|
end
|
101
|
+
|
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
|
94
105
|
def create_code_lens_listener(response_builder, uri, dispatcher)
|
95
106
|
return unless @global_state
|
96
107
|
|
97
108
|
CodeLens.new(@rails_runner_client, @global_state, response_builder, uri, dispatcher)
|
98
109
|
end
|
99
110
|
|
100
|
-
|
101
|
-
|
102
|
-
response_builder: ResponseBuilders::Hover,
|
103
|
-
node_context: NodeContext,
|
104
|
-
dispatcher: Prism::Dispatcher,
|
105
|
-
).void
|
106
|
-
end
|
111
|
+
# @override
|
112
|
+
#: (ResponseBuilders::Hover response_builder, NodeContext node_context, Prism::Dispatcher dispatcher) -> void
|
107
113
|
def create_hover_listener(response_builder, node_context, dispatcher)
|
108
114
|
return unless @global_state
|
109
115
|
|
110
116
|
Hover.new(@rails_runner_client, response_builder, node_context, @global_state, dispatcher)
|
111
117
|
end
|
112
118
|
|
113
|
-
|
114
|
-
|
115
|
-
response_builder: ResponseBuilders::DocumentSymbol,
|
116
|
-
dispatcher: Prism::Dispatcher,
|
117
|
-
).returns(Object)
|
118
|
-
end
|
119
|
+
# @override
|
120
|
+
#: (ResponseBuilders::DocumentSymbol response_builder, Prism::Dispatcher dispatcher) -> Object
|
119
121
|
def create_document_symbol_listener(response_builder, dispatcher)
|
120
122
|
DocumentSymbol.new(response_builder, dispatcher)
|
121
123
|
end
|
122
124
|
|
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
|
125
|
+
# @override
|
126
|
+
#: (ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)] response_builder, URI::Generic uri, NodeContext node_context, Prism::Dispatcher dispatcher) -> void
|
133
127
|
def create_definition_listener(response_builder, uri, node_context, dispatcher)
|
134
128
|
return unless @global_state
|
135
129
|
|
136
130
|
Definition.new(@rails_runner_client, response_builder, node_context, @global_state.index, dispatcher)
|
137
131
|
end
|
138
132
|
|
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
|
133
|
+
# @override
|
134
|
+
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem] response_builder, NodeContext node_context, Prism::Dispatcher dispatcher, URI::Generic uri) -> void
|
147
135
|
def create_completion_listener(response_builder, node_context, dispatcher, uri)
|
148
136
|
Completion.new(@rails_runner_client, response_builder, node_context, dispatcher, uri)
|
149
137
|
end
|
150
138
|
|
151
|
-
|
139
|
+
#: (Array[{uri: String, type: Integer}] changes) -> void
|
152
140
|
def workspace_did_change_watched_files(changes)
|
153
141
|
if changes.any? { |c| c[:uri].end_with?("db/schema.rb") || c[:uri].end_with?("structure.sql") }
|
154
142
|
@rails_runner_client.trigger_reload
|
@@ -162,12 +150,14 @@ module RubyLsp
|
|
162
150
|
end
|
163
151
|
end
|
164
152
|
|
165
|
-
|
153
|
+
# @override
|
154
|
+
#: -> String
|
166
155
|
def name
|
167
156
|
"Ruby LSP Rails"
|
168
157
|
end
|
169
158
|
|
170
|
-
|
159
|
+
# @override
|
160
|
+
#: (String title) -> void
|
171
161
|
def handle_window_show_message_response(title)
|
172
162
|
if title == RUN_MIGRATIONS_TITLE
|
173
163
|
|
@@ -194,7 +184,7 @@ module RubyLsp
|
|
194
184
|
|
195
185
|
private
|
196
186
|
|
197
|
-
|
187
|
+
#: (String id, String title, ?percentage: Integer?, ?message: String?) -> void
|
198
188
|
def begin_progress(id, title, percentage: nil, message: nil)
|
199
189
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
200
190
|
|
@@ -212,21 +202,21 @@ module RubyLsp
|
|
212
202
|
)
|
213
203
|
end
|
214
204
|
|
215
|
-
|
216
|
-
def report_progress(id,
|
205
|
+
#: (String id, ?percentage: Integer?, ?message: String?) -> void
|
206
|
+
def report_progress(id, percentage: nil, message: nil)
|
217
207
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
218
208
|
|
219
209
|
@outgoing_queue << Notification.progress_report(id, percentage: percentage, message: message)
|
220
210
|
end
|
221
211
|
|
222
|
-
|
212
|
+
#: (String id) -> void
|
223
213
|
def end_progress(id)
|
224
214
|
return unless @global_state&.client_capabilities&.supports_progress && @outgoing_queue
|
225
215
|
|
226
216
|
@outgoing_queue << Notification.progress_end(id)
|
227
217
|
end
|
228
218
|
|
229
|
-
|
219
|
+
#: (global_state: GlobalState, outgoing_queue: Thread::Queue) -> void
|
230
220
|
def register_additional_file_watchers(global_state:, outgoing_queue:)
|
231
221
|
return unless global_state.client_capabilities.supports_watching_files
|
232
222
|
|
@@ -247,7 +237,7 @@ module RubyLsp
|
|
247
237
|
)
|
248
238
|
end
|
249
239
|
|
250
|
-
|
240
|
+
#: -> Interface::FileSystemWatcher
|
251
241
|
def structure_sql_file_watcher
|
252
242
|
Interface::FileSystemWatcher.new(
|
253
243
|
glob_pattern: "**/*structure.sql",
|
@@ -255,7 +245,7 @@ module RubyLsp
|
|
255
245
|
)
|
256
246
|
end
|
257
247
|
|
258
|
-
|
248
|
+
#: -> Interface::FileSystemWatcher
|
259
249
|
def fixture_file_watcher
|
260
250
|
Interface::FileSystemWatcher.new(
|
261
251
|
glob_pattern: "**/fixtures/**/*.{yml,yaml,yml.erb,yaml.erb}",
|
@@ -263,7 +253,7 @@ module RubyLsp
|
|
263
253
|
)
|
264
254
|
end
|
265
255
|
|
266
|
-
|
256
|
+
#: -> void
|
267
257
|
def offer_to_run_pending_migrations
|
268
258
|
return unless @outgoing_queue
|
269
259
|
return unless @global_state&.client_capabilities&.window_show_message_supports_extra_properties
|
@@ -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,
|