|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Red Hat, Inc. All rights reserved.. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | +import { commands, Extension, extensions, window } from 'vscode'; |
| 6 | + |
| 7 | +// A set of VSCode extension ID's that conflict with VSCode-YAML |
| 8 | +const azureDeploy = 'ms-vscode-deploy-azure.azure-deploy'; |
| 9 | +const conflictingIDs = new Set(['vscoss.vscode-ansible', azureDeploy, 'sysninja.vscode-ansible-mod', 'haaaad.ansible']); |
| 10 | + |
| 11 | +// A set of VSCode extension ID's that are currently uninstalling |
| 12 | +const uninstallingIDs = new Set(); |
| 13 | + |
| 14 | +/** |
| 15 | + * Get all of the installed extensions that currently conflict with VSCode-YAML |
| 16 | + */ |
| 17 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 18 | +export function getConflictingExtensions(): Extension<any>[] { |
| 19 | + const conflictingExtensions = []; |
| 20 | + conflictingIDs.forEach((extension) => { |
| 21 | + const ext = extensions.getExtension(extension); |
| 22 | + if (ext && !uninstallingIDs.has(ext.id)) { |
| 23 | + conflictingExtensions.push(ext); |
| 24 | + } |
| 25 | + }); |
| 26 | + return conflictingExtensions; |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Display the uninstall conflicting extension notification if there are any conflicting extensions currently installed |
| 31 | + */ |
| 32 | +// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 33 | +export function showUninstallConflictsNotification(conflictingExts: Extension<any>[]): void { |
| 34 | + // Add all available conflicting extensions to the uninstalling IDs map |
| 35 | + for (const extIndex in conflictingExts) { |
| 36 | + const ext = conflictingExts[extIndex]; |
| 37 | + uninstallingIDs.add(ext.id); |
| 38 | + } |
| 39 | + |
| 40 | + const uninstallMsg = 'Uninstall'; |
| 41 | + |
| 42 | + // Gather all the conflicting display names |
| 43 | + let conflictMsg = ''; |
| 44 | + if (conflictingExts.length === 1) { |
| 45 | + conflictMsg = `${conflictingExts[0].packageJSON.displayName} extension is incompatible with VSCode-YAML. Please uninstall it.`; |
| 46 | + } else { |
| 47 | + const extNames = []; |
| 48 | + conflictingExts.forEach((ext) => { |
| 49 | + extNames.push(ext.packageJSON.displayName); |
| 50 | + }); |
| 51 | + conflictMsg = `The ${extNames.join(', ')} extensions are incompatible with VSCode-YAML. Please uninstall them.`; |
| 52 | + } |
| 53 | + |
| 54 | + if (conflictingExts.length > 0) { |
| 55 | + window.showInformationMessage(conflictMsg, uninstallMsg).then((clickedMsg) => { |
| 56 | + if (clickedMsg === uninstallMsg) { |
| 57 | + conflictingExts.forEach((ext) => { |
| 58 | + commands.executeCommand('workbench.extensions.uninstallExtension', ext.id); |
| 59 | + uninstallingIDs.delete(ext.id); |
| 60 | + }); |
| 61 | + |
| 62 | + // The azure deploy extension must be reloaded in order to be completely uninstalled |
| 63 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 64 | + if (conflictingExts.findIndex((ext: any) => ext.id === azureDeploy) !== -1) { |
| 65 | + commands.executeCommand('workbench.action.reloadWindow'); |
| 66 | + } |
| 67 | + } |
| 68 | + }); |
| 69 | + } |
| 70 | +} |
0 commit comments