| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  | # typed: true # rubocop:todo Sorbet/StrictSigil | 
					
						
							|  |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							|  |  |  |   module Bundle | 
					
						
							|  |  |  |     module VscodeExtensionInstaller | 
					
						
							| 
									
										
										
										
											2025-03-21 04:24:55 +00:00
										 |  |  |       def self.reset! | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |         @installed_extensions = nil | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-21 04:24:55 +00:00
										 |  |  |       def self.preinstall(name, no_upgrade: false, verbose: false) | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |         if !Bundle.vscode_installed? && Bundle.cask_installed? | 
					
						
							|  |  |  |           puts "Installing visual-studio-code. It is not currently installed." if verbose | 
					
						
							|  |  |  |           Bundle.brew("install", "--cask", "visual-studio-code", verbose:) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if extension_installed?(name) | 
					
						
							|  |  |  |           puts "Skipping install of #{name} VSCode extension. It is already installed." if verbose | 
					
						
							|  |  |  |           return false | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         raise "Unable to install #{name} VSCode extension. VSCode is not installed." unless Bundle.vscode_installed? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         true | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-21 04:24:55 +00:00
										 |  |  |       def self.install(name, preinstall: true, no_upgrade: false, verbose: false, force: false) | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |         return true unless preinstall | 
					
						
							|  |  |  |         return true if extension_installed?(name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         puts "Installing #{name} VSCode extension. It is not currently installed." if verbose | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false unless Bundle.exchange_uid_if_needed! do | 
					
						
							| 
									
										
										
										
											2025-04-02 17:15:32 +01:00
										 |  |  |           Bundle.system(T.must(Bundle.which_vscode), "--install-extension", name, verbose:) | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         installed_extensions << name | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         true | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-21 04:24:55 +00:00
										 |  |  |       def self.extension_installed?(name) | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |         installed_extensions.include? name.downcase | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-21 04:24:55 +00:00
										 |  |  |       def self.installed_extensions | 
					
						
							| 
									
										
										
										
											2025-03-24 21:55:47 +08:00
										 |  |  |         require "bundle/vscode_extension_dumper" | 
					
						
							| 
									
										
										
										
											2025-03-18 17:38:37 +00:00
										 |  |  |         @installed_extensions ||= Homebrew::Bundle::VscodeExtensionDumper.extensions | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |