ruby-lsp-rails 0.3.10 → 0.3.11
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e684ecacd45b09fee18e386a95d0dfa61bd3cce2c64869bf34f711d9d0c2fa3
|
|
4
|
+
data.tar.gz: c575d062c88f997967989f1cca84a1241fb6d07750a0535e122112b890e9dd0e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 17c1805f2e1d7363e2734d6983fdba8b11b72e083ff07b0d872745121f9b4c1d20898e439a19c7dc9f179f8729260cf2f90e701e47967d4901576166fe66c420
|
|
7
|
+
data.tar.gz: '039f940ff0ea3247316609b379396a7096ada44ed0b4127969223c3277d946bbbd913e106ede27912fc29c53a0e349999231e1561940e5d75ff6adbf0cea1a89'
|
|
@@ -51,9 +51,7 @@ module RubyLsp
|
|
|
51
51
|
).void
|
|
52
52
|
end
|
|
53
53
|
def create_code_lens_listener(response_builder, uri, dispatcher)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
CodeLens.new(@client, response_builder, uri, dispatcher)
|
|
54
|
+
CodeLens.new(@client, T.must(@global_state), response_builder, uri, dispatcher)
|
|
57
55
|
end
|
|
58
56
|
|
|
59
57
|
sig do
|
|
@@ -79,20 +79,30 @@ module RubyLsp
|
|
|
79
79
|
sig do
|
|
80
80
|
params(
|
|
81
81
|
client: RunnerClient,
|
|
82
|
+
global_state: GlobalState,
|
|
82
83
|
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens],
|
|
83
84
|
uri: URI::Generic,
|
|
84
85
|
dispatcher: Prism::Dispatcher,
|
|
85
86
|
).void
|
|
86
87
|
end
|
|
87
|
-
def initialize(client, response_builder, uri, dispatcher)
|
|
88
|
+
def initialize(client, global_state, response_builder, uri, dispatcher)
|
|
88
89
|
@client = client
|
|
90
|
+
@global_state = global_state
|
|
89
91
|
@response_builder = response_builder
|
|
90
92
|
@path = T.let(uri.to_standardized_path, T.nilable(String))
|
|
91
93
|
@group_id = T.let(1, Integer)
|
|
92
94
|
@group_id_stack = T.let([], T::Array[Integer])
|
|
93
95
|
@constant_name_stack = T.let([], T::Array[[String, T.nilable(String)]])
|
|
94
96
|
|
|
95
|
-
dispatcher.register(
|
|
97
|
+
dispatcher.register(
|
|
98
|
+
self,
|
|
99
|
+
:on_call_node_enter,
|
|
100
|
+
:on_class_node_enter,
|
|
101
|
+
:on_def_node_enter,
|
|
102
|
+
:on_class_node_leave,
|
|
103
|
+
:on_module_node_enter,
|
|
104
|
+
:on_module_node_leave,
|
|
105
|
+
)
|
|
96
106
|
end
|
|
97
107
|
|
|
98
108
|
sig { params(node: Prism::CallNode).void }
|
|
@@ -119,6 +129,7 @@ module RubyLsp
|
|
|
119
129
|
|
|
120
130
|
if controller?
|
|
121
131
|
add_route_code_lens_to_action(node)
|
|
132
|
+
add_jump_to_view(node)
|
|
122
133
|
end
|
|
123
134
|
end
|
|
124
135
|
|
|
@@ -156,6 +167,16 @@ module RubyLsp
|
|
|
156
167
|
@constant_name_stack.pop
|
|
157
168
|
end
|
|
158
169
|
|
|
170
|
+
sig { params(node: Prism::ModuleNode).void }
|
|
171
|
+
def on_module_node_enter(node)
|
|
172
|
+
@constant_name_stack << [node.constant_path.slice, nil]
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
sig { params(node: Prism::ModuleNode).void }
|
|
176
|
+
def on_module_node_leave(node)
|
|
177
|
+
@constant_name_stack.pop
|
|
178
|
+
end
|
|
179
|
+
|
|
159
180
|
private
|
|
160
181
|
|
|
161
182
|
sig { returns(T.nilable(T::Boolean)) }
|
|
@@ -167,34 +188,42 @@ module RubyLsp
|
|
|
167
188
|
end
|
|
168
189
|
|
|
169
190
|
sig { params(node: Prism::DefNode).void }
|
|
170
|
-
def
|
|
171
|
-
class_name
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
191
|
+
def add_jump_to_view(node)
|
|
192
|
+
class_name = @constant_name_stack.map(&:first).join("::")
|
|
193
|
+
action_name = node.name
|
|
194
|
+
controller_name = class_name
|
|
195
|
+
.delete_suffix("Controller")
|
|
196
|
+
.gsub(/([a-z])([A-Z])/, "\\1_\\2")
|
|
197
|
+
.gsub("::", "/")
|
|
198
|
+
.downcase
|
|
199
|
+
|
|
200
|
+
view_uris = Dir.glob("#{@client.rails_root}/app/views/#{controller_name}/#{action_name}*").map! do |path|
|
|
201
|
+
URI::Generic.from_path(path: path).to_s
|
|
202
|
+
end
|
|
203
|
+
return if view_uris.empty?
|
|
204
|
+
|
|
205
|
+
@response_builder << create_code_lens(
|
|
206
|
+
node,
|
|
207
|
+
title: "Jump to view",
|
|
208
|
+
command_name: "rubyLsp.openFile",
|
|
209
|
+
arguments: [view_uris],
|
|
210
|
+
data: { type: "file" },
|
|
175
211
|
)
|
|
212
|
+
end
|
|
176
213
|
|
|
214
|
+
sig { params(node: Prism::DefNode).void }
|
|
215
|
+
def add_route_code_lens_to_action(node)
|
|
216
|
+
class_name, _ = T.must(@constant_name_stack.last)
|
|
217
|
+
route = @client.route(controller: class_name, action: node.name.to_s)
|
|
177
218
|
return unless route
|
|
178
219
|
|
|
179
|
-
|
|
180
|
-
verb = route[:verb]
|
|
181
|
-
source_location = route[:source_location]
|
|
182
|
-
|
|
183
|
-
arguments = [
|
|
184
|
-
source_location,
|
|
185
|
-
{
|
|
186
|
-
start_line: node.location.start_line - 1,
|
|
187
|
-
start_column: node.location.start_column,
|
|
188
|
-
end_line: node.location.end_line - 1,
|
|
189
|
-
end_column: node.location.end_column,
|
|
190
|
-
},
|
|
191
|
-
]
|
|
220
|
+
file_path, line = route[:source_location]
|
|
192
221
|
|
|
193
222
|
@response_builder << create_code_lens(
|
|
194
223
|
node,
|
|
195
|
-
title: [verb
|
|
224
|
+
title: "#{route[:verb]} #{route[:path]}",
|
|
196
225
|
command_name: "rubyLsp.openFile",
|
|
197
|
-
arguments:
|
|
226
|
+
arguments: [["file://#{file_path}#L#{line}"]],
|
|
198
227
|
data: { type: "file" },
|
|
199
228
|
)
|
|
200
229
|
end
|
|
@@ -230,6 +259,7 @@ module RubyLsp
|
|
|
230
259
|
sig { params(node: Prism::Node, name: String, command: String, kind: Symbol).void }
|
|
231
260
|
def add_test_code_lens(node, name:, command:, kind:)
|
|
232
261
|
return unless @path
|
|
262
|
+
return unless @global_state.test_library == "rails"
|
|
233
263
|
|
|
234
264
|
arguments = [
|
|
235
265
|
@path,
|
|
@@ -36,6 +36,9 @@ module RubyLsp
|
|
|
36
36
|
|
|
37
37
|
extend T::Sig
|
|
38
38
|
|
|
39
|
+
sig { returns(String) }
|
|
40
|
+
attr_reader :rails_root
|
|
41
|
+
|
|
39
42
|
sig { void }
|
|
40
43
|
def initialize
|
|
41
44
|
# Spring needs a Process session ID. It uses this ID to "attach" itself to the parent process, so that when the
|
|
@@ -67,7 +70,8 @@ module RubyLsp
|
|
|
67
70
|
|
|
68
71
|
begin
|
|
69
72
|
count += 1
|
|
70
|
-
read_response
|
|
73
|
+
initialize_response = T.must(read_response)
|
|
74
|
+
@rails_root = T.let(initialize_response[:root], String)
|
|
71
75
|
rescue EmptyMessageError
|
|
72
76
|
$stderr.puts("Ruby LSP Rails is retrying initialize (#{count})")
|
|
73
77
|
retry if count < MAX_RETRIES
|
|
@@ -218,6 +222,11 @@ module RubyLsp
|
|
|
218
222
|
true
|
|
219
223
|
end
|
|
220
224
|
|
|
225
|
+
sig { override.returns(String) }
|
|
226
|
+
def rails_root
|
|
227
|
+
Dir.pwd
|
|
228
|
+
end
|
|
229
|
+
|
|
221
230
|
private
|
|
222
231
|
|
|
223
232
|
sig { override.params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
|
|
@@ -24,7 +24,7 @@ module RubyLsp
|
|
|
24
24
|
routes_reloader = ::Rails.application.routes_reloader
|
|
25
25
|
routes_reloader.execute_unless_loaded if routes_reloader&.respond_to?(:execute_unless_loaded)
|
|
26
26
|
|
|
27
|
-
initialize_result = { result: { message: "ok" } }.to_json
|
|
27
|
+
initialize_result = { result: { message: "ok", root: ::Rails.root.to_s } }.to_json
|
|
28
28
|
$stdout.write("Content-Length: #{initialize_result.length}\r\n\r\n#{initialize_result}")
|
|
29
29
|
|
|
30
30
|
while @running
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-lsp-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shopify
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-07-
|
|
11
|
+
date: 2024-07-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ruby-lsp
|
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
79
79
|
- !ruby/object:Gem::Version
|
|
80
80
|
version: '0'
|
|
81
81
|
requirements: []
|
|
82
|
-
rubygems_version: 3.5.
|
|
82
|
+
rubygems_version: 3.5.15
|
|
83
83
|
signing_key:
|
|
84
84
|
specification_version: 4
|
|
85
85
|
summary: A Ruby LSP addon for Rails
|