Class: Homebrew::Bundle::VscodeExtension Private

Inherits:
Extension show all
Defined in:
bundle/extensions/vscode_extension.rb

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Constant Summary collapse

PACKAGE_TYPE =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

:vscode
PACKAGE_TYPE_NAME =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"VSCode Extension"
"VSCode (and forks/variants) extensions"

Constants inherited from Extension

Extension::EntryOptions

Class Method Summary collapse

Methods inherited from Extension

add_supported?, banner_name, check, check_label, cleanup_supported?, dump, dump_disable_description, dump_disable_env, dump_disable_predicate_method, dump_disable_supported?, dump_entry, dump_name, dump_supported?, dump_with, entry, #failure_reason, flag, inherited, install_supported?, #installed_and_up_to_date?, package_description, package_manager_executable, package_manager_installed?, package_manager_name, predicate_method, quote, remove_supported?, switch_description, type

Methods inherited from Checker::Base

#checkable_entries, #exit_early_check, #failure_reason, #find_actionable, #format_checkable, #full_check, #installed_and_up_to_date?

Class Method Details

.cleanup!(extensions) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



176
177
178
179
180
181
182
183
184
185
# File 'bundle/extensions/vscode_extension.rb', line 176

def cleanup!(extensions)
  vscode = Bundle.which_vscode
  return if vscode.nil?

  Bundle.exchange_uid_if_needed! do
    extensions.each do |extension|
      Kernel.system(vscode.to_s, "--uninstall-extension", extension)
    end
  end
end

.cleanup_headingString?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



21
22
23
# File 'bundle/extensions/vscode_extension.rb', line 21

def cleanup_heading
  "VSCode extensions"
end

.cleanup_items(entries) ⇒ Array<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



164
165
166
167
168
169
170
171
172
173
# File 'bundle/extensions/vscode_extension.rb', line 164

def cleanup_items(entries)
  kept_extensions = entries.filter_map do |entry|
    entry = T.cast(entry, Dsl::Entry)
    entry.name.downcase if entry.type == type
  end

  return [].freeze if kept_extensions.empty?

  packages - kept_extensions
end

.extension_installed?(name) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


83
84
85
# File 'bundle/extensions/vscode_extension.rb', line 83

def extension_installed?(name)
  package_installed?(name)
end

.extensionsArray<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'bundle/extensions/vscode_extension.rb', line 40

def extensions
  extensions = @extensions
  return extensions if extensions

  @extensions = if Bundle.vscode_installed?
    vscode = Bundle.which_vscode
    return [] if vscode.nil?

    Bundle.exchange_uid_if_needed! do
      ENV["WSL_DISTRO_NAME"] = ENV.fetch("HOMEBREW_WSL_DISTRO_NAME", nil)
      `"#{vscode}" --list-extensions 2>/dev/null`
    end.split("\n").map(&:downcase)
  else
    []
  end
end

.install!(name, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • preinstall (Boolean) (defaults to: true)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • force (Boolean) (defaults to: false)

Returns:

  • (Boolean)


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'bundle/extensions/vscode_extension.rb', line 142

def install!(name, with: nil, preinstall: true, no_upgrade: false, verbose: false, force: false)
  _ = with
  _ = no_upgrade
  _ = force

  return true unless preinstall

  puts "Installing #{name} VSCode extension. It is not currently installed." if verbose
  return false unless install_package!(name, verbose:)

  package = T.cast(package_record(name), String)
  installed_extensions << package unless installed_extensions.include?(package)
  if @extensions
    @extensions << package unless @extensions.include?(package)
  else
    @extensions = [package]
  end

  true
end

.install_package!(name, with: nil, verbose: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


121
122
123
124
125
126
127
128
129
130
# File 'bundle/extensions/vscode_extension.rb', line 121

def install_package!(name, with: nil, verbose: false)
  _ = with

  vscode = Bundle.which_vscode
  return false if vscode.nil?

  Bundle.exchange_uid_if_needed! do
    Bundle.system(vscode, "--install-extension", name, verbose:)
  end
end

.installed_extensionsArray<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



68
69
70
71
72
73
# File 'bundle/extensions/vscode_extension.rb', line 68

def installed_extensions
  installed_extensions = @installed_extensions
  return installed_extensions if installed_extensions

  @installed_extensions = extensions.dup
end

.installed_packagesArray<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



63
64
65
# File 'bundle/extensions/vscode_extension.rb', line 63

def installed_packages
  installed_extensions
end

.legacy_cleanup_methodSymbol?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



26
27
28
29
30
# File 'bundle/extensions/vscode_extension.rb', line 26

def legacy_cleanup_method
  # TODO: Remove this legacy cleanup hook once the direct cleanup specs
  # stop stubbing the old command-level VSCode helper.
  :vscode_extensions_to_uninstall
end

.package_installed?(name, with: nil) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:

  • (Boolean)


76
77
78
79
80
# File 'bundle/extensions/vscode_extension.rb', line 76

def package_installed?(name, with: nil)
  _ = with

  installed_extensions.include?(name.downcase)
end

.package_record(name, with: nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



33
34
35
36
37
# File 'bundle/extensions/vscode_extension.rb', line 33

def package_record(name, with: nil)
  _ = with

  name.downcase
end

.packagesArray<String>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



58
59
60
# File 'bundle/extensions/vscode_extension.rb', line 58

def packages
  extensions
end

.preinstall!(name, with: nil, no_upgrade: false, verbose: false) ⇒ Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • name (String)
  • with (Array<String>, nil) (defaults to: nil)
  • no_upgrade (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'bundle/extensions/vscode_extension.rb', line 95

def preinstall!(name, with: nil, no_upgrade: false, verbose: false)
  _ = with
  _ = no_upgrade

  if !Bundle.vscode_installed? && Bundle.cask_installed?
    puts "Installing visual-studio-code. It is not currently installed." if verbose
    Bundle.system(HOMEBREW_BREW_FILE, "install", "--cask", "visual-studio-code", verbose:)
  end

  if package_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

.reset!void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



15
16
17
18
# File 'bundle/extensions/vscode_extension.rb', line 15

def reset!
  @extensions = T.let(nil, T.nilable(T::Array[String]))
  @installed_extensions = T.let(nil, T.nilable(T::Array[String]))
end