Skip to content

Commit 6b30ade

Browse files
author
Benjamin Pasero
committed
startup - convert workspacestats to workbench contribution
1 parent 8e97fef commit 6b30ade

9 files changed

Lines changed: 56 additions & 13 deletions

File tree

src/vs/platform/windows/common/windows.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export interface IWindowService {
169169

170170
onDidChangeFocus: Event<boolean>;
171171

172+
getConfiguration(): IWindowConfiguration;
172173
getCurrentWindowId(): number;
173174
pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void>;
174175
pickFileAndOpen(options: INativeOpenDialogOptions): TPromise<void>;

src/vs/platform/windows/electron-browser/windowService.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Event, { filterEvent, mapEvent, anyEvent } from 'vs/base/common/event';
99
import { TPromise } from 'vs/base/common/winjs.base';
10-
import { IWindowService, IWindowsService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult } from 'vs/platform/windows/common/windows';
10+
import { IWindowService, IWindowsService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, IWindowConfiguration } from 'vs/platform/windows/common/windows';
1111
import { remote } from 'electron';
1212
import { IRecentlyOpened } from 'vs/platform/history/common/history';
1313
import { ICommandAction } from 'vs/platform/actions/common/actions';
@@ -23,6 +23,7 @@ export class WindowService implements IWindowService {
2323

2424
constructor(
2525
private windowId: number,
26+
private configuration: IWindowConfiguration,
2627
@IWindowsService private windowsService: IWindowsService
2728
) {
2829
const onThisWindowFocus = mapEvent(filterEvent(windowsService.onWindowFocus, id => id === windowId), _ => true);
@@ -34,6 +35,10 @@ export class WindowService implements IWindowService {
3435
return this.windowId;
3536
}
3637

38+
getConfiguration(): IWindowConfiguration {
39+
return this.configuration;
40+
}
41+
3742
pickFileFolderAndOpen(options: INativeOpenDialogOptions): TPromise<void> {
3843
options.windowId = this.windowId;
3944

src/vs/workbench/electron-browser/shell.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import ErrorTelemetry from 'vs/platform/telemetry/browser/errorTelemetry';
3030
import { ElectronWindow } from 'vs/workbench/electron-browser/window';
3131
import { resolveWorkbenchCommonProperties, getOrCreateMachineId } from 'vs/platform/telemetry/node/workbenchCommonProperties';
3232
import { machineIdIpcChannel } from 'vs/platform/telemetry/node/commonProperties';
33-
import { WorkspaceStats } from 'vs/workbench/services/telemetry/node/workspaceStats';
3433
import { IWindowsService, IWindowService, IWindowConfiguration } from 'vs/platform/windows/common/windows';
3534
import { WindowService } from 'vs/platform/windows/electron-browser/windowService';
3635
import { MessageService } from 'vs/workbench/services/message/electron-browser/messageService';
@@ -249,11 +248,6 @@ export class WorkbenchShell {
249248
this.telemetryService.publicLog('startupTime', this.timerService.startupMetrics);
250249
});
251250

252-
// Telemetry: workspace tags
253-
const workspaceStats: WorkspaceStats = <WorkspaceStats>this.workbench.getInstantiationService().createInstance(WorkspaceStats);
254-
workspaceStats.reportWorkspaceTags(this.configuration);
255-
workspaceStats.reportCloudStats();
256-
257251
// Root Warning
258252
if ((platform.isLinux || platform.isMacintosh) && process.getuid() === 0) {
259253
this.messageService.show(Severity.Warning, nls.localize('runningAsRoot', "It is recommended not to run Code as 'root'."));
@@ -285,7 +279,7 @@ export class WorkbenchShell {
285279
this.broadcastService = new BroadcastService(currentWindow.id);
286280
serviceCollection.set(IBroadcastService, this.broadcastService);
287281

288-
serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, currentWindow.id));
282+
serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, currentWindow.id, this.configuration));
289283

290284
const sharedProcess = (<IWindowsService>serviceCollection.get(IWindowsService)).whenSharedProcessReady()
291285
.then(() => connectNet(this.environmentService.sharedIPCHandle, `window:${currentWindow.id}`));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { Registry } from 'vs/platform/registry/common/platform';
9+
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
10+
import { WorkspaceStatsReporter } from 'vs/workbench/parts/stats/node/workspaceStats';
11+
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
12+
13+
// Register Workspace Stats Contribution
14+
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(WorkspaceStatsReporter, LifecyclePhase.Running);

src/vs/workbench/services/telemetry/node/workspaceStats.ts renamed to src/vs/workbench/parts/stats/node/workspaceStats.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import { IFileService, IFileStat } from 'vs/platform/files/common/files';
1313
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1414
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
1515
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
16-
import { IWindowConfiguration } from 'vs/platform/windows/common/windows';
16+
import { IWindowConfiguration, IWindowService } from 'vs/platform/windows/common/windows';
17+
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
18+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1719

1820
const SshProtocolMatcher = /^([^@:]+@)?([^:]+):/;
1921
const SshUrlMatcher = /^([^@:]+@)?([^:]+):(.+)$/;
@@ -131,7 +133,7 @@ export function getHashedRemotes(text: string): string[] {
131133
});
132134
}
133135

