@@ -26,7 +26,8 @@ class AbstractDsl < CommandWithoutTracker
2626 #| ?app_root: String,
2727 #| ?halt_upon_load_error: bool,
2828 #| ?compiler_options: Hash[String, untyped],
29- #| ?lsp_addon: bool
29+ #| ?lsp_addon: bool,
30+ #| ?max_diff_lines: Integer
3031 #| ) -> void
3132 def initialize (
3233 requested_constants :,
@@ -46,7 +47,8 @@ def initialize(
4647 app_root : "." ,
4748 halt_upon_load_error : true ,
4849 compiler_options : { } ,
49- lsp_addon : false
50+ lsp_addon : false ,
51+ max_diff_lines : DEFAULT_MAX_DIFF_LINES
5052 )
5153 @requested_constants = requested_constants
5254 @requested_paths = requested_paths
@@ -66,6 +68,7 @@ def initialize(
6668 @skip_constant = skip_constant
6769 @compiler_options = compiler_options
6870 @lsp_addon = lsp_addon
71+ @max_diff_lines = max_diff_lines
6972
7073 super ( )
7174 end
@@ -240,9 +243,9 @@ def compile_dsl_rbi(constant_name, rbi, outpath: @outpath, quiet: false)
240243
241244 #: (Pathname dir) -> void
242245 def perform_dsl_verification ( dir )
243- diff = verify_dsl_rbi ( tmp_dir : dir )
246+ diff , diff_output = verify_dsl_rbi ( tmp_dir : dir )
244247
245- report_diff_and_exit_if_out_of_date ( diff , :dsl )
248+ report_diff_and_exit_if_out_of_date ( diff , diff_output , :dsl )
246249 ensure
247250 FileUtils . remove_entry ( dir )
248251 end
@@ -264,9 +267,10 @@ def dsl_rbi_filename(constant_name)
264267 @outpath / "#{ underscore ( constant_name ) } .rbi"
265268 end
266269
267- #: (tmp_dir: Pathname) -> Hash[String, Symbol]
270+ #: (tmp_dir: Pathname) -> [ Hash[String, Symbol], String ]
268271 def verify_dsl_rbi ( tmp_dir :)
269272 diff = { }
273+ diff_output = String . new
270274
271275 existing_rbis = rbi_files_in ( @outpath )
272276 new_rbis = rbi_files_in ( tmp_dir )
@@ -275,12 +279,14 @@ def verify_dsl_rbi(tmp_dir:)
275279
276280 added_files . each do |file |
277281 diff [ file ] = :added
282+ diff_output << file_diff ( file , File ::NULL , tmp_dir / file )
278283 end
279284
280285 removed_files = ( existing_rbis - new_rbis )
281286
282287 removed_files . each do |file |
283288 diff [ file ] = :removed
289+ diff_output << file_diff ( file , @outpath / file , File ::NULL )
284290 end
285291
286292 common_files = ( existing_rbis & new_rbis )
@@ -291,9 +297,10 @@ def verify_dsl_rbi(tmp_dir:)
291297
292298 changed_files . each do |file |
293299 diff [ file ] = :changed
300+ diff_output << file_diff ( file , @outpath / file , tmp_dir / file )
294301 end
295302
296- diff
303+ [ diff , diff_output ]
297304 end
298305
299306 #: (Symbol cause, Array[String] files) -> String
@@ -305,16 +312,25 @@ def build_error_for_files(cause, files)
305312 " File(s) #{ cause } :\n - #{ filenames } "
306313 end
307314
308- #: (Hash[String, Symbol] diff, Symbol command) -> void
309- def report_diff_and_exit_if_out_of_date ( diff , command )
315+ #: (Hash[String, Symbol] diff, String diff_output, Symbol command) -> void
316+ def report_diff_and_exit_if_out_of_date ( diff , diff_output , command )
310317 if diff . empty?
311318 say ( "Nothing to do, all RBIs are up-to-date." )
312319 else
313320 reasons = diff . group_by ( &:last ) . sort . map do |cause , diff_for_cause |
314321 build_error_for_files ( cause , diff_for_cause . map ( &:first ) )
315322 end . join ( "\n " )
316323
317- raise Tapioca ::Error , <<~ERROR
324+ diff_lines = diff_output . lines . count
325+ file_diff = if diff_lines . between? ( 1 , @max_diff_lines )
326+ "#{ set_color ( "Diff:" , :red ) } \n #{ diff_output . chomp } "
327+ elsif diff_lines > @max_diff_lines
328+ set_color ( "Diff not displayed as it exceeds #{ @max_diff_lines } lines" , :red )
329+ else
330+ ""
331+ end
332+
333+ raise Tapioca ::Error , <<~ERROR . rstrip
318334 #{ set_color ( "RBI files are out-of-date. In your development environment, please run:" , :green ) }
319335 #{ set_color ( "`#{ default_command ( command ) } `" , :green , :bold ) }
320336 #{ set_color ( "Once it is complete, be sure to commit and push any changes" , :green ) }
@@ -323,6 +339,8 @@ def report_diff_and_exit_if_out_of_date(diff, command)
323339
324340 #{ set_color ( "Reason:" , :red ) }
325341 #{ reasons }
342+
343+ #{ file_diff }
326344 ERROR
327345 end
328346 end
0 commit comments