Repository: microsoft/vscode (TypeScript)
Date: 2022-09-29 20:39:39+00:00
Task type: Bug Fix

Issue:
Failed to enable an extension when working in remote development
<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: 1.70.2
- OS Version: Darwin arm64 21.4.0

Steps to Reproduce:
1. Open VS Code on desktop.
2. Connect to any GitHub Codespace.
3. Install the gitlab.gitlab-workflow extension.
4. Disable this extension & reload.
5. Enable this extension.
6. An error message "Cannot change enablement of Git extension because of its extension kind" pops up.

I searched the error in the repository and realized it could be a bug when checking for the changeability of the builtin git extension's enablement state. The GitLab Workflow extension lists vscode.git as an [extension dependency](https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/blob/main/package.json#L880), which triggers the check.
https://github.com/microsoft/vscode/blob/36351641a2051c81cc0134744e2983c111c27367/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts#L167
Somehow the git extension's enablement is considered not changeable. 

<img width="1440" alt="Screen Shot 2022-08-26 at 15 00 43" src="https://user-images.githubusercontent.com/23252886/186848818-d40cbc68-ba79-40a0-bc41-6a6f394e731b.png">



Issue discussion:
@sandy081, could you help triaging this issue? Thanks! 
Will investigate

Solution patch:
diff --git a/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts b/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts
--- a/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts
+++ b/src/vs/workbench/services/extensionManagement/browser/extensionEnablementService.ts
@@ -249,6 +249,11 @@ export class ExtensionEnablementService extends Disposable implements IWorkbench
 				continue;
 			}
 
+			// Skip if dependency extension is disabled by extension kind
+			if (enablementStateOfExtension === EnablementState.DisabledByExtensionKind) {
+				continue;
+			}
+
 			// Check if the extension is a dependency or in extension pack
 			if (extensions.some(e =>
 				(options.dependencies && e.manifest.extensionDependencies?.some(id => areSameExtensions({ id }, extension.identifier)))


Test patch:
diff --git a/src/vs/workbench/services/extensionManagement/test/browser/extensionEnablementService.test.ts b/src/vs/workbench/services/extensionManagement/test/browser/extensionEnablementService.test.ts
--- a/src/vs/workbench/services/extensionManagement/test/browser/extensionEnablementService.test.ts
+++ b/src/vs/workbench/services/extensionManagement/test/browser/extensionEnablementService.test.ts
@@ -412,6 +412,22 @@ suite('ExtensionEnablementService Test', () => {
 		assert.strictEqual(testObject.getEnablementState(target), EnablementState.EnabledWorkspace);
 	});
 
+	test('test enable an extension with a dependency extension that cannot be enabled', async () => {
+		instantiationService.stub(IExtensionManagementServerService, anExtensionManagementServerService(anExtensionManagementServer('vscode-local', instantiationService), anExtensionManagementServer('vscode-remote', instantiationService), null));
+		const localWorkspaceDepExtension = aLocalExtension2('pub.b', { extensionKind: ['workspace'] }, { location: URI.file(`pub.b`) });
+		const remoteWorkspaceExtension = aLocalExtension2('pub.a', { extensionKind: ['workspace'], extensionDependencies: ['pub.b'] }, { location: URI.file(`pub.a`).with({ scheme: Schemas.vscodeRemote }) });
+		const remoteWorkspaceDepExtension = aLocalExtension2('pub.b', { extensionKind: ['workspace'] }, { location: URI.file(`pub.b`).with({ scheme: Schemas.vscodeRemote }) });
+		installed.push(localWorkspaceDepExtension, remoteWorkspaceExtension, remoteWorkspaceDepExtension);
+
+		testObject = new TestExtensionEnablementService(instantiationService);
+		await (<TestExtensionEnablementService>testObject).waitUntilInitialized();
+
+		await testObject.setEnablement([remoteWorkspaceExtension], EnablementState.DisabledGlobally);
+		await testObject.setEnablement([remoteWorkspaceExtension], EnablementState.EnabledGlobally);
+		assert.ok(testObject.isEnabled(remoteWorkspaceExtension));
+		assert.strictEqual(testObject.getEnablementState(remoteWorkspaceExtension), EnablementState.EnabledGlobally);
+	});
+
 	test('test enable an extension also enables packed extensions', async () => {
 		installed.push(...[aLocalExtension2('pub.a', { extensionPack: ['pub.b'] }), aLocalExtension('pub.b')]);
 		const target = installed[0];