134-
export class WorkspaceStats {
136+
class WorkspaceStats {
135137
constructor(
136138
@IFileService private fileService: IFileService,
137139
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@@ -414,3 +416,24 @@ export class WorkspaceStats {
414416
}
415417
}
416418
}
419+
420+
// Telemetry: workspace tags
421+
export class WorkspaceStatsReporter implements IWorkbenchContribution {
422+
423+
constructor(
424+
@IInstantiationService private instantiationService: IInstantiationService,
425+
@IWindowService private windowService: IWindowService
426+
) {
427+
this.reportWorkspaceStats();
428+
}
429+
430+
public getId(): string {
431+
return 'vs.backup.backupModelTracker';
432+
}
433+
434+
private reportWorkspaceStats(): void {
435+
const workspaceStats: WorkspaceStats = this.instantiationService.createInstance(WorkspaceStats);
436+
workspaceStats.reportWorkspaceTags(this.windowService.getConfiguration());
437+
workspaceStats.reportCloudStats();
438+
}
439+
}

src/vs/workbench/services/telemetry/test/workspaceStats.test.ts renamed to src/vs/workbench/parts/stats/test/workspaceStats.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import * as assert from 'assert';
99
import * as crypto from 'crypto';
10-
import { getDomainsOfRemotes, getRemotes, getHashedRemotes } from 'vs/workbench/services/telemetry/node/workspaceStats';
10+
import { getDomainsOfRemotes, getRemotes, getHashedRemotes } from 'vs/workbench/parts/stats/node/workspaceStats';
1111

1212
function hash(value: string): string {
1313
return crypto.createHash('sha1').update(value.toString()).digest('hex');

src/vs/workbench/test/workbenchTestServices.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
4646
import { IHistoryService } from 'vs/workbench/services/history/common/history';
4747
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
4848
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
49-
import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult } from 'vs/platform/windows/common/windows';
49+
import { IWindowsService, IWindowService, INativeOpenDialogOptions, IEnterWorkspaceResult, IMessageBoxResult, IWindowConfiguration } from 'vs/platform/windows/common/windows';
5050
import { TestWorkspace } from 'vs/platform/workspace/test/common/testWorkspace';
5151
import { RawTextSource, IRawTextSource } from 'vs/editor/common/model/textSource';
5252
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -890,6 +890,10 @@ export class TestWindowService implements IWindowService {
890890
return TPromise.as(false);
891891
}
892892

893+
getConfiguration(): IWindowConfiguration {
894+
return Object.create(null);
895+
}
896+
893897
getCurrentWindowId(): number {
894898
return 0;
895899
}

src/vs/workbench/workbench.main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import 'vs/workbench/parts/files/browser/files.contribution';
4242

4343
import 'vs/workbench/parts/backup/common/backup.contribution';
4444

45+
import 'vs/workbench/parts/stats/node/stats.contribution';
46+
4547
import 'vs/workbench/parts/search/browser/search.contribution';
4648
import 'vs/workbench/parts/search/browser/searchViewlet'; // can be packaged separately
4749
import 'vs/workbench/parts/search/browser/openAnythingHandler'; // can be packaged separately

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@
421421
},
422422
{
423423
"target": "{**/**.test.ts,**/test/**}",
424-
"restrictions": "{**/vs/**,assert,sinon}"
424+
"restrictions": "{**/vs/**,assert,sinon,crypto}"
425425
},
426426
{
427427
"target": "**/{common,browser,workbench}/**",

0 commit comments

Comments
 (0)