ruby-lsp-rails 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e684ecacd45b09fee18e386a95d0dfa61bd3cce2c64869bf34f711d9d0c2fa3
4
- data.tar.gz: c575d062c88f997967989f1cca84a1241fb6d07750a0535e122112b890e9dd0e
3
+ metadata.gz: 9c4bfe664b0783f9ae11cc912ec6eff3cd8c2d9c5c9c51731a85d0ed7de2fbf1
4
+ data.tar.gz: 1f3f74de8ec6891464b84a8d88fd339e33ce1ddcdc770a6a34177c60d4001ebe
5
5
  SHA512:
6
- metadata.gz: 17c1805f2e1d7363e2734d6983fdba8b11b72e083ff07b0d872745121f9b4c1d20898e439a19c7dc9f179f8729260cf2f90e701e47967d4901576166fe66c420
7
- data.tar.gz: '039f940ff0ea3247316609b379396a7096ada44ed0b4127969223c3277d946bbbd913e106ede27912fc29c53a0e349999231e1561940e5d75ff6adbf0cea1a89'
6
+ metadata.gz: 2e4493fb0f18638b208e3d9f40671846e351670936214420131ae0482fe7d6410f74afc5b808a707dd616471f83233eb201be51a25e29152817daa1ec0380e73
7
+ data.tar.gz: 9eb01978fc74c0d212a65240ff2f5874d38768abf85b647943c7eba0aee84116912a0ebe9c6206ddf84b6ee7b48f60535f1a288cd66c538ff56a40c501adc4ee
@@ -13,6 +13,7 @@ require_relative "hover"
13
13
  require_relative "code_lens"
14
14
  require_relative "document_symbol"
15
15
  require_relative "definition"
16
+ require_relative "indexing_enhancement"
16
17
 
17
18
  module RubyLsp
18
19
  module Rails
@@ -35,6 +36,8 @@ module RubyLsp
35
36
  # Start booting the real client in a background thread. Until this completes, the client will be a NullClient
36
37
  Thread.new { @client = RunnerClient.create_client }
37
38
  register_additional_file_watchers(global_state: global_state, message_queue: message_queue)
39
+
40
+ T.must(@global_state).index.register_enhancement(IndexingEnhancement.new)
38
41
  end
39
42
 
40
43
  sig { override.void }
@@ -77,7 +80,9 @@ module RubyLsp
77
80
 
78
81
  sig do
79
82
  override.params(
80
- response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::Location],
83
+ response_builder: ResponseBuilders::CollectionResponseBuilder[T.any(
84
+ Interface::Location, Interface::LocationLink
85
+ )],
81
86
  uri: URI::Generic,
82
87
  node_context: NodeContext,
83
88
  dispatcher: Prism::Dispatcher,
@@ -17,7 +17,7 @@ module RubyLsp
17
17
  # # Example
18
18
  #
19
19
  # ```ruby
20
- # before_action :foo # <- Go to definition on this symbol will jump to the method if it is defined in the same class
20
+ # before_action :foo # <- Go to definition on this symbol will jump to the method
21
21
  # ```
22
22
  #
23
23
  # Notes for named routes:
@@ -34,7 +34,9 @@ module RubyLsp
34
34
  sig do
35
35
  params(
36
36
  client: RunnerClient,
37
- response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::Location],
37
+ response_builder: RubyLsp::ResponseBuilders::CollectionResponseBuilder[T.any(
38
+ Interface::Location, Interface::LocationLink
39
+ )],
38
40
  node_context: NodeContext,
39
41
  index: RubyIndexer::Index,
40
42
  dispatcher: Prism::Dispatcher,
@@ -0,0 +1,113 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module RubyLsp
5
+ module Rails
6
+ class IndexingEnhancement
7
+ extend T::Sig
8
+ include RubyIndexer::Enhancement
9
+
10
+ sig do
11
+ override.params(
12
+ index: RubyIndexer::Index,
13
+ owner: T.nilable(RubyIndexer::Entry::Namespace),
14
+ node: Prism::CallNode,
15
+ file_path: String,
16
+ ).void
17
+ end
18
+ def on_call_node(index, owner, node, file_path)
19
+ return unless owner
20
+
21
+ name = node.name
22
+
23
+ case name
24
+ when :extend
25
+ handle_concern_extend(index, owner, node)
26
+ when :has_one, :has_many, :belongs_to, :has_and_belongs_to_many
27
+ handle_association(index, owner, node, file_path)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ sig do
34
+ params(
35
+ index: RubyIndexer::Index,
36
+ owner: RubyIndexer::Entry::Namespace,
37
+ node: Prism::CallNode,
38
+ file_path: String,
39
+ ).void
40
+ end
41
+ def handle_association(index, owner, node, file_path)
42
+ arguments = node.arguments&.arguments
43
+ return unless arguments
44
+
45
+ name_arg = arguments.first
46
+
47
+ name = case name_arg
48
+ when Prism::StringNode
49
+ name_arg.content
50
+ when Prism::SymbolNode
51
+ name_arg.value
52
+ end
53
+
54
+ return unless name
55
+
56
+ # Reader
57
+ index.add(RubyIndexer::Entry::Method.new(
58
+ name,
59
+ file_path,
60
+ name_arg.location,
61
+ name_arg.location,
62
+ [],
63
+ [RubyIndexer::Entry::Signature.new([])],
64
+ RubyIndexer::Entry::Visibility::PUBLIC,
65
+ owner,
66
+ ))
67
+
68
+ # Writer
69
+ index.add(RubyIndexer::Entry::Method.new(
70
+ "#{name}=",
71
+ file_path,
72
+ name_arg.location,
73
+ name_arg.location,
74
+ [],
75
+ [RubyIndexer::Entry::Signature.new([RubyIndexer::Entry::RequiredParameter.new(name: name.to_sym)])],
76
+ RubyIndexer::Entry::Visibility::PUBLIC,
77
+ owner,
78
+ ))
79
+ end
80
+
81
+ sig do
82
+ params(
83
+ index: RubyIndexer::Index,
84
+ owner: RubyIndexer::Entry::Namespace,
85
+ node: Prism::CallNode,
86
+ ).void
87
+ end
88
+ def handle_concern_extend(index, owner, node)
89
+ arguments = node.arguments&.arguments
90
+ return unless arguments
91
+
92
+ arguments.each do |node|
93
+ next unless node.is_a?(Prism::ConstantReadNode) || node.is_a?(Prism::ConstantPathNode)
94
+
95
+ module_name = node.full_name
96
+ next unless module_name == "ActiveSupport::Concern"
97
+
98
+ index.register_included_hook(owner.name) do |index, base|
99
+ class_methods_name = "#{owner.name}::ClassMethods"
100
+
101
+ if index.indexed?(class_methods_name)
102
+ singleton = index.existing_or_new_singleton_class(base.name)
103
+ singleton.mixin_operations << RubyIndexer::Entry::Include.new(class_methods_name)
104
+ end
105
+ end
106
+ rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError,
107
+ Prism::ConstantPathNode::MissingNodesInConstantPathError
108
+ # Do nothing
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -84,9 +84,7 @@ module RubyLsp
84
84
  if @wait_thread.alive?
