fade2gray
fade2gray

Reputation: 19

How to determine programmatically whether an extension is disabled?

Can an extension's enabled/disabled status be determined using the Windows command line or some other method?

If an extension's settings are changed and those changes are recorded in the settings.json file and that extension is then disabled or uninstalled, those changes become 'dimmed out'. Perhaps there is a database entry somewhere that stores the dimmed status of an entry in the settings.json?

Upvotes: 1

Views: 557

Answers (3)

Mark
Mark

Reputation: 180805

To clarify: the Extension.isActive property has nothing to do with whether an extension is enabled or disabled. An extension can be enabled but not yet activated when you test it - activation may not happen until one of its commands is triggered for example. But it is still enabled even though isActive may be false.

This is why "changing the status of the Extension from the Extensions page also does not seem to affect the value if isActive" has no effect. That "status" is enabled/disabled and has effect on activation.

// assume not installed
let getExtension1 = await vscode.extensions.getExtension("gcsboss.how-long");
// getExtension1 = undefined

// assume installed but disabled    
let getExtension = await vscode.extensions.getExtension("arturodent.highlight-files");
// the below will error, getExtension() returns undefined
// let isActive = await vscode.extensions.getExtension("arturodent.highlight-files").isActive;  // will error, getExtension() returns undefined
// getExtension = undefined
        
// installed and enabled
const getExtension2 = await vscode.extensions.getExtension("moalamri.inline-fold");
const isActive2 = await vscode.extensions.getExtension("moalamri.inline-fold").isActive;
// getExtension2 != undefined; isActive may or may not be true at the time you test

Thus if you want to test whether an extension is enabled or disabled just do this:

let getExtension1 = await vscode.extensions.getExtension("gcsboss.how-long");

if that is undefined, the extension is installed and disabled OR not installed at all.

Upvotes: 0

boocs
boocs

Reputation: 599

You can check the extension's config to see if it has any of it's settings.

const isCppExtEnabled = cCppConfig.has(cCppSettingNames.autocomplete);

IsActive on the cpp extension returns false but isCppExtEnabled returns true

If I disable the extension then isCppExtEnabled is false

Upvotes: 0

Axel
Axel

Reputation: 482

From within your own TypeScript extension you can use this:

const testedExtension =  vscode.extensions.getExtension("<author of the extension>.<name of the extension>");
if (typeof testedExtension !== "undefined") {
    if (testedExtension.isActive) {
        vscode.window.showInformationMessage("The tested extension is active (ie enabled). :-)", {modal: true});
    }
    else {
        vscode.window.showInformationMessage("The tested extension is NOT active (ie disabled). :-(", {modal: true});
    }
}
else {
    vscode.window.showInformationMessage("The tested extension was not found (ie not installed). :-( :-(", {modal: true});
}

Upvotes: 1

Related Questions