Skip to content

Commit

Permalink
Update extensionConflicts to include only ansible specific support
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Pinkney <[email protected]>
  • Loading branch information
JPinkney committed Dec 2, 2020
1 parent 5e7cf50 commit fd1746e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 41 deletions.
14 changes: 9 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}

Expand Down
48 changes: 12 additions & 36 deletions src/extensionConflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>[] {
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<any>[]): 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);
});
}
});
}

0 comments on commit fd1746e

Please sign in to comment.