From 5f1a9a4f573f9237bfe138f25927d9a38b7152c8 Mon Sep 17 00:00:00 2001 From: Joe Maloney Date: Wed, 28 Jan 2026 15:18:55 -0500 Subject: [PATCH 1/2] Add Feature to autodetect VSCC output directory --- src/data/vscc_datasource.ts | 45 +++++++++++++++++++++++++++++-------- src/extension.ts | 2 +- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/data/vscc_datasource.ts b/src/data/vscc_datasource.ts index 24950ed..b2980d3 100644 --- a/src/data/vscc_datasource.ts +++ b/src/data/vscc_datasource.ts @@ -1,22 +1,49 @@ -import { Uri } from "vscode"; - +import { Uri, workspace } from 'vscode'; +import { isAbsolute, join, normalize } from 'path'; export class VSCCDataSource { public data: object = Object; public folder: String = ''; public date: String = ''; private _dataFolderUri: Uri; - public constructor(wsUri: Uri, targetDir: Uri) { - this._dataFolderUri = Uri.joinPath(wsUri, '.VSCodeCounter');; + public constructor(wsUri: Uri) { + this._dataFolderUri = this._getVSCCDataFolder(wsUri); this._selectDataSourceFolder(wsUri); this._readDataSource(); } - private _selectDataSourceFolder(wsUri: Uri) { - let result: {date: String, path: String}[] = []; - const fs = require('fs'); - const dirPath = fs.readdirSync(this._dataFolderUri.fsPath); - dirPath.map((item: String) => { + private _getVSCCDataFolder(wsUri: Uri): Uri { + const defaultPath = '.VSCodeCounter'; + const autoPathDetectEnabled = workspace + .getConfiguration('CodeViz') + .get('autoDetectCounterOutputPath'); + if (autoPathDetectEnabled) { + return this._generateVSCCUri(wsUri, defaultPath); + } else { + return Uri.joinPath(wsUri, defaultPath); + } + } + + private _generateVSCCUri(wsUri: Uri, defaultPath: string): Uri { + let counterOutputDir = workspace + .getConfiguration('VSCodeCounter') + .get('outputDirectory'); + + if (counterOutputDir) { + if (isAbsolute(counterOutputDir)) { + return Uri.file(counterOutputDir); + } else { + return Uri.joinPath(wsUri, counterOutputDir); + } + } else { + return Uri.joinPath(wsUri, defaultPath); + } + } + private _selectDataSourceFolder(wsUri: Uri) { + let result: { date: String; path: String }[] = []; + const fs = require('fs'); + const dirPath = fs.readdirSync(this._dataFolderUri.fsPath); + dirPath.map((item: String) => { let path = Uri.joinPath(this._dataFolderUri, item.valueOf()); result.push({date: item, path: path.fsPath}); }); diff --git a/src/extension.ts b/src/extension.ts index 98e2d66..ace70a4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -45,7 +45,7 @@ export function activate(context: ExtensionContext) { let source: VSCCDataSource; if (targetDir == undefined) targetDir = wsPath; - source = new VSCCDataSource(wsPath, targetDir); + source = new VSCCDataSource(wsPath); if (source.data != undefined) { let data = new VSCCDataPrep(); data.makeDataTable(source.data); From 3993dbe9b1cf089a9dc4318b20f53a9e132d0974 Mon Sep 17 00:00:00 2001 From: Joe Maloney Date: Wed, 28 Jan 2026 15:20:23 -0500 Subject: [PATCH 2/2] Add option to disable/enable autodetect VSCC output directory feature --- package.json | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/package.json b/package.json index faf1cac..0db0dd4 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,16 @@ } ] }, + "configuration": { + "title": "CodeViz Stats", + "properties": { + "CodeViz.autoDetectCounterOutputPath": { + "type": "boolean", + "default": true, + "description": "Enable this to get the Visual Studio Code Counter (VSCC) output path setting automatically when running \"CodeViz: Show statistics\". Disable this to use the default VSCC output path \"%workspaceFolder%/.VSCodeCounter\"." + } + } + }, "commands": [ { "command": "CodeViz.show",