tapioca 0.16.9 → 0.16.11

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: b2d6abd53e84e3b22cc6045597788c98d8f9571f486976baa8db4e5beb6ccd10
4
- data.tar.gz: 5aa9162275489d2280f07419f74a4243c9ee813f922dd367e6260bae0fa37331
3
+ metadata.gz: 05e19aeab9d997df21ef0b042afe97b1fdcca0b7ce148ecb4f05b0d14b792294
4
+ data.tar.gz: '09a81f179ccc96606f97bfffe3b07a113315ace4adf5d312998f6caae674cd6e'
5
5
  SHA512:
6
- metadata.gz: 4fd946bacca4a56fe9f9befaa65404393719cacedf4877ce2e8ba0d9d5ab150d9957bea7298783a04e456170086b035b06b42b0312bc2840e1465631259801a1
7
- data.tar.gz: '0825b9451bed3958b7132008993675de624753d41d5b7b267b50e8b7cf2900f344e5c666ac7726686ebfe9c997592dec6c02b5b2e1d14b144cdbaf837daeac08'
6
+ metadata.gz: ec69dd3c33275760ebd701d92335da1d0afd7da6e8908887ef3622a836fad09d3e1752f2dedab1efc20fb805065968cea6ec7980cc0abd4561318529a45a6559
7
+ data.tar.gz: 1258bd043e9edb53e08afcc78fecdcbc5cc228d0a069beb31c4b2c3ef818d894d16751e2aa24f8e1a6c0b7eb144cc7cb47aba1aa834fa86a6502dc1bd9577649
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.23.1", "< 0.24")
4
+ RubyLsp::Addon.depend_on_ruby_lsp!(">= 0.23.10", "< 0.24")
5
5
 
6
6
  begin
7
7
  # The Tapioca add-on depends on the Rails add-on to add a runtime component to the runtime server. We can allow the
@@ -53,8 +53,11 @@ module RubyLsp
53
53
  workspace_path: @global_state.workspace_path,
54
54
  )
55
55
 
56
+ send_usage_telemetry("activated")
56
57
  run_gem_rbi_check
57
58
  rescue IncompatibleApiError
59
+ send_usage_telemetry("incompatible_api_error")
60
+
58
61
  # The requested version for the Rails add-on no longer matches. We need to upgrade and fix the breaking
59
62
  # changes
