提交 0edcbadb 编写于 作者: B Benjamin Pasero

💄

上级 a53164fe
...@@ -178,6 +178,8 @@ export function getHashedRemotesFromUri(workspaceUri: URI, fileService: IFileSer ...@@ -178,6 +178,8 @@ export function getHashedRemotesFromUri(workspaceUri: URI, fileService: IFileSer
export class WorkspaceStats implements IWorkbenchContribution { export class WorkspaceStats implements IWorkbenchContribution {
static TAGS: Tags;
private static DISABLE_WORKSPACE_PROMPT_KEY = 'workspaces.dontPromptToOpen'; private static DISABLE_WORKSPACE_PROMPT_KEY = 'workspaces.dontPromptToOpen';
constructor( constructor(
...@@ -190,11 +192,18 @@ export class WorkspaceStats implements IWorkbenchContribution { ...@@ -190,11 +192,18 @@ export class WorkspaceStats implements IWorkbenchContribution {
@IQuickInputService private quickInputService: IQuickInputService, @IQuickInputService private quickInputService: IQuickInputService,
@IStorageService private storageService: IStorageService @IStorageService private storageService: IStorageService
) { ) {
this.reportWorkspaceTags(windowService.getConfiguration()); this.report();
this.reportCloudStats();
} }
static TAGS: Tags; private report(): void {
// Workspace Stats
this.resolveWorkspaceTags(this.windowService.getConfiguration(), rootFiles => this.handleWorkspaceFiles(rootFiles))
.then(tags => this.reportWorkspaceTags(tags), error => onUnexpectedError(error));
// Cloud Stats
this.reportCloudStats();
}
private searchArray(arr: string[], regEx: RegExp): boolean { private searchArray(arr: string[], regEx: RegExp): boolean {
return arr.some(v => v.search(regEx) > -1) || undefined; return arr.some(v => v.search(regEx) > -1) || undefined;
...@@ -243,21 +252,19 @@ export class WorkspaceStats implements IWorkbenchContribution { ...@@ -243,21 +252,19 @@ export class WorkspaceStats implements IWorkbenchContribution {
"workspace.reactNative" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true } "workspace.reactNative" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
} }
*/ */
private getWorkspaceTags(configuration: IWindowConfiguration): TPromise<Tags> { private resolveWorkspaceTags(configuration: IWindowConfiguration, participant?: (rootFiles: string[]) => void): TPromise<Tags> {
const tags: Tags = Object.create(null); const tags: Tags = Object.create(null);
const state = this.contextService.getWorkbenchState(); const state = this.contextService.getWorkbenchState();
const workspace = this.contextService.getWorkspace(); const workspace = this.contextService.getWorkspace();
let workspaceId: string; let workspaceId: string;
let isSingleLocalWorkspaceFolder = false;
switch (state) { switch (state) {
case WorkbenchState.EMPTY: case WorkbenchState.EMPTY:
workspaceId = void 0; workspaceId = void 0;
break; break;
case WorkbenchState.FOLDER: case WorkbenchState.FOLDER:
isSingleLocalWorkspaceFolder = workspace.folders[0].uri.scheme === Schemas.file; workspaceId = crypto.createHash('sha1').update(workspace.folders[0].uri.scheme === Schemas.file ? workspace.folders[0].uri.fsPath : workspace.folders[0].uri.toString()).digest('hex');
workspaceId = crypto.createHash('sha1').update(isSingleLocalWorkspaceFolder ? workspace.folders[0].uri.fsPath : workspace.folders[0].uri.toString()).digest('hex');
break; break;
case WorkbenchState.WORKSPACE: case WorkbenchState.WORKSPACE:
workspaceId = crypto.createHash('sha1').update(workspace.configuration.fsPath).digest('hex'); workspaceId = crypto.createHash('sha1').update(workspace.configuration.fsPath).digest('hex');
...@@ -283,6 +290,10 @@ export class WorkspaceStats implements IWorkbenchContribution { ...@@ -283,6 +290,10 @@ export class WorkspaceStats implements IWorkbenchContribution {
const names = (<IFileStat[]>[]).concat(...files.map(result => result.success ? (result.stat.children || []) : [])).map(c => c.name); const names = (<IFileStat[]>[]).concat(...files.map(result => result.success ? (result.stat.children || []) : [])).map(c => c.name);
const nameSet = names.reduce((s, n) => s.add(n.toLowerCase()), new Set()); const nameSet = names.reduce((s, n) => s.add(n.toLowerCase()), new Set());
if (participant) {
participant(names);
}
tags['workspace.grunt'] = nameSet.has('gruntfile.js'); tags['workspace.grunt'] = nameSet.has('gruntfile.js');
tags['workspace.gulp'] = nameSet.has('gulpfile.js'); tags['workspace.gulp'] = nameSet.has('gulpfile.js');
tags['workspace.jake'] = nameSet.has('jakefile.js'); tags['workspace.jake'] = nameSet.has('jakefile.js');
...@@ -361,19 +372,24 @@ export class WorkspaceStats implements IWorkbenchContribution { ...@@ -361,19 +372,24 @@ export class WorkspaceStats implements IWorkbenchContribution {
}); });
}); });
// Handle top-level workspace files for local single folder workspace
if (isSingleLocalWorkspaceFolder) {
const workspaceFiles = names.filter(name => extname(name) === `.${WORKSPACE_EXTENSION}`);
if (workspaceFiles.length > 0) {
this.handleWorkspaceFiles(workspace.folders[0].uri, workspaceFiles);
}
}
return TPromise.join(packageJsonPromises).then(() => tags); return TPromise.join(packageJsonPromises).then(() => tags);
}); });
} }
private handleWorkspaceFiles(folder: URI, workspaces: string[]): void { private handleWorkspaceFiles(rootFiles: string[]): void {
const state = this.contextService.getWorkbenchState();
const workspace = this.contextService.getWorkspace();
// Handle top-level workspace files for local single folder workspace
if (state === WorkbenchState.FOLDER && workspace.folders[0].uri.scheme === Schemas.file) {
const workspaceFiles = rootFiles.filter(name => extname(name) === `.${WORKSPACE_EXTENSION}`);
if (workspaceFiles.length > 0) {
this.doHandleWorkspaceFiles(workspace.folders[0].uri, workspaceFiles);
}
}
}
private doHandleWorkspaceFiles(folder: URI, workspaces: string[]): void {
if (this.storageService.getBoolean(WorkspaceStats.DISABLE_WORKSPACE_PROMPT_KEY, StorageScope.WORKSPACE)) { if (this.storageService.getBoolean(WorkspaceStats.DISABLE_WORKSPACE_PROMPT_KEY, StorageScope.WORKSPACE)) {
return; // prompt disabled by user return; // prompt disabled by user
} }
...@@ -388,7 +404,7 @@ export class WorkspaceStats implements IWorkbenchContribution { ...@@ -388,7 +404,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
if (workspaces.length === 1) { if (workspaces.length === 1) {
const workspaceFile = workspaces[0]; const workspaceFile = workspaces[0];
this.notificationService.prompt(Severity.Info, localize('workspaceFound', "This folder contains a workspace file '{0}'. Do you want to open it (click [here]({1}) to learn more)?", workspaceFile, 'https://code.visualstudio.com/docs/editor/multi-root-workspaces'), [{ this.notificationService.prompt(Severity.Info, localize('workspaceFound', "This folder contains a workspace file '{0}'. Do you want to open it (click [here]({1}) to learn more)?", workspaceFile, 'https://go.microsoft.com/fwlink/?linkid=2025315'), [{
label: localize('openWorkspace', "Open Workspace"), label: localize('openWorkspace', "Open Workspace"),
run: () => this.windowService.openWindow([URI.file(join(folder.fsPath, workspaceFile))]) run: () => this.windowService.openWindow([URI.file(join(folder.fsPath, workspaceFile))])
}, doNotShowAgain]); }, doNotShowAgain]);
...@@ -396,7 +412,7 @@ export class WorkspaceStats implements IWorkbenchContribution { ...@@ -396,7 +412,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
// Prompt to select a workspace from many // Prompt to select a workspace from many
else if (workspaces.length > 1) { else if (workspaces.length > 1) {
this.notificationService.prompt(Severity.Info, localize('workspacesFound', "This folder contains multiple workspace files. Do you want to open one (click [here]({0}) to learn more)?", 'https://code.visualstudio.com/docs/editor/multi-root-workspaces'), [{ this.notificationService.prompt(Severity.Info, localize('workspacesFound', "This folder contains multiple workspace files. Do you want to open one (click [here]({0}) to learn more)?", 'https://go.microsoft.com/fwlink/?linkid=2025315'), [{
label: localize('selectWorkspace', "Select Workspace"), label: localize('selectWorkspace', "Select Workspace"),
run: () => { run: () => {
this.quickInputService.pick( this.quickInputService.pick(
...@@ -433,18 +449,16 @@ export class WorkspaceStats implements IWorkbenchContribution { ...@@ -433,18 +449,16 @@ export class WorkspaceStats implements IWorkbenchContribution {
return i !== -1 ? uri.with({ path: path.substr(0, i) }) : undefined; return i !== -1 ? uri.with({ path: path.substr(0, i) }) : undefined;
} }
reportWorkspaceTags(configuration: IWindowConfiguration): void { private reportWorkspaceTags(tags: Tags): void {
this.getWorkspaceTags(configuration).then((tags) => { /* __GDPR__
/* __GDPR__ "workspce.tags" : {
"workspce.tags" : { "${include}": [
"${include}": [ "${WorkspaceTags}"
"${WorkspaceTags}" ]
] }
} */
*/ this.telemetryService.publicLog('workspce.tags', tags);
this.telemetryService.publicLog('workspce.tags', tags); WorkspaceStats.TAGS = tags;
WorkspaceStats.TAGS = tags;
}, error => onUnexpectedError(error));
} }
private reportRemoteDomains(workspaceUris: URI[]): void { private reportRemoteDomains(workspaceUris: URI[]): void {
...@@ -549,7 +563,7 @@ export class WorkspaceStats implements IWorkbenchContribution { ...@@ -549,7 +563,7 @@ export class WorkspaceStats implements IWorkbenchContribution {
}).then(null, onUnexpectedError); }).then(null, onUnexpectedError);
} }
reportCloudStats(): void { private reportCloudStats(): void {
const uris = this.contextService.getWorkspace().folders.map(folder => folder.uri); const uris = this.contextService.getWorkspace().folders.map(folder => folder.uri);
if (uris.length && this.fileService) { if (uris.length && this.fileService) {
this.reportRemoteDomains(uris); this.reportRemoteDomains(uris);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册