has_state_machine 1.2.1 → 1.2.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f9619070408aa690d1e8b70c31baf787c91d949c0e28665a42af8b17ff79955
|
|
4
|
+
data.tar.gz: '099784a11f816d49d75b18432a1497688838aac08a775d15fe5d29827eb7ac38'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 749b711582fc925fd8efbfcb7dcdee7dfb3f9902e945d5cc26e1f7f3737ea77f646087a117ccf9e6675444a858acb2497ae52dba0a3c8b2777628ebae33297af
|
|
7
|
+
data.tar.gz: a8cbe864ada7ab74316c55c14704ea33fa18bae5050d3a728d2f5458cb16b561419643805af0824fd7bdcca10cf42e5023e708d84f88ed1e3478a9b24bad2d43
|
|
@@ -12,12 +12,25 @@ module RubyLsp
|
|
|
12
12
|
class Addon < ::RubyLsp::Addon
|
|
13
13
|
def activate(global_state, outgoing_queue)
|
|
14
14
|
@global_state = global_state
|
|
15
|
+
@model_name_cache = {}
|
|
15
16
|
@rails_client = register_rails_server_addon(outgoing_queue)
|
|
17
|
+
|
|
18
|
+
rails_status = if @rails_client
|
|
19
|
+
"registered"
|
|
20
|
+
else
|
|
21
|
+
"unavailable, using naming convention only"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
log(
|
|
25
|
+
outgoing_queue,
|
|
26
|
+
"Activating Has State Machine Ruby LSP add-on v#{version} (Rails integration: #{rails_status})"
|
|
27
|
+
)
|
|
16
28
|
end
|
|
17
29
|
|
|
18
30
|
def deactivate
|
|
19
31
|
@global_state = nil
|
|
20
32
|
@rails_client = nil
|
|
33
|
+
@model_name_cache = nil
|
|
21
34
|
end
|
|
22
35
|
|
|
23
36
|
def name
|
|
@@ -35,7 +48,8 @@ module RubyLsp
|
|
|
35
48
|
node_context,
|
|
36
49
|
dispatcher,
|
|
37
50
|
index: @global_state&.index,
|
|
38
|
-
rails_client: @rails_client
|
|
51
|
+
rails_client: @rails_client,
|
|
52
|
+
model_name_cache: @model_name_cache
|
|
39
53
|
)
|
|
40
54
|
end
|
|
41
55
|
|
|
@@ -53,6 +67,7 @@ module RubyLsp
|
|
|
53
67
|
|
|
54
68
|
client = rails_addon.rails_runner_client
|
|
55
69
|
return unless client.respond_to?(:register_server_addon)
|
|
70
|
+
return if client.respond_to?(:connected?) && !client.connected?
|
|
56
71
|
|
|
57
72
|
client.register_server_addon(File.expand_path("rails_server_addon.rb", __dir__))
|
|
58
73
|
client
|
|
@@ -7,6 +7,10 @@ module RubyLsp
|
|
|
7
7
|
class Definition
|
|
8
8
|
SERVER_ADDON_NAME = "has_state_machine"
|
|
9
9
|
|
|
10
|
+
# AR methods that return self, so `object.reload.foo` targets the model
|
|
11
|
+
# just like `object.foo`.
|
|
12
|
+
SELF_RETURNING_METHODS = ["reload"].freeze
|
|
13
|
+
|
|
10
14
|
def initialize(response_builder, _uri, node_context, dispatcher, index: nil, rails_client: nil,
|
|
11
15
|
model_name_cache: nil)
|
|
12
16
|
@response_builder = response_builder
|
|
@@ -33,6 +37,7 @@ module RubyLsp
|
|
|
33
37
|
method_name = message(node)
|
|
34
38
|
entries = method_entries(resolved_model_name, method_name)
|
|
35
39
|
entries = association_entries(resolved_model_name, method_name) if entries.empty?
|
|
40
|
+
entries = constant_entries(resolved_model_name) if entries.empty?
|
|
36
41
|
|
|
37
42
|
push_entries(entries)
|
|
38
43
|
end
|
|
@@ -84,7 +89,7 @@ module RubyLsp
|
|
|
84
89
|
end
|
|
85
90
|
|
|
86
91
|
def model_name_from_rails(workflow_namespace)
|
|
87
|
-
return unless workflow_namespace &&
|
|
92
|
+
return unless workflow_namespace && rails_client_available?
|
|
88
93
|
|
|
89
94
|
# Cache hits and misses for the life of the LSP process; the set of
|
|
90
95
|
# models rarely changes mid-session. Failures raise past the cache
|
|
@@ -114,8 +119,17 @@ module RubyLsp
|
|
|
114
119
|
constant_entries(association_model_name)
|
|
115
120
|
end
|
|
116
121
|
|
|
122
|
+
# Delegating a request to a disconnected client (ruby-lsp-rails NullClient)
|
|
123
|
+
# never produces a response, so read_response would block forever and the
|
|
124
|
+
# convention fallback would never run.
|
|
125
|
+
def rails_client_available?
|
|
126
|
+
return false unless rails_client
|
|
127
|
+
|
|
128
|
+
!rails_client.respond_to?(:connected?) || rails_client.connected?
|
|
129
|
+
end
|
|
130
|
+
|
|
117
131
|
def association_model_name(model_name, association_name)
|
|
118
|
-
return unless rails_client
|
|
132
|
+
return unless rails_client_available? && rails_client.respond_to?(:association_target)
|
|
119
133
|
|
|
120
134
|
result = rails_client.association_target(model_name: model_name, association_name: association_name)
|
|
121
135
|
response_name(result)
|
|
@@ -189,7 +203,14 @@ module RubyLsp
|
|
|
189
203
|
end
|
|
190
204
|
|
|
191
205
|
def object_method_call?(node)
|
|
192
|
-
message(node) &&
|
|
206
|
+
message(node) && object_chain?(receiver(node))
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def object_chain?(node)
|
|
210
|
+
return false unless node
|
|
211
|
+
return true if object_call?(node)
|
|
212
|
+
|
|
213
|
+
SELF_RETURNING_METHODS.include?(message(node)) && object_chain?(receiver(node))
|
|
193
214
|
end
|
|
194
215
|
|
|
195
216
|
def object_call?(node)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "ruby_lsp/ruby_lsp_rails/server"
|
|
3
|
+
require "ruby_lsp/ruby_lsp_rails/server" unless defined?(::RubyLsp::Rails::ServerAddon)
|
|
4
4
|
|
|
5
5
|
module RubyLsp
|
|
6
6
|
module HasStateMachine
|
|
@@ -13,7 +13,7 @@ module RubyLsp
|
|
|
13
13
|
with_request_error_handling(request) do
|
|
14
14
|
case request
|
|
15
15
|
when "model_for_workflow_namespace"
|
|
16
|
-
send_result(model_for_workflow_namespace(params.fetch("workflow_namespace")))
|
|
16
|
+
send_result(model_for_workflow_namespace(params[:workflow_namespace] || params.fetch("workflow_namespace")))
|
|
17
17
|
else
|
|
18
18
|
raise NotImplementedError, "Unknown request: #{request}"
|
|
19
19
|
end
|