ruby-lsp-rbs_rails 0.1.0
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 +7 -0
- data/.rspec +1 -0
- data/.vscode/extensions.json +7 -0
- data/.vscode/settings.json +34 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +27 -0
- data/Steepfile +9 -0
- data/lib/ruby_lsp/rbs_rails/addon.rb +206 -0
- data/lib/ruby_lsp/rbs_rails/file_writer.rb +30 -0
- data/lib/ruby_lsp/rbs_rails/logger.rb +22 -0
- data/lib/ruby_lsp/rbs_rails/version.rb +7 -0
- data/lib/ruby_lsp/rbs_rails.rb +10 -0
- data/rbs_collection.lock.yaml +284 -0
- data/rbs_collection.yaml +41 -0
- data/sig/gems/language_server-protocol.rbs +11 -0
- data/sig/gems/ruby-lsp.rbs +15 -0
- data/sig/ruby_lsp/rbs_rails/addon.rbs +63 -0
- data/sig/ruby_lsp/rbs_rails/file_writer.rbs +18 -0
- data/sig/ruby_lsp/rbs_rails/logger.rbs +15 -0
- data/sig/ruby_lsp/rbs_rails/version.rbs +7 -0
- data/sig/ruby_lsp/rbs_rails.rbs +8 -0
- data/spec/ruby_lsp/rbs_rails/addon_spec.rb +205 -0
- data/spec/ruby_lsp/rbs_rails/file_writer_spec.rb +59 -0
- data/spec/ruby_lsp/rbs_rails/logger_spec.rb +20 -0
- data/spec/spec_helper.rb +98 -0
- data/spec/test-app/.gitattributes +9 -0
- data/spec/test-app/.gitignore +34 -0
- data/spec/test-app/.ruby-version +1 -0
- data/spec/test-app/Gemfile +18 -0
- data/spec/test-app/Gemfile.lock +234 -0
- data/spec/test-app/README.md +24 -0
- data/spec/test-app/Rakefile +6 -0
- data/spec/test-app/app/assets/images/.keep +0 -0
- data/spec/test-app/app/assets/stylesheets/application.css +10 -0
- data/spec/test-app/app/controllers/application_controller.rb +4 -0
- data/spec/test-app/app/controllers/concerns/.keep +0 -0
- data/spec/test-app/app/helpers/application_helper.rb +2 -0
- data/spec/test-app/app/models/application_record.rb +3 -0
- data/spec/test-app/app/models/blog.rb +3 -0
- data/spec/test-app/app/models/concerns/.keep +0 -0
- data/spec/test-app/app/models/user.rb +2 -0
- data/spec/test-app/app/views/layouts/application.html.erb +27 -0
- data/spec/test-app/app/views/pwa/manifest.json.erb +22 -0
- data/spec/test-app/app/views/pwa/service-worker.js +26 -0
- data/spec/test-app/bin/dev +2 -0
- data/spec/test-app/bin/rails +4 -0
- data/spec/test-app/bin/rake +4 -0
- data/spec/test-app/bin/setup +34 -0
- data/spec/test-app/config/application.rb +42 -0
- data/spec/test-app/config/boot.rb +3 -0
- data/spec/test-app/config/credentials.yml.enc +1 -0
- data/spec/test-app/config/database.yml +32 -0
- data/spec/test-app/config/environment.rb +5 -0
- data/spec/test-app/config/environments/development.rb +51 -0
- data/spec/test-app/config/environments/production.rb +67 -0
- data/spec/test-app/config/environments/test.rb +42 -0
- data/spec/test-app/config/initializers/assets.rb +7 -0
- data/spec/test-app/config/initializers/content_security_policy.rb +25 -0
- data/spec/test-app/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/test-app/config/initializers/inflections.rb +16 -0
- data/spec/test-app/config/locales/en.yml +31 -0
- data/spec/test-app/config/puma.rb +38 -0
- data/spec/test-app/config/routes.rb +14 -0
- data/spec/test-app/config.ru +6 -0
- data/spec/test-app/db/migrate/20250907043524_create_users.rb +10 -0
- data/spec/test-app/db/migrate/20250907175033_create_blogs.rb +10 -0
- data/spec/test-app/db/schema.rb +30 -0
- data/spec/test-app/db/seeds.rb +9 -0
- data/spec/test-app/lib/tasks/.keep +0 -0
- data/spec/test-app/log/.keep +0 -0
- data/spec/test-app/public/400.html +114 -0
- data/spec/test-app/public/404.html +114 -0
- data/spec/test-app/public/406-unsupported-browser.html +114 -0
- data/spec/test-app/public/422.html +114 -0
- data/spec/test-app/public/500.html +114 -0
- data/spec/test-app/public/icon.png +0 -0
- data/spec/test-app/public/icon.svg +3 -0
- data/spec/test-app/public/robots.txt +1 -0
- data/spec/test-app/script/.keep +0 -0
- data/spec/test-app/storage/.keep +0 -0
- data/spec/test-app/test/controllers/.keep +0 -0
- data/spec/test-app/test/fixtures/blogs.yml +9 -0
- data/spec/test-app/test/fixtures/files/.keep +0 -0
- data/spec/test-app/test/fixtures/users.yml +9 -0
- data/spec/test-app/test/helpers/.keep +0 -0
- data/spec/test-app/test/integration/.keep +0 -0
- data/spec/test-app/test/models/.keep +0 -0
- data/spec/test-app/test/models/blog_test.rb +7 -0
- data/spec/test-app/test/models/user_test.rb +7 -0
- data/spec/test-app/test/test_helper.rb +15 -0
- data/spec/test-app/tmp/.keep +0 -0
- data/spec/test-app/tmp/pids/.keep +0 -0
- data/spec/test-app/tmp/storage/.keep +0 -0
- data/spec/test-app/vendor/.keep +0 -0
- metadata +211 -0
@@ -0,0 +1,284 @@
|
|
1
|
+
---
|
2
|
+
path: ".gem_rbs_collection"
|
3
|
+
gems:
|
4
|
+
- name: actionpack
|
5
|
+
version: '7.2'
|
6
|
+
source:
|
7
|
+
type: git
|
8
|
+
name: ruby/gem_rbs_collection
|
9
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
10
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
11
|
+
repo_dir: gems
|
12
|
+
- name: actionview
|
13
|
+
version: '6.0'
|
14
|
+
source:
|
15
|
+
type: git
|
16
|
+
name: ruby/gem_rbs_collection
|
17
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
18
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
19
|
+
repo_dir: gems
|
20
|
+
- name: activemodel
|
21
|
+
version: '7.1'
|
22
|
+
source:
|
23
|
+
type: git
|
24
|
+
name: ruby/gem_rbs_collection
|
25
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
26
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
27
|
+
repo_dir: gems
|
28
|
+
- name: activerecord
|
29
|
+
version: '8.0'
|
30
|
+
source:
|
31
|
+
type: git
|
32
|
+
name: ruby/gem_rbs_collection
|
33
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
34
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
35
|
+
repo_dir: gems
|
36
|
+
- name: activesupport
|
37
|
+
version: '7.0'
|
38
|
+
source:
|
39
|
+
type: git
|
40
|
+
name: ruby/gem_rbs_collection
|
41
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
42
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
43
|
+
repo_dir: gems
|
44
|
+
- name: base64
|
45
|
+
version: 0.3.0
|
46
|
+
source:
|
47
|
+
type: rubygems
|
48
|
+
- name: benchmark
|
49
|
+
version: '0'
|
50
|
+
source:
|
51
|
+
type: stdlib
|
52
|
+
- name: bigdecimal
|
53
|
+
version: '3.1'
|
54
|
+
source:
|
55
|
+
type: git
|
56
|
+
name: ruby/gem_rbs_collection
|
57
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
58
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
59
|
+
repo_dir: gems
|
60
|
+
- name: cgi
|
61
|
+
version: '0'
|
62
|
+
source:
|
63
|
+
type: stdlib
|
64
|
+
- name: concurrent-ruby
|
65
|
+
version: '1.1'
|
66
|
+
source:
|
67
|
+
type: git
|
68
|
+
name: ruby/gem_rbs_collection
|
69
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
70
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
71
|
+
repo_dir: gems
|
72
|
+
- name: connection_pool
|
73
|
+
version: '2.4'
|
74
|
+
source:
|
75
|
+
type: git
|
76
|
+
name: ruby/gem_rbs_collection
|
77
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
78
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
79
|
+
repo_dir: gems
|
80
|
+
- name: date
|
81
|
+
version: '0'
|
82
|
+
source:
|
83
|
+
type: stdlib
|
84
|
+
- name: dbm
|
85
|
+
version: '0'
|
86
|
+
source:
|
87
|
+
type: stdlib
|
88
|
+
- name: delegate
|
89
|
+
version: '0'
|
90
|
+
source:
|
91
|
+
type: stdlib
|
92
|
+
- name: digest
|
93
|
+
version: '0'
|
94
|
+
source:
|
95
|
+
type: stdlib
|
96
|
+
- name: erb
|
97
|
+
version: '0'
|
98
|
+
source:
|
99
|
+
type: stdlib
|
100
|
+
- name: fileutils
|
101
|
+
version: '0'
|
102
|
+
source:
|
103
|
+
type: stdlib
|
104
|
+
- name: forwardable
|
105
|
+
version: '0'
|
106
|
+
source:
|
107
|
+
type: stdlib
|
108
|
+
- name: i18n
|
109
|
+
version: '1.10'
|
110
|
+
source:
|
111
|
+
type: git
|
112
|
+
name: ruby/gem_rbs_collection
|
113
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
114
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
115
|
+
repo_dir: gems
|
116
|
+
- name: io-console
|
117
|
+
version: '0'
|
118
|
+
source:
|
119
|
+
type: stdlib
|
120
|
+
- name: json
|
121
|
+
version: '0'
|
122
|
+
source:
|
123
|
+
type: stdlib
|
124
|
+
- name: logger
|
125
|
+
version: '0'
|
126
|
+
source:
|
127
|
+
type: stdlib
|
128
|
+
- name: minitest
|
129
|
+
version: '5.25'
|
130
|
+
source:
|
131
|
+
type: git
|
132
|
+
name: ruby/gem_rbs_collection
|
133
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
134
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
135
|
+
repo_dir: gems
|
136
|
+
- name: monitor
|
137
|
+
version: '0'
|
138
|
+
source:
|
139
|
+
type: stdlib
|
140
|
+
- name: nokogiri
|
141
|
+
version: '1.11'
|
142
|
+
source:
|
143
|
+
type: git
|
144
|
+
name: ruby/gem_rbs_collection
|
145
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
146
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
147
|
+
repo_dir: gems
|
148
|
+
- name: openssl
|
149
|
+
version: '0'
|
150
|
+
source:
|
151
|
+
type: stdlib
|
152
|
+
- name: optparse
|
153
|
+
version: '0'
|
154
|
+
source:
|
155
|
+
type: stdlib
|
156
|
+
- name: pathname
|
157
|
+
version: '0'
|
158
|
+
source:
|
159
|
+
type: stdlib
|
160
|
+
- name: pp
|
161
|
+
version: '0'
|
162
|
+
source:
|
163
|
+
type: stdlib
|
164
|
+
- name: prettyprint
|
165
|
+
version: '0'
|
166
|
+
source:
|
167
|
+
type: stdlib
|
168
|
+
- name: prism
|
169
|
+
version: 1.2.0
|
170
|
+
source:
|
171
|
+
type: rubygems
|
172
|
+
- name: pstore
|
173
|
+
version: '0'
|
174
|
+
source:
|
175
|
+
type: stdlib
|
176
|
+
- name: psych
|
177
|
+
version: '0'
|
178
|
+
source:
|
179
|
+
type: stdlib
|
180
|
+
- name: rack
|
181
|
+
version: '2.2'
|
182
|
+
source:
|
183
|
+
type: git
|
184
|
+
name: ruby/gem_rbs_collection
|
185
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
186
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
187
|
+
repo_dir: gems
|
188
|
+
- name: rails-dom-testing
|
189
|
+
version: '2.0'
|
190
|
+
source:
|
191
|
+
type: git
|
192
|
+
name: ruby/gem_rbs_collection
|
193
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
194
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
195
|
+
repo_dir: gems
|
196
|
+
- name: rails-html-sanitizer
|
197
|
+
version: '1.6'
|
198
|
+
source:
|
199
|
+
type: git
|
200
|
+
name: ruby/gem_rbs_collection
|
201
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
202
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
203
|
+
repo_dir: gems
|
204
|
+
- name: railties
|
205
|
+
version: '6.0'
|
206
|
+
source:
|
207
|
+
type: git
|
208
|
+
name: ruby/gem_rbs_collection
|
209
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
210
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
211
|
+
repo_dir: gems
|
212
|
+
- name: rake
|
213
|
+
version: '13.0'
|
214
|
+
source:
|
215
|
+
type: git
|
216
|
+
name: ruby/gem_rbs_collection
|
217
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
218
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
219
|
+
repo_dir: gems
|
220
|
+
- name: rbs
|
221
|
+
version: 3.9.5
|
222
|
+
source:
|
223
|
+
type: rubygems
|
224
|
+
- name: rbs_rails
|
225
|
+
version: 0.12.1
|
226
|
+
source:
|
227
|
+
type: rubygems
|
228
|
+
- name: rdoc
|
229
|
+
version: '0'
|
230
|
+
source:
|
231
|
+
type: stdlib
|
232
|
+
- name: securerandom
|
233
|
+
version: '0'
|
234
|
+
source:
|
235
|
+
type: stdlib
|
236
|
+
- name: singleton
|
237
|
+
version: '0'
|
238
|
+
source:
|
239
|
+
type: stdlib
|
240
|
+
- name: socket
|
241
|
+
version: '0'
|
242
|
+
source:
|
243
|
+
type: stdlib
|
244
|
+
- name: stringio
|
245
|
+
version: '0'
|
246
|
+
source:
|
247
|
+
type: stdlib
|
248
|
+
- name: tempfile
|
249
|
+
version: '0'
|
250
|
+
source:
|
251
|
+
type: stdlib
|
252
|
+
- name: thor
|
253
|
+
version: '1.2'
|
254
|
+
source:
|
255
|
+
type: git
|
256
|
+
name: ruby/gem_rbs_collection
|
257
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
258
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
259
|
+
repo_dir: gems
|
260
|
+
- name: time
|
261
|
+
version: '0'
|
262
|
+
source:
|
263
|
+
type: stdlib
|
264
|
+
- name: timeout
|
265
|
+
version: '0'
|
266
|
+
source:
|
267
|
+
type: stdlib
|
268
|
+
- name: tsort
|
269
|
+
version: '0'
|
270
|
+
source:
|
271
|
+
type: stdlib
|
272
|
+
- name: tzinfo
|
273
|
+
version: '2.0'
|
274
|
+
source:
|
275
|
+
type: git
|
276
|
+
name: ruby/gem_rbs_collection
|
277
|
+
revision: 1c0e3f62ff100436becf905ec3ae30a691019384
|
278
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
279
|
+
repo_dir: gems
|
280
|
+
- name: uri
|
281
|
+
version: '0'
|
282
|
+
source:
|
283
|
+
type: stdlib
|
284
|
+
gemfile_lock_path: Gemfile.lock
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
6
|
+
revision: main
|
7
|
+
repo_dir: gems
|
8
|
+
|
9
|
+
# You can specify local directories as sources also.
|
10
|
+
# - type: local
|
11
|
+
# path: path/to/your/local/repository
|
12
|
+
|
13
|
+
# A directory to install the downloaded RBSs
|
14
|
+
path: .gem_rbs_collection
|
15
|
+
|
16
|
+
gems:
|
17
|
+
- name: forwardable
|
18
|
+
|
19
|
+
# rbs_rails conflicts with parser gem because rbs_rails distributes types for parser gem. This is a bug of rbs_rails.
|
20
|
+
- name: parser
|
21
|
+
ignore: true
|
22
|
+
|
23
|
+
# Ignore dependencies from spec/test-app
|
24
|
+
- name: actionmailer
|
25
|
+
ignore: true
|
26
|
+
- name: actioncable
|
27
|
+
ignore: true
|
28
|
+
- name: actiontext
|
29
|
+
ignore: true
|
30
|
+
- name: activejob
|
31
|
+
ignore: true
|
32
|
+
- name: activestorage
|
33
|
+
ignore: true
|
34
|
+
- name: mail
|
35
|
+
ignore: true
|
36
|
+
- name: marcel
|
37
|
+
ignore: true
|
38
|
+
- name: mini_mime
|
39
|
+
ignore: true
|
40
|
+
- name: sqlite3
|
41
|
+
ignore: true
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RubyLsp
|
2
|
+
class Addon
|
3
|
+
end
|
4
|
+
|
5
|
+
class GlobalState
|
6
|
+
attr_reader workspace_path: String
|
7
|
+
end
|
8
|
+
|
9
|
+
class Message
|
10
|
+
end
|
11
|
+
|
12
|
+
class Notification < Message
|
13
|
+
def self.window_log_message: (String message, ?type: Integer) -> Notification
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated from lib/ruby_lsp/rbs_rails/addon.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RubyLsp
|
4
|
+
module RbsRails
|
5
|
+
class Addon < ::RubyLsp::Addon
|
6
|
+
include LanguageServer::Protocol::Constant
|
7
|
+
|
8
|
+
attr_reader global_state: GlobalState
|
9
|
+
|
10
|
+
attr_reader logger: Logger
|
11
|
+
|
12
|
+
# @rbs global_state: GlobalState
|
13
|
+
# @rbs message_queue: Thread::Queue
|
14
|
+
def activate: (GlobalState global_state, Thread::Queue message_queue) -> void
|
15
|
+
|
16
|
+
def deactivate: () -> void
|
17
|
+
|
18
|
+
def name: () -> String
|
19
|
+
|
20
|
+
def version: () -> String
|
21
|
+
|
22
|
+
# @rbs changes: Array[{ uri: String, type: Integer }]
|
23
|
+
def workspace_did_change_watched_files: (Array[{ uri: String, type: Integer }] changes) -> void
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
@workspace_path: Pathname?
|
28
|
+
|
29
|
+
def workspace_path: () -> Pathname
|
30
|
+
|
31
|
+
# Load Rails application and enable reloading
|
32
|
+
def load_application: () -> void
|
33
|
+
|
34
|
+
def install_hooks: () -> void
|
35
|
+
|
36
|
+
def load_rbs_rails_config: () -> void
|
37
|
+
|
38
|
+
def config: () -> ::RbsRails::CLI::Configuration
|
39
|
+
|
40
|
+
# @rbs uri: String
|
41
|
+
def generate_signature: (String uri) -> void
|
42
|
+
|
43
|
+
def generate_all_model_signatures: () -> void
|
44
|
+
|
45
|
+
def generate_path_helpers_signature: () -> void
|
46
|
+
|
47
|
+
# @rbs klass: Class
|
48
|
+
def generate_signature0: (Class klass) -> void
|
49
|
+
|
50
|
+
# @rbs uri: String
|
51
|
+
def delete_signature: (String uri) -> void
|
52
|
+
|
53
|
+
# @rbs uri: String
|
54
|
+
def uri_to_path: (String uri) -> Pathname?
|
55
|
+
|
56
|
+
# @rbs path: Pathname
|
57
|
+
def constantize: (Pathname path) -> Class?
|
58
|
+
|
59
|
+
# @rbs klass: Class
|
60
|
+
def get_rbs_path_for_model: (Class klass) -> Pathname
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Generated from lib/ruby_lsp/rbs_rails/file_writer.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RubyLsp
|
4
|
+
module RbsRails
|
5
|
+
# To avoid unnecessary type reloading by type checkers and other utilities,
|
6
|
+
# FileWriter modifies the target file only if its content has been changed.
|
7
|
+
#
|
8
|
+
# See https://github.com/pocke/rbs_rails/pull/346
|
9
|
+
class FileWriter
|
10
|
+
attr_reader path: Pathname
|
11
|
+
|
12
|
+
# @rbs path: Pathname
|
13
|
+
def initialize: (Pathname path) -> void
|
14
|
+
|
15
|
+
def write: (untyped content) -> void
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Generated from lib/ruby_lsp/rbs_rails/logger.rb with RBS::Inline
|
2
|
+
|
3
|
+
module RubyLsp
|
4
|
+
module RbsRails
|
5
|
+
class Logger
|
6
|
+
attr_reader message_queue: Thread::Queue
|
7
|
+
|
8
|
+
# @rbs message_queue: Thread::Queue
|
9
|
+
def initialize: (Thread::Queue message_queue) -> void
|
10
|
+
|
11
|
+
# @rbs message: String
|
12
|
+
def info: (String message) -> void
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,205 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ruby_lsp/global_state"
|
4
|
+
require "ruby_lsp/rbs_rails/addon"
|
5
|
+
|
6
|
+
include LanguageServer::Protocol::Constant # rubocop:disable Style/MixinUsage
|
7
|
+
|
8
|
+
RSpec.describe RubyLsp::RbsRails::Addon do
|
9
|
+
before :all do # rubocop:disable RSpec/BeforeAfterAll
|
10
|
+
test_app_path = Pathname.new(__FILE__).dirname.join("../test-app/").expand_path.to_s
|
11
|
+
system("bundle exec rails db:migrate", chdir: test_app_path, exception: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#activate" do
|
15
|
+
subject { described_class.new.activate(global_state, message_queue) }
|
16
|
+
|
17
|
+
let(:global_state) { instance_double(RubyLsp::GlobalState, workspace_path: workspace_path) }
|
18
|
+
let(:message_queue) { Thread::Queue.new }
|
19
|
+
|
20
|
+
context "when Rails application is not found" do
|
21
|
+
let(:workspace_path) { "/" }
|
22
|
+
|
23
|
+
it "skips activation" do
|
24
|
+
subject
|
25
|
+
|
26
|
+
log = message_queue.pop
|
27
|
+
expect(log.params.message).to eq "rbs_rails: Rails application not found. Skip to activate rbs_rails addon."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when Rails application found" do
|
32
|
+
let(:workspace_path) { Pathname.new(__FILE__).dirname.join("../test-app/").expand_path.to_s }
|
33
|
+
|
34
|
+
it "activates Rails app" do
|
35
|
+
subject
|
36
|
+
|
37
|
+
expect(message_queue).to be_empty
|
38
|
+
expect(Rails.application).to be_a(Rails::Application)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#workspace_did_change_watched_files" do
|
44
|
+
subject { addon.workspace_did_change_watched_files(changes) }
|
45
|
+
|
46
|
+
before { addon.activate(global_state, message_queue) }
|
47
|
+
|
48
|
+
after do
|
49
|
+
signature_path = Pathname.new("#{workspace_path}/sig/rbs_rails")
|
50
|
+
signature_path.rmtree if signature_path.exist?
|
51
|
+
|
52
|
+
RbsRails::CLI::Configuration.instance.send(:initialize)
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:addon) { described_class.new }
|
56
|
+
let(:global_state) { instance_double(RubyLsp::GlobalState, workspace_path: workspace_path) }
|
57
|
+
let(:message_queue) { Thread::Queue.new }
|
58
|
+
let(:workspace_path) { Pathname.new(__FILE__).dirname.join("../test-app/").expand_path.to_s }
|
59
|
+
|
60
|
+
context "when file created event is received" do
|
61
|
+
let(:changes) do
|
62
|
+
[
|
63
|
+
{ uri: "file://#{workspace_path}/#{filename}", type: FileChangeType::CREATED }
|
64
|
+
]
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when a model file is created" do
|
68
|
+
let(:filename) { "app/models/user.rb" }
|
69
|
+
let(:rbs_path) { Pathname.new("#{workspace_path}/sig/rbs_rails/app/models/user.rbs") }
|
70
|
+
|
71
|
+
context "when the model is not ignored" do
|
72
|
+
it "generates the corresponding RBS file" do
|
73
|
+
subject
|
74
|
+
|
75
|
+
expect(rbs_path).to exist
|
76
|
+
content = rbs_path.read
|
77
|
+
expect(content).to include("class ::User")
|
78
|
+
expect(content).to include("def name: () -> ::String?")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when the model is ignored" do
|
83
|
+
before do
|
84
|
+
RbsRails::CLI::Configuration.instance.ignore_model_if { |klass| klass.name == "User" }
|
85
|
+
end
|
86
|
+
|
87
|
+
it "generates no RBS files" do
|
88
|
+
subject
|
89
|
+
|
90
|
+
rbs_files = Pathname.new("#{workspace_path}/sig/").glob("**/*.rbs")
|
91
|
+
expect(rbs_files).to be_empty
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "when the model is abstract" do
|
96
|
+
let(:filename) { "app/models/application_record.rb" }
|
97
|
+
|
98
|
+
it "generates no RBS files" do
|
99
|
+
subject
|
100
|
+
|
101
|
+
rbs_files = Pathname.new("#{workspace_path}/sig/").glob("**/*.rbs")
|
102
|
+
expect(rbs_files).to be_empty
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when db/schema.rb is created" do
|
108
|
+
let(:filename) { "db/schema.rb" }
|
109
|
+
|
110
|
+
it "generates RBS files for all models" do
|
111
|
+
subject
|
112
|
+
|
113
|
+
rbs_files = Pathname.new("#{workspace_path}/sig/").glob("**/*.rbs").map(&:to_s)
|
114
|
+
expect(rbs_files).to contain_exactly("#{workspace_path}/sig/rbs_rails/app/models/user.rbs",
|
115
|
+
"#{workspace_path}/sig/rbs_rails/app/models/blog.rbs")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when config/routes.rb is created" do
|
120
|
+
let(:filename) { "config/routes.rb" }
|
121
|
+
let(:rbs_path) { Pathname.new("#{workspace_path}/sig/rbs_rails/path_helpers.rbs") }
|
122
|
+
|
123
|
+
it "generates path_helpers.rbs" do
|
124
|
+
subject
|
125
|
+
|
126
|
+
expect(rbs_path).to exist
|
127
|
+
content = rbs_path.read
|
128
|
+
expect(content).to include("interface ::_RbsRailsPathHelpers")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "when config/routes/*.rb is created" do
|
133
|
+
let(:filename) { "config/routes/api.rb" }
|
134
|
+
let(:rbs_path) { Pathname.new("#{workspace_path}/sig/rbs_rails/path_helpers.rbs") }
|
135
|
+
|
136
|
+
it "generates path_helpers.rbs" do
|
137
|
+
subject
|
138
|
+
|
139
|
+
expect(rbs_path).to exist
|
140
|
+
content = rbs_path.read
|
141
|
+
expect(content).to include("interface ::_RbsRailsPathHelpers")
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "when any other file is created" do
|
146
|
+
let(:filename) { "app/controllers/users_controller.rb" }
|
147
|
+
|
148
|
+
it "generates no RBS files" do
|
149
|
+
subject
|
150
|
+
|
151
|
+
rbs_files = Pathname.new("#{workspace_path}/sig/").glob("**/*.rbs")
|
152
|
+
expect(rbs_files).to be_empty
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when file changed event is received" do
|
158
|
+
let(:changes) do
|
159
|
+
[
|
160
|
+
{ uri: "file://#{workspace_path}/app/models/user.rb", type: FileChangeType::CHANGED }
|
161
|
+
]
|
162
|
+
end
|
163
|
+
let(:rbs_path) { Pathname.new("#{workspace_path}/sig/rbs_rails/app/models/user.rbs") }
|
164
|
+
|
165
|
+
it "generates the corresponding RBS file" do
|
166
|
+
subject
|
167
|
+
|
168
|
+
expect(rbs_path).to exist
|
169
|
+
content = rbs_path.read
|
170
|
+
expect(content).to include("class ::User")
|
171
|
+
expect(content).to include("def name: () -> ::String?")
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when file deleted event is received" do
|
176
|
+
let(:changes) do
|
177
|
+
[
|
178
|
+
{ uri: "file://#{workspace_path}/app/models/user.rb", type: FileChangeType::DELETED }
|
179
|
+
]
|
180
|
+
end
|
181
|
+
let(:rbs_path) { Pathname.new("#{workspace_path}/sig/rbs_rails/app/models/user.rbs") }
|
182
|
+
|
183
|
+
context "when the RBS file corresponding to the deleted Ruby file exists" do
|
184
|
+
before do
|
185
|
+
rbs_path.parent.mkpath
|
186
|
+
rbs_path.write("") # Create a dummy RBS file
|
187
|
+
end
|
188
|
+
|
189
|
+
it "deletes the corresponding RBS file" do
|
190
|
+
subject
|
191
|
+
|
192
|
+
expect(rbs_path).not_to exist
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context "when the RBS file corresponding to the deleted Ruby file does not exist" do
|
197
|
+
it "does not raise an error" do
|
198
|
+
subject
|
199
|
+
|
200
|
+
expect(rbs_path).not_to exist
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|