85
85
  $stderr.puts("Ruby LSP Rails is force killing the server")
86
86
  sleep(0.5) # give the server a bit of time if we already issued a shutdown notification
87
-
88
- # Windows does not support the `TERM` signal, so we're forced to use `KILL` here
89
- Process.kill(T.must(Signal.list["KILL"]), @wait_thread.pid)
87
+ force_kill
90
88
  end
91
89
  end
92
90
  end
@@ -149,6 +147,9 @@ module RubyLsp
149
147
  send_message("shutdown")
150
148
  sleep(0.5) # give the server a bit of time to shutdown
151
149
  [@stdin, @stdout, @stderr].each(&:close)
150
+ rescue IOError
151
+ # The server connection may have died
152
+ force_kill
152
153
  end
153
154
 
154
155
  sig { returns(T::Boolean) }
@@ -169,7 +170,7 @@ module RubyLsp
169
170
  read_response
170
171
  end
171
172
 
172
- sig { params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
173
+ sig { overridable.params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
173
174
  def send_message(request, params = nil)
174
175
  message = { method: request }
175
176
  message[:params] = params if params
@@ -180,9 +181,11 @@ module RubyLsp
180
181
  # The server connection died
181
182
  end
182
183
 
183
- alias_method :send_notification, :send_message
184
+ # Notifications are like messages, but one-way, with no response sent back.
185
+ sig { params(request: String, params: T.nilable(T::Hash[Symbol, T.untyped])).void }
186
+ def send_notification(request, params = nil) = send_message(request, params)
184
187
 
185
- sig { returns(T.nilable(T::Hash[Symbol, T.untyped])) }
188
+ sig { overridable.returns(T.nilable(T::Hash[Symbol, T.untyped])) }
186
189
  def read_response
187
190
  headers = @stdout.gets("\r\n\r\n")
188
191
  raise IncompleteMessageError unless headers
@@ -203,6 +206,12 @@ module RubyLsp
203
206
  # The server connection died
204
207
  nil
205
208
  end
209
+
210
+ sig { void }
211
+ def force_kill
212
+ # Windows does not support the `TERM` signal, so we're forced to use `KILL` here
213
+ Process.kill(T.must(Signal.list["KILL"]), @wait_thread.pid)
214
+ end
206
215
  end
207
216
 
208
217
  class NullClient < RunnerClient
@@ -3,6 +3,6 @@
3
3
 
4
4
  module RubyLsp
5
5
  module Rails
6
- VERSION = "0.3.11"
6
+ VERSION = "0.3.12"
7
7
  end
8
8
  end
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.11
4
+ version: 0.3.12
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-19 00:00:00.000000000 Z
11
+ date: 2024-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-lsp
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.17.2
19
+ version: 0.17.12
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 0.18.0
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 0.17.2
29
+ version: 0.17.12
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 0.18.0
@@ -46,6 +46,7 @@ files:
46
46
  - lib/ruby_lsp/ruby_lsp_rails/definition.rb
47
47
  - lib/ruby_lsp/ruby_lsp_rails/document_symbol.rb
48
48
  - lib/ruby_lsp/ruby_lsp_rails/hover.rb
49
+ - lib/ruby_lsp/ruby_lsp_rails/indexing_enhancement.rb
49
50
  - lib/ruby_lsp/ruby_lsp_rails/runner_client.rb
50
51
  - lib/ruby_lsp/ruby_lsp_rails/server.rb
51
52
  - lib/ruby_lsp/ruby_lsp_rails/support/active_support_test_case_helper.rb
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
- rubygems_version: 3.5.15
83
+ rubygems_version: 3.5.16
83
84
  signing_key:
84
85
  specification_version: 4
85
86
  summary: A Ruby LSP addon for Rails