ruby-lsp-rails 0.4.6 → 0.4.8
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/lib/ruby_lsp/ruby_lsp_rails/definition.rb +1 -1
- data/lib/ruby_lsp/ruby_lsp_rails/hover.rb +61 -1
- data/lib/ruby_lsp/ruby_lsp_rails/rails_test_style.rb +1 -1
- data/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb +2 -2
- data/lib/ruby_lsp/ruby_lsp_rails/server.rb +10 -6
- data/lib/ruby_lsp/ruby_lsp_rails/support/callbacks.rb +7 -1
- data/lib/ruby_lsp_rails/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03be48ffee8e42576471456d11c3ddd9b483d1795b09adce6faf768bc0c07b8e
|
4
|
+
data.tar.gz: 17a31e143ed3b32899004f74bd54d0feb9f8a1284669f5b3448c18e42f2fe6ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7332a6411c36903267d8bcb448513eb21636205ca13290d71c2eeee26efa326c40dca280d639332428e863638e9db0fe12ffbd35f0a5e517ccc1ed777ce6a59b
|
7
|
+
data.tar.gz: b1c3e40c0def28339e948db1d336754197e697d1aa483b83e87786fa834f83f3c0088cbf7c3699dc7783df1f20c3ad6a8b1d104ab63e60c7bfb6a4a6962e7fa3
|
@@ -21,9 +21,15 @@ module RubyLsp
|
|
21
21
|
def initialize(client, response_builder, node_context, global_state, dispatcher)
|
22
22
|
@client = client
|
23
23
|
@response_builder = response_builder
|
24
|
+
@node_context = node_context
|
24
25
|
@nesting = node_context.nesting #: Array[String]
|
25
26
|
@index = global_state.index #: RubyIndexer::Index
|
26
|
-
dispatcher.register(
|
27
|
+
dispatcher.register(
|
28
|
+
self,
|
29
|
+
:on_constant_path_node_enter,
|
30
|
+
:on_constant_read_node_enter,
|
31
|
+
:on_symbol_node_enter,
|
32
|
+
)
|
27
33
|
end
|
28
34
|
|
29
35
|
#: (Prism::ConstantPathNode node) -> void
|
@@ -45,6 +51,11 @@ module RubyLsp
|
|
45
51
|
generate_column_content(item.name)
|
46
52
|
end
|
47
53
|
|
54
|
+
#: (Prism::SymbolNode node) -> void
|
55
|
+
def on_symbol_node_enter(node)
|
56
|
+
handle_possible_dsl(node)
|
57
|
+
end
|
58
|
+
|
48
59
|
private
|
49
60
|
|
50
61
|
#: (String name) -> void
|
@@ -104,6 +115,55 @@ module RubyLsp
|
|
104
115
|
default_value
|
105
116
|
end
|
106
117
|
end
|
118
|
+
|
119
|
+
#: (Prism::SymbolNode node) -> void
|
120
|
+
def handle_possible_dsl(node)
|
121
|
+
node = @node_context.call_node
|
122
|
+
return unless node
|
123
|
+
return unless self_receiver?(node)
|
124
|
+
|
125
|
+
message = node.message
|
126
|
+
|
127
|
+
return unless message
|
128
|
+
|
129
|
+
if Support::Associations::ALL.include?(message)
|
130
|
+
handle_association(node)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
#: (Prism::CallNode node) -> void
|
135
|
+
def handle_association(node)
|
136
|
+
first_argument = node.arguments&.arguments&.first
|
137
|
+
return unless first_argument.is_a?(Prism::SymbolNode)
|
138
|
+
|
139
|
+
association_name = first_argument.unescaped
|
140
|
+
|
141
|
+
result = @client.association_target(
|
142
|
+
model_name: @nesting.join("::"),
|
143
|
+
association_name: association_name,
|
144
|
+
)
|
145
|
+
|
146
|
+
return unless result
|
147
|
+
|
148
|
+
generate_hover(result[:name])
|
149
|
+
end
|
150
|
+
|
151
|
+
# Copied from `RubyLsp::Listeners::Hover#generate_hover`
|
152
|
+
#: (String name) -> void
|
153
|
+
def generate_hover(name)
|
154
|
+
entries = @index.resolve(name, @node_context.nesting)
|
155
|
+
return unless entries
|
156
|
+
|
157
|
+
# We should only show hover for private constants if the constant is defined in the same namespace as the
|
158
|
+
# reference
|
159
|
+
first_entry = entries.first #: as !nil
|
160
|
+
full_name = first_entry.name
|
161
|
+
return if first_entry.private? && full_name != "#{@node_context.fully_qualified_name}::#{name}"
|
162
|
+
|
163
|
+
categorized_markdown_from_index_entries(full_name, entries).each do |category, content|
|
164
|
+
@response_builder.push(content, category: category)
|
165
|
+
end
|
166
|
+
end
|
107
167
|
end
|
108
168
|
end
|
109
169
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
module RubyLsp
|
5
5
|
module Rails
|
6
6
|
class RailsTestStyle < Listeners::TestDiscovery
|
7
|
-
BASE_COMMAND = "#{
|
7
|
+
BASE_COMMAND = "bundle exec ruby -r#{Listeners::TestStyle::MINITEST_REPORTER_PATH} bin/rails test" #: String
|
8
8
|
|
9
9
|
class << self
|
10
10
|
#: (Array[Hash[Symbol, untyped]]) -> Array[String]
|
@@ -144,9 +144,9 @@ module RubyLsp
|
|
144
144
|
end
|
145
145
|
|
146
146
|
#: (model_name: String, association_name: String) -> Hash[Symbol, untyped]?
|
147
|
-
def
|
147
|
+
def association_target(model_name:, association_name:)
|
148
148
|
make_request(
|
149
|
-
"
|
149
|
+
"association_target",
|
150
150
|
model_name: model_name,
|
151
151
|
association_name: association_name,
|
152
152
|
)
|
@@ -68,8 +68,10 @@ module RubyLsp
|
|
68
68
|
send_error_response("Request #{request_name} failed because database connection was not established.")
|
69
69
|
rescue ActiveRecord::NoDatabaseError
|
70
70
|
send_error_response("Request #{request_name} failed because the database does not exist.")
|
71
|
-
rescue => e
|
72
|
-
send_error_response("Request #{request_name} failed:\n#{e.full_message(highlight: false)}")
|
71
|
+
rescue NotImplementedError, LoadError, SyntaxError, SystemExit, SystemStackError => e
|
72
|
+
send_error_response("Request #{request_name} failed with #{e.class}:\n#{e.full_message(highlight: false)}")
|
73
|
+
rescue StandardError => e
|
74
|
+
send_error_response("Request #{request_name} failed with StandardError:\n#{e.full_message(highlight: false)}")
|
73
75
|
end
|
74
76
|
|
75
77
|
# Handle possible errors for a notification. This should only be used for notifications, which means messages that
|
@@ -82,8 +84,10 @@ module RubyLsp
|
|
82
84
|
log_message("Request #{notification_name} failed because database connection was not established.")
|
83
85
|
rescue ActiveRecord::NoDatabaseError
|
84
86
|
log_message("Request #{notification_name} failed because the database does not exist.")
|
85
|
-
rescue => e
|
86
|
-
log_message("Request #{notification_name} failed:\n#{e.full_message(highlight: false)}")
|
87
|
+
rescue NotImplementedError, LoadError, SyntaxError, SystemExit, SystemStackError => e
|
88
|
+
log_message("Request #{notification_name} failed with #{e.class}:\n#{e.full_message(highlight: false)}")
|
89
|
+
rescue StandardError => e
|
90
|
+
log_message("Request #{notification_name} failed with StandardError:\n#{e.full_message(highlight: false)}")
|
87
91
|
end
|
88
92
|
|
89
93
|
#: (String, String, ?percentage: Integer?, ?message: String?) -> void
|
@@ -302,7 +306,7 @@ module RubyLsp
|
|
302
306
|
with_request_error_handling(request) do
|
303
307
|
send_result(resolve_database_info_from_model(params.fetch(:name)))
|
304
308
|
end
|
305
|
-
when "
|
309
|
+
when "association_target"
|
306
310
|
with_request_error_handling(request) do
|
307
311
|
send_result(resolve_association_target(params))
|
308
312
|
end
|
@@ -427,7 +431,7 @@ module RubyLsp
|
|
427
431
|
source_location = Object.const_source_location(association_klass.to_s)
|
428
432
|
return unless source_location
|
429
433
|
|
430
|
-
{ location: "#{source_location[0]}:#{source_location[1]}" }
|
434
|
+
{ location: "#{source_location[0]}:#{source_location[1]}", name: association_klass.name }
|
431
435
|
rescue NameError
|
432
436
|
nil
|
433
437
|
end
|
@@ -55,7 +55,13 @@ module RubyLsp
|
|
55
55
|
"before_perform",
|
56
56
|
].freeze
|
57
57
|
|
58
|
-
|
58
|
+
MAILBOX = [
|
59
|
+
"after_processing",
|
60
|
+
"before_processing",
|
61
|
+
"around_processing",
|
62
|
+
].freeze
|
63
|
+
|
64
|
+
ALL = (MODELS + CONTROLLERS + JOBS + MAILBOX).freeze #: Array[String]
|
59
65
|
end
|
60
66
|
end
|
61
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsp-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
@@ -15,20 +15,20 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - ">="
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 0.
|
18
|
+
version: 0.26.0
|
19
19
|
- - "<"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.27.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.
|
28
|
+
version: 0.26.0
|
29
29
|
- - "<"
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
version: 0.
|
31
|
+
version: 0.27.0
|
32
32
|
description: A Ruby LSP addon that adds extra editor functionality for Rails applications
|
33
33
|
email:
|
34
34
|
- ruby@shopify.com
|