Skip to content

Commit 8ffcb49

Browse files
committed
disable some extension commands in web
1 parent 28473ed commit 8ffcb49

12 files changed

Lines changed: 98 additions & 69 deletions

File tree

src/vs/code/electron-browser/issue/issueReporterMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export class IssueReporter extends Disposable {
312312
const channel = getDelayedChannel(sharedProcess.then(c => c.getChannel('telemetryAppender')));
313313
const appender = combinedAppender(new TelemetryAppenderClient(channel), new LogAppender(logService));
314314
const commonProperties = resolveCommonProperties(product.commit || 'Commit unknown', pkg.version, configuration.machineId, this.environmentService.installSourcePath);
315-
const piiPaths = [this.environmentService.appRoot, this.environmentService.extensionsPath];
315+
const piiPaths = this.environmentService.extensionsPath ? [this.environmentService.appRoot, this.environmentService.extensionsPath] : [this.environmentService.appRoot];
316316
const config: ITelemetryServiceConfig = { appender, commonProperties, piiPaths };
317317

318318
const telemetryService = instantiationService.createInstance(TelemetryService, config);

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
158158
const config: ITelemetryServiceConfig = {
159159
appender: combinedAppender(appInsightsAppender, new LogAppender(logService)),
160160
commonProperties: resolveCommonProperties(product.commit, pkg.version, configuration.machineId, installSourcePath),
161-
piiPaths: [appRoot, extensionsPath]
161+
piiPaths: extensionsPath ? [appRoot, extensionsPath] : [appRoot]
162162
};
163163

164164
telemetryService = new TelemetryService(config, configurationService);

src/vs/code/electron-main/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export class CodeApplication extends Disposable {
484484
const channel = getDelayedChannel(sharedProcessClient.then(client => client.getChannel('telemetryAppender')));
485485
const appender = combinedAppender(new TelemetryAppenderClient(channel), new LogAppender(this.logService));
486486
const commonProperties = resolveCommonProperties(product.commit, pkg.version, machineId, this.environmentService.installSourcePath);
487-
const piiPaths = [this.environmentService.appRoot, this.environmentService.extensionsPath];
487+
const piiPaths = this.environmentService.extensionsPath ? [this.environmentService.appRoot, this.environmentService.extensionsPath] : [this.environmentService.appRoot];
488488
const config: ITelemetryServiceConfig = { appender, commonProperties, piiPaths, trueMachineId };
489489

490490
services.set(ITelemetryService, new SyncDescriptor(TelemetryService, [config]));

src/vs/code/electron-main/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ class CodeMain {
332332
if (error.code === 'EACCES' || error.code === 'EPERM') {
333333
this.showStartupWarningDialog(
334334
localize('startupDataDirError', "Unable to write program user data."),
335-
localize('startupDataDirErrorDetail', "Please make sure the directories {0} and {1} are writeable.", environmentService.userDataPath, environmentService.extensionsPath)
335+
environmentService.extensionsPath
336+
? localize('startupUserDataAndExtensionsDirErrorDetail', "Please make sure the directories {0} and {1} are writeable.", environmentService.userDataPath, environmentService.extensionsPath)
337+
: localize('startupUserDataDirErrorDetail', "Please make sure the directory {0} is writeable.", environmentService.userDataPath)
336338
);
337339
}
338340
}

src/vs/code/node/cliProcessMain.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class Main {
102102
const ids: string[] = typeof arg === 'string' ? [arg] : arg;
103103
await this.locateExtension(ids);
104104
} else if (argv['telemetry']) {
105-
console.log(buildTelemetryMessage(this.environmentService.appRoot, this.environmentService.extensionsPath));
105+
console.log(buildTelemetryMessage(this.environmentService.appRoot, this.environmentService.extensionsPath ? this.environmentService.extensionsPath : undefined));
106106
}
107107
}
108108

@@ -293,7 +293,8 @@ export async function main(argv: ParsedArgs): Promise<void> {
293293
process.once('exit', () => logService.dispose());
294294
logService.info('main', argv);
295295

296-
await Promise.all([environmentService.appSettingsHome.fsPath, environmentService.extensionsPath].map(p => mkdirp(p)));
296+
await Promise.all<void | undefined>([environmentService.appSettingsHome.fsPath, environmentService.extensionsPath]
297+
.map((path): undefined | Promise<void> => path ? mkdirp(path) : undefined));
297298

298299
const configurationService = new ConfigurationService(environmentService.settingsResource);
299300
disposables.add(configurationService);
@@ -339,7 +340,7 @@ export async function main(argv: ParsedArgs): Promise<void> {
339340
const config: ITelemetryServiceConfig = {
340341
appender: combinedAppender(...appenders),
341342
commonProperties: resolveCommonProperties(product.commit, pkg.version, stateService.getItem('telemetry.machineId'), installSourcePath),
342-
piiPaths: [appRoot, extensionsPath]
343+
piiPaths: extensionsPath ? [appRoot, extensionsPath] : [appRoot]
343344
};
344345

345346
services.set(ITelemetryService, new SyncDescriptor(TelemetryService, [config]));

src/vs/platform/environment/common/environment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export interface IEnvironmentService {
132132
isExtensionDevelopment: boolean;
133133
disableExtensions: boolean | string[];
134134
builtinExtensionsPath: string;
135-
extensionsPath: string;
135+
extensionsPath?: string;
136136
extensionDevelopmentLocationURI?: URI[];
137137
extensionTestsLocationURI?: URI;
138138

src/vs/platform/extensionManagement/node/extensionManagementService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class ExtensionManagementService extends Disposable implements IExtension
135135
) {
136136
super();
137137
this.systemExtensionsPath = environmentService.builtinExtensionsPath;
138-
this.extensionsPath = environmentService.extensionsPath;
138+
this.extensionsPath = environmentService.extensionsPath!;
139139
this.uninstalledPath = path.join(this.extensionsPath, '.obsolete');
140140
this.uninstalledFileLimiter = new Queue();
141141
this.manifestCache = this._register(new ExtensionsManifestCache(environmentService, this));

src/vs/platform/telemetry/node/telemetry.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,36 @@ import { readdirSync } from 'vs/base/node/pfs';
88
import { statSync, readFileSync } from 'fs';
99
import { join } from 'vs/base/common/path';
1010

11-
export function buildTelemetryMessage(appRoot: string, extensionsPath: string): string {
12-
// Gets all the directories inside the extension directory
13-
const dirs = readdirSync(extensionsPath).filter(files => {
14-
// This handles case where broken symbolic links can cause statSync to throw and error
15-
try {
16-
return statSync(join(extensionsPath, files)).isDirectory();
17-
} catch {
18-
return false;
19-
}
20-
});
21-
const telemetryJsonFolders: string[] = [];
22-
dirs.forEach((dir) => {
23-
const files = readdirSync(join(extensionsPath, dir)).filter(file => file === 'telemetry.json');
24-
// We know it contains a telemetry.json file so we add it to the list of folders which have one
25-
if (files.length === 1) {
26-
telemetryJsonFolders.push(dir);
27-
}
28-
});
11+
export function buildTelemetryMessage(appRoot: string, extensionsPath?: string): string {
2912
const mergedTelemetry = Object.create(null);
3013
// Simple function to merge the telemetry into one json object
3114
const mergeTelemetry = (contents: string, dirName: string) => {
3215
const telemetryData = JSON.parse(contents);
3316
mergedTelemetry[dirName] = telemetryData;
3417
};
35-
telemetryJsonFolders.forEach((folder) => {
36-
const contents = readFileSync(join(extensionsPath, folder, 'telemetry.json')).toString();
37-
mergeTelemetry(contents, folder);
38-
});
18+
if (extensionsPath) {
19+
// Gets all the directories inside the extension directory
20+
const dirs = readdirSync(extensionsPath).filter(files => {
21+
// This handles case where broken symbolic links can cause statSync to throw and error
22+
try {
23+
return statSync(join(extensionsPath, files)).isDirectory();
24+
} catch {
25+
return false;
26+
}
27+
});
28+
const telemetryJsonFolders: string[] = [];
29+
dirs.forEach((dir) => {
30+
const files = readdirSync(join(extensionsPath, dir)).filter(file => file === 'telemetry.json');
31+
// We know it contains a telemetry.json file so we add it to the list of folders which have one
32+
if (files.length === 1) {
33+
telemetryJsonFolders.push(dir);
34+
}
35+
});
36+
telemetryJsonFolders.forEach((folder) => {
37+
const contents = readFileSync(join(extensionsPath, folder, 'telemetry.json')).toString();
38+
mergeTelemetry(contents, folder);
39+
});
40+
}
3941
let contents = readFileSync(join(appRoot, 'telemetry-core.json')).toString();
4042
mergeTelemetry(contents, 'vscode-core');
4143
contents = readFileSync(join(appRoot, 'telemetry-extensions.json')).toString();

src/vs/workbench/contrib/extensions/browser/extensions.contribution.ts

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes';
99
import { Registry } from 'vs/platform/registry/common/platform';
1010
import { SyncActionDescriptor, MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
1111
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
12-
import { ExtensionsLabel, ExtensionsChannelId, PreferencesLabel, IExtensionManagementService, IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement';
12+
import { ExtensionsLabel, ExtensionsChannelId, PreferencesLabel, IExtensionManagementService, IExtensionGalleryService, IExtensionManagementServerService } from 'vs/platform/extensionManagement/common/extensionManagement';
1313
import { IWorkbenchActionRegistry, Extensions as WorkbenchActionExtensions } from 'vs/workbench/common/actions';
14-
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
14+
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions';
1515
import { IOutputChannelRegistry, Extensions as OutputExtensions } from 'vs/workbench/contrib/output/common/output';
1616
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
1717
import { VIEWLET_ID, IExtensionsWorkbenchService } from 'vs/workbench/contrib/extensions/common/extensions';
@@ -42,19 +42,11 @@ import { onUnexpectedError } from 'vs/base/common/errors';
4242
import { ExtensionDependencyChecker } from 'vs/workbench/contrib/extensions/browser/extensionsDependencyChecker';
4343
import { CancellationToken } from 'vs/base/common/cancellation';
4444
import { ExtensionType } from 'vs/platform/extensions/common/extensions';
45+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
4546

4647
// Singletons
4748
registerSingleton(IExtensionsWorkbenchService, ExtensionsWorkbenchService);
4849

49-
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
50-
workbenchRegistry.registerWorkbenchContribution(StatusUpdater, LifecyclePhase.Restored);
51-
workbenchRegistry.registerWorkbenchContribution(MaliciousExtensionChecker, LifecyclePhase.Eventually);
52-
workbenchRegistry.registerWorkbenchContribution(ConfigureRecommendedExtensionsCommandsContributor, LifecyclePhase.Eventually);
53-
workbenchRegistry.registerWorkbenchContribution(KeymapExtensions, LifecyclePhase.Restored);
54-
workbenchRegistry.registerWorkbenchContribution(ExtensionsViewletViewsContribution, LifecyclePhase.Starting);
55-
workbenchRegistry.registerWorkbenchContribution(ExtensionActivationProgress, LifecyclePhase.Eventually);
56-
workbenchRegistry.registerWorkbenchContribution(ExtensionDependencyChecker, LifecyclePhase.Eventually);
57-
5850
Registry.as<IOutputChannelRegistry>(OutputExtensions.OutputChannels)
5951
.registerChannel({ id: ExtensionsChannelId, label: ExtensionsLabel, log: false });
6052

@@ -70,17 +62,6 @@ Registry.as<IQuickOpenRegistry>(Extensions.Quickopen).registerQuickOpenHandler(
7062
)
7163
);
7264

73-
Registry.as<IQuickOpenRegistry>(Extensions.Quickopen).registerQuickOpenHandler(
74-
new QuickOpenHandlerDescriptor(
75-
GalleryExtensionsHandler,
76-
GalleryExtensionsHandler.ID,
77-
'ext install ',
78-
undefined,
79-
localize('galleryExtensionsCommands', "Install Gallery Extensions"),
80-
true
81-
)
82-
);
83-
8465
// Editor
8566
const editorDescriptor = new EditorDescriptor(
8667
ExtensionEditor,
@@ -145,9 +126,6 @@ actionRegistry.registerWorkbenchAction(builtinActionDescriptor, 'Extensions: Sho
145126
const updateAllActionDescriptor = new SyncActionDescriptor(UpdateAllAction, UpdateAllAction.ID, UpdateAllAction.LABEL);
146127
actionRegistry.registerWorkbenchAction(updateAllActionDescriptor, 'Extensions: Update All Extensions', ExtensionsLabel);
147128

148-
const openExtensionsFolderActionDescriptor = new SyncActionDescriptor(OpenExtensionsFolderAction, OpenExtensionsFolderAction.ID, OpenExtensionsFolderAction.LABEL);
149-
actionRegistry.registerWorkbenchAction(openExtensionsFolderActionDescriptor, 'Extensions: Open Extensions Folder', ExtensionsLabel);
150-
151129
const installVSIXActionDescriptor = new SyncActionDescriptor(InstallVSIXAction, InstallVSIXAction.ID, InstallVSIXAction.LABEL);
152130
actionRegistry.registerWorkbenchAction(installVSIXActionDescriptor, 'Extensions: Install from VSIX...', ExtensionsLabel);
153131

@@ -349,4 +327,46 @@ MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
349327
title: localize('showExtensions', "Extensions")
350328
},
351329
order: 3
352-
});
330+
});
331+
332+
const workbenchRegistry = Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench);
333+
334+
class ExtensionsContributions implements IWorkbenchContribution {
335+
336+
constructor(
337+
@IWorkbenchEnvironmentService workbenchEnvironmentService: IWorkbenchEnvironmentService,
338+
@IExtensionManagementServerService extensionManagementServerService: IExtensionManagementServerService
339+
) {
340+
341+
const canManageExtensions = extensionManagementServerService.localExtensionManagementServer || extensionManagementServerService.remoteExtensionManagementServer;
342+
343+
if (canManageExtensions) {
344+
Registry.as<IQuickOpenRegistry>(Extensions.Quickopen).registerQuickOpenHandler(
345+
new QuickOpenHandlerDescriptor(
346+
GalleryExtensionsHandler,
347+
GalleryExtensionsHandler.ID,
348+
'ext install ',
349+
undefined,
350+
localize('galleryExtensionsCommands', "Install Gallery Extensions"),
351+
true
352+
)
353+
);
354+
}
355+
356+
if (workbenchEnvironmentService.extensionsPath) {
357+
const openExtensionsFolderActionDescriptor = new SyncActionDescriptor(OpenExtensionsFolderAction, OpenExtensionsFolderAction.ID, OpenExtensionsFolderAction.LABEL);
358+
actionRegistry.registerWorkbenchAction(openExtensionsFolderActionDescriptor, 'Extensions: Open Extensions Folder', ExtensionsLabel);
359+
}
360+
361+
}
362+
363+
}
364+
365+
workbenchRegistry.registerWorkbenchContribution(ExtensionsContributions, LifecyclePhase.Starting);
366+
workbenchRegistry.registerWorkbenchContribution(StatusUpdater, LifecyclePhase.Restored);
367+
workbenchRegistry.registerWorkbenchContribution(MaliciousExtensionChecker, LifecyclePhase.Eventually);
368+
workbenchRegistry.registerWorkbenchContribution(ConfigureRecommendedExtensionsCommandsContributor, LifecyclePhase.Eventually);
369+
workbenchRegistry.registerWorkbenchContribution(KeymapExtensions, LifecyclePhase.Restored);
370+
workbenchRegistry.registerWorkbenchContribution(ExtensionsViewletViewsContribution, LifecyclePhase.Starting);
371+
workbenchRegistry.registerWorkbenchContribution(ExtensionActivationProgress, LifecyclePhase.Eventually);
372+
workbenchRegistry.registerWorkbenchContribution(ExtensionDependencyChecker, LifecyclePhase.Eventually);

src/vs/workbench/contrib/extensions/browser/extensionsActions.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,18 +2815,22 @@ export class OpenExtensionsFolderAction extends Action {
28152815
}
28162816

28172817
run(): Promise<void> {
2818-
const extensionsHome = URI.file(this.environmentService.extensionsPath);
2818+
if (this.environmentService.extensionsPath) {
28192819

2820-
return Promise.resolve(this.fileService.resolve(extensionsHome)).then(file => {
2821-
let itemToShow: URI;
2822-
if (file.children && file.children.length > 0) {
2823-
itemToShow = file.children[0].resource;
2824-
} else {
2825-
itemToShow = extensionsHome;
2826-
}
2820+
const extensionsHome = URI.file(this.environmentService.extensionsPath);
28272821

2828-
return this.windowsService.showItemInFolder(itemToShow);
2829-
});
2822+
return Promise.resolve(this.fileService.resolve(extensionsHome)).then(file => {
2823+
let itemToShow: URI;
2824+
if (file.children && file.children.length > 0) {
2825+
itemToShow = file.children[0].resource;
2826+
} else {
2827+
itemToShow = extensionsHome;
2828+
}
2829+
2830+
return this.windowsService.showItemInFolder(itemToShow);
2831+
});
2832+
}
2833+
return Promise.resolve();
28302834
}
28312835
}
28322836

0 commit comments

Comments
 (0)