60
63
  @outgoing_queue << Notification.window_log_message(
@@ -75,12 +78,12 @@ module RubyLsp
75
78
 
76
79
  sig { override.returns(String) }
77
80
  def version
78
- "0.1.1"
81
+ "0.1.3"
79
82
  end
80
83
 
81
84
  sig { params(changes: T::Array[{ uri: String, type: Integer }]).void }
82
85
  def workspace_did_change_watched_files(changes)
83
- return unless T.must(@global_state).enabled_feature?(:tapiocaAddon)
86
+ return unless @global_state&.enabled_feature?(:tapiocaAddon)
84
87
  return unless @rails_runner_client.connected?
85
88
 
86
89
  has_route_change = T.let(false, T::Boolean)
@@ -89,11 +92,10 @@ module RubyLsp
89
92
 
90
93
  constants = changes.flat_map do |change|
91
94
  path = URI(change[:uri]).to_standardized_path
92
- next if path.end_with?("_test.rb", "_spec.rb")
93
95
  next unless file_updated?(change, path)
94
96
 
95
- if File.fnmatch?("**/tapioca/**/compilers/**/*.rb", path, File::FNM_PATHNAME)
96
- needs_compiler_reload = true
97
+ if File.fnmatch("**/fixtures/**/*.yml{,.erb}", path, File::FNM_PATHNAME | File::FNM_EXTGLOB)
98
+ has_fixtures_change = true
97
99
  next
98
100
  end
99
101
 
@@ -102,9 +104,10 @@ module RubyLsp
102
104
  next
103
105
  end
104
106
 
105
- # NOTE: We only get notification for fixtures if ruby-lsp-rails is v0.3.31 or higher
106
- if File.fnmatch("**/fixtures/**/*.yml{,.erb}", path, File::FNM_PATHNAME | File::FNM_EXTGLOB)
107
- has_fixtures_change = true
107
+ next if File.fnmatch?("**/{test,spec,features}/**/*", path, File::FNM_PATHNAME | File::FNM_EXTGLOB)
108
+
109
+ if File.fnmatch?("**/tapioca/**/compilers/**/*.rb", path, File::FNM_PATHNAME)
110
+ needs_compiler_reload = true
108
111
  next
109
112
  end
110
113
 
@@ -124,19 +127,22 @@ module RubyLsp
124
127
  @rails_runner_client.delegate_notification(
125
128
  server_addon_name: "Tapioca",
126
129
  request_name: "reload_workspace_compilers",
127
- workspace_path: T.must(@global_state).workspace_path,
130
+ workspace_path: @global_state.workspace_path,
128
131
  )
129
132
  end
130
133
 
131
134
  if has_route_change
135
+ send_usage_telemetry("route_dsl")
132
136
  @rails_runner_client.delegate_notification(server_addon_name: "Tapioca", request_name: "route_dsl")
133
137
  end
134
138
 
135
139
  if has_fixtures_change
140
+ send_usage_telemetry("fixtures_dsl")
136
141
  @rails_runner_client.delegate_notification(server_addon_name: "Tapioca", request_name: "fixtures_dsl")
137
142
  end
138
143
 
139
144
  if constants.any?
145
+ send_usage_telemetry("dsl")
140
146
  @rails_runner_client.delegate_notification(
141
147
  server_addon_name: "Tapioca",
142
148
  request_name: "dsl",
@@ -147,6 +153,25 @@ module RubyLsp
147
153
 
148
154
  private
149
155
 
156
+ sig { params(feature_name: String).void }
157
+ def send_usage_telemetry(feature_name)
158
+ return unless @outgoing_queue && @global_state
159
+
160
+ # Telemetry is not captured by default even if events are produced by the server
161
+ # See https://github.com/Shopify/ruby-lsp/tree/main/vscode#telemetry
162
+ @outgoing_queue << Notification.telemetry({
163
+ eventName: "tapioca_addon.feature_usage",
164
+ type: "data",
165
+ data: {
166
+ type: "counter",
167
+ attributes: {
168
+ label: feature_name,
169
+ machineId: @global_state.telemetry_machine_id,
170
+ },
171
+ },
172
+ })
173
+ end
174
+
150
175
  sig { params(change: T::Hash[Symbol, T.untyped], path: String).returns(T::Boolean) }
151
176
  def file_updated?(change, path)
152
177
  case change[:type]
@@ -62,11 +62,13 @@ module RubyLsp
62
62
  def dsl(constants, *args)
63
63
  load("tapioca/cli.rb") # Reload the CLI to reset thor defaults between requests
64
64
 
65
+ ::Tapioca::Cli.addon_mode!
66
+
65
67
  # Order here is important to avoid having Thor confuse arguments. Do not put an array argument at the end before
66
68
  # the list of constants
67
69
  arguments = ["dsl"]
68
70
  arguments.concat(args)
69
- arguments.push("--lsp_addon", "--workers=1")
71
+ arguments.push("--workers=1")
70
72
  arguments.concat(constants)
71
73
 
72
74
  ::Tapioca::Cli.start(arguments)
data/lib/tapioca/cli.rb CHANGED
@@ -143,11 +143,6 @@ module Tapioca
143
143
  type: :hash,
144
144
  desc: "Options to pass to the DSL compilers",
145
145
  default: {}
146
- option :lsp_addon,
147
- type: :boolean,
148
- desc: "Generate DSL RBIs from the LSP add-on. Internal to Tapioca and not intended for end-users",
149
- default: false,
150
- hide: true
151
146
  def dsl(*constant_or_paths)
152
147
  set_environment(options)
153
148
 
@@ -170,7 +165,7 @@ module Tapioca
170
165
  app_root: options[:app_root],
171
166
  halt_upon_load_error: options[:halt_upon_load_error],
172
167
  compiler_options: options[:compiler_options],
173
- lsp_addon: options[:lsp_addon],
168
+ lsp_addon: self.class.addon_mode,
174
169
  }
175
170
 
176
171
  command = if options[:verify]
@@ -379,9 +374,22 @@ module Tapioca
379
374
  end
380
375
 
381
376
  no_commands do
377
+ @addon_mode = false
378
+
382
379
  class << self
380
+ extend T::Sig
381
+
382
+ # Indicates that we are running from the LSP, set using the `addon_mode!` method
383
+ attr_reader :addon_mode
384
+
385
+ sig { void }
386
+ def addon_mode!
387
+ @addon_mode = true
388
+ end
389
+
390
+ sig { returns(T::Boolean) }
383
391
  def exit_on_failure?
384
- true
392
+ !@addon_mode
385
393
  end
386
394
  end
387
395
  end
@@ -131,15 +131,22 @@ module Tapioca
131
131
 
132
132
  sig { returns(Tapioca::Dsl::Pipeline) }
133
133
  def create_pipeline
134
+ error_handler = if @lsp_addon
135
+ ->(error) {
136
+ say(error)
137
+ }
138
+ else
139
+ ->(error) {
140
+ say_error(error, :bold, :red)
141
+ }
142
+ end
134
143
  Tapioca::Dsl::Pipeline.new(
135
144
  requested_constants:
136
145
  constantize(@requested_constants) + constantize(constants_from_requested_paths, ignore_missing: true),
137
146
  requested_paths: @requested_paths,
138
147
  requested_compilers: constantize_compilers(@only),
139
148
  excluded_compilers: constantize_compilers(@exclude),
140
- error_handler: ->(error) {
141
- say_error(error, :bold, :red)
142
- },
149
+ error_handler: error_handler,
143
150
  skipped_constants: constantize(@skip_constant, ignore_missing: true),
144
151
  number_of_workers: @number_of_workers,
145
152
  compiler_options: @compiler_options,
@@ -78,6 +78,7 @@ module Tapioca
78
78
  No classes/modules can be matched for RBI generation.
79
79
  Please check that the requested classes/modules include processable DSL methods.
80
80
  ERROR
81
+ raise Thor::Error, ""
81
82
  end
82
83
 
83
84
  if defined?(::ActiveRecord::Base) && constants_to_process.any? { |c| ::ActiveRecord::Base > c }
@@ -94,8 +95,12 @@ module Tapioca
94
95
  blk.call(constant, rbi)
95
96
  end
96
97
 
97
- errors.each do |msg|
98
- report_error(msg)
98
+ if errors.any?
99
+ errors.each do |msg|
100
+ report_error(msg)
101
+ end
102
+
103
+ raise Thor::Error, ""
99
104
  end
100
105
 
101
106
  result.compact
@@ -216,11 +221,10 @@ module Tapioca
216
221
  file
217
222
  end
218
223
 
219
- sig { params(error: String).returns(T.noreturn) }
224
+ sig { params(error: String).void }
220
225
  def report_error(error)
221
226
  handler = error_handler
222
227
  handler.call(error)
223
- exit(1)
224
228
  end
225
229
 
226
230
  sig { void }
@@ -14,11 +14,10 @@ module Tapioca
14
14
  sig { override.params(event: ScopeNodeAdded).void }
15
15
  def on_scope(event)
16
16
  symbol = event.symbol
17
- return if @pipeline.symbol_in_payload?(symbol) && event.node.empty?
17
+ constant = event.constant
18
18
 
19
19
  prefix = symbol == "Object" ? "" : symbol
20
20
 
21
- constant = event.constant
22
21
  constants_of(constant).sort.uniq.map do |constant_name|
23
22
  name = "#{prefix}::#{constant_name}"
24
23
  subconstant = constantize(name)
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.16.9"
5
+ VERSION = "0.16.11"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.9
4
+ version: 0.16.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -10,7 +10,7 @@ authors:
10
10
  - Peter Zhu
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2025-02-04 00:00:00.000000000 Z
13
+ date: 2025-02-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: benchmark