diff --git a/src/vs/base/node/stats.ts b/src/vs/base/node/stats.ts index def7b94207deb9cc2a61d345379b544c51dc5b01..245e3efcc4517651f7055cf539bc9d8ccab21eea 100644 --- a/src/vs/base/node/stats.ts +++ b/src/vs/base/node/stats.ts @@ -5,17 +5,52 @@ 'use strict'; -import { readdirSync, statSync } from 'fs'; +import { readdirSync, statSync, existsSync, readFileSync } from 'fs'; +import { join } from 'path'; export interface WorkspaceStatItem { name: string; - value: number; + count: number; } + export interface WorkspaceStats { fileTypes: WorkspaceStatItem[]; configFiles: WorkspaceStatItem[]; } +function asSortedItems(map: Map): WorkspaceStatItem[] { + let a: WorkspaceStatItem[] = []; + map.forEach((value, index) => a.push({ name: index, count: value })); + return a.sort((a, b) => b.count - a.count); +} + +export function collectLaunchConfigs(folder: string): WorkspaceStatItem[] { + let launchConfigs = new Map(); + + let launchConfig = join(folder, '.vscode', 'launch.json'); + if (existsSync(launchConfig)) { + try { + const contents = readFileSync(launchConfig).toString(); + const json = JSON.parse(contents); + if (json['configurations']) { + for (const each of json['configurations']) { + const type = each['type']; + if (type) { + if (launchConfigs.has(type)) { + launchConfigs.set(type, launchConfigs.get(type) + 1); + } + else { + launchConfigs.set(type, 1); + } + } + } + } + } catch { + } + } + return asSortedItems(launchConfigs); +} + export function collectWorkspaceStats(folder: string, filter: string[]): WorkspaceStats { const configFilePatterns = [ { 'tag': 'grunt.js', 'pattern': /^gruntfile\.js$/i }, @@ -42,9 +77,9 @@ export function collectWorkspaceStats(folder: string, filter: string[]): Workspa let walkSync = (dir: string, acceptFile: (fileName: string) => void, filter: string[]) => { let files = readdirSync(dir); for (const file of files) { - if (statSync(dir + '/' + file).isDirectory()) { + if (statSync(join(dir, file)).isDirectory()) { if (filter.indexOf(file) === -1) { - walkSync(dir + '/' + file, acceptFile, filter); + walkSync(join(dir, file), acceptFile, filter); } } else { @@ -84,12 +119,6 @@ export function collectWorkspaceStats(folder: string, filter: string[]): Workspa addConfigFiles(name); }; - let asSortedItems = (map: Map): WorkspaceStatItem[] => { - let a: WorkspaceStatItem[] = []; - map.forEach((value, index) => a.push({ name: index, value: value })); - return a.sort((a, b) => b.value - a.value); - }; - walkSync(folder, acceptFile, filter); let result = { diff --git a/src/vs/code/electron-main/diagnostics.ts b/src/vs/code/electron-main/diagnostics.ts index bc59aaf8d7440141dc9cd0f55c4b995e1e33149d..4ce3f82633a05695dddda312a06cb1f07068ae72 100644 --- a/src/vs/code/electron-main/diagnostics.ts +++ b/src/vs/code/electron-main/diagnostics.ts @@ -5,7 +5,7 @@ 'use strict'; -import { WorkspaceStats, collectWorkspaceStats } from 'vs/base/node/stats'; +import { WorkspaceStats, collectWorkspaceStats, collectLaunchConfigs, WorkspaceStatItem } from 'vs/base/node/stats'; import { IMainProcessInfo } from 'vs/code/electron-main/launch'; import { ProcessItem, listProcesses } from 'vs/base/node/ps'; import product from 'vs/platform/node/product'; @@ -43,6 +43,11 @@ export function printDiagnostics(info: IMainProcessInfo): Promise { console.log(`| Folder (${basename(folder)})`); const stats = collectWorkspaceStats(folder, ['node_modules', '.git']); console.log(formatWorkspaceStats(stats)); + + const launchConfigs = collectLaunchConfigs(folder); + if (launchConfigs.length > 0) { + console.log(formatLaunchConfigs(launchConfigs)); + } }); }); } @@ -56,8 +61,9 @@ function formatWorkspaceStats(workspaceStats: WorkspaceStats): string { const lineLength = 60; let col = 0; - const appendAndWrap = (index: string, value: number) => { - const item = ` ${index}(${value})`; + const appendAndWrap = (name: string, count: number) => { + const item = count > 1 ? ` ${name}(${count})` : ` ${name}`; + if (col + item.length > lineLength) { output.push(line); line = '| '; @@ -81,21 +87,29 @@ function formatWorkspaceStats(workspaceStats: WorkspaceStats): string { output.push(line); // Conf Files - line = '| Conf files:'; - col = 0; - let hasConfFiles = false; - workspaceStats.configFiles.forEach((item) => { - hasConfFiles = true; - appendAndWrap(item.name, item.value); - }); - if (!hasConfFiles) { - line = `${line} `; + if (workspaceStats.configFiles.length >= 0) { + line = '| Conf files:'; + col = 0; + workspaceStats.configFiles.forEach((item) => { + appendAndWrap(item.name, item.count); + }); + output.push(line); } - output.push(line); return output.join('\n'); } +function formatLaunchConfigs(configs: WorkspaceStatItem[]): string { + const output: string[] = []; + let line = '| Launch Configs:'; + configs.forEach(each => { + const item = each.count > 1 ? ` ${each.name}(${each.count})` : ` ${each.name}`; + line += item; + }); + output.push(line); + return output.join('\n'); +} + function formatEnvironment(info: IMainProcessInfo): string { const MB = 1024 * 1024; const GB = 1024 * MB;