diff --git a/src/extension.ts b/src/extension.ts index a518eb0a..6c93253f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,7 +20,7 @@ import { import { CUSTOM_SCHEMA_REQUEST, CUSTOM_CONTENT_REQUEST, SchemaExtensionAPI } from './schema-extension-api'; import { joinPath } from './paths'; import { xhr, configure as configureHttpRequests, getErrorStatusDescription, XHRResponse } from 'request-light'; -import { getConflictingExtensions, showUninstallConflictsNotification } from './extensionConflicts'; +import { ansibleID, showDisableAnsibleNotification } from './extensionConflicts'; export interface ISchemaAssociations { [pattern: string]: string[]; @@ -106,6 +106,10 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI { client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociations()); findConflicts(); }); + workspace.onDidChangeConfiguration(() => { + // If a user updates one of their settings and its now conflicting + findConflicts(); + }); // Tell the server that the client is ready to provide custom schema content client.sendNotification(DynamicCustomSchemaRequestRegistration.type); // Tell the server that the client supports schema requests sent directly to it @@ -138,13 +142,13 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI { /** * Finds extensions that conflict with VSCode-YAML. - * If one or more conflicts are found then show an uninstall notification + * If a conflict is found then show the correct notification * If no conflicts are found then do nothing */ function findConflicts(): void { - const conflictingExtensions = getConflictingExtensions(); - if (conflictingExtensions.length > 0) { - showUninstallConflictsNotification(conflictingExtensions); + const ansibleExt = extensions.getExtension(ansibleID); + if (ansibleExt) { + showDisableAnsibleNotification(); } } diff --git a/src/extensionConflicts.ts b/src/extensionConflicts.ts index 38b64832..bfdf5906 100644 --- a/src/extensionConflicts.ts +++ b/src/extensionConflicts.ts @@ -2,50 +2,26 @@ * Copyright (c) Red Hat, Inc. All rights reserved.. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { commands, Extension, extensions, window } from 'vscode'; +import { window, workspace } from 'vscode'; // A set of VSCode extension ID's that conflict with VSCode-YAML -const conflictingIDs = new Set(['vscoss.vscode-ansible']); - -/** - * Get all of the installed extensions that currently conflict with VSCode-YAML - */ -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function getConflictingExtensions(): Extension[] { - const conflictingExtensions = []; - conflictingIDs.forEach((extension) => { - const ext = extensions.getExtension(extension); - if (ext) { - conflictingExtensions.push(ext); - } - }); - return conflictingExtensions; -} +export const ansibleID = 'vscoss.vscode-ansible'; /** * Display the uninstall conflicting extension notification if there are any conflicting extensions currently installed */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export function showUninstallConflictsNotification(conflictingExts: Extension[]): void { - const uninstallMsg = 'Uninstall'; +export function showDisableAnsibleNotification(): void { + const disableMsg = 'Disable Ansible Validation'; + const conflictMsg = 'VSCode Ansible validation is incompatible with VSCode-YAML validation. Please turn it off.'; + const ansibleConfiguration = workspace.getConfiguration('ansible'); + const validationID = 'validation'; + const validationValue = ansibleConfiguration.get(validationID); - // Gather all the conflicting display names - let conflictMsg = ''; - if (conflictingExts.length === 1) { - conflictMsg = `${conflictingExts[0].packageJSON.displayName} extension is incompatible with VSCode-YAML. Please uninstall it.`; - } else { - const extNames = []; - conflictingExts.forEach((ext) => { - extNames.push(ext.packageJSON.displayName); + // If the validationValue is true in the settings.json or undefined (hasn't been set yet) then show the disable notification + if (validationValue === undefined || validationValue === true) { + window.showInformationMessage(conflictMsg, disableMsg).then(() => { + ansibleConfiguration.update(validationID, false, true); }); - conflictMsg = `The ${extNames.join(', ')} extensions are incompatible with VSCode-YAML. Please uninstall them.`; } - - window.showInformationMessage(conflictMsg, uninstallMsg).then((clickedMsg) => { - if (clickedMsg === uninstallMsg) { - conflictingExts.forEach((ext) => { - commands.executeCommand('workbench.extensions.uninstallExtension', ext.id); - }); - } - }); }