Skip to content

Commit 6246da9

Browse files
authored
Merge pull request #21 from twentyTwo/bugfix/workspace_folder_tracking
Bugfix/workspace folder tracking
2 parents b103d1b + ec55b01 commit 6246da9

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/summaryView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ export class SummaryViewProvider implements vscode.WebviewViewProvider {
537537
}
538538
}
539539
};
540-
540+
541541
window.addEventListener('message', event => {
542542
const message = event.data;
543543
if (message.command === 'update') {
@@ -781,7 +781,7 @@ export class SummaryViewProvider implements vscode.WebviewViewProvider {
781781
content.innerHTML = '<p>No results found.</p>';
782782
return;
783783
}
784-
784+
785785
// Calculate data for all charts
786786
let totalTime = 0;
787787
const projectData = {};

src/timeTracker.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,51 @@ export class TimeTracker implements vscode.Disposable {
149149

150150
private getCurrentProject(): string {
151151
const workspaceFolders = vscode.workspace.workspaceFolders;
152-
return workspaceFolders ? workspaceFolders[0].name : 'Unknown Project';
152+
if (!workspaceFolders) {
153+
return 'Unknown Project';
154+
}
155+
156+
// Get the active text editor
157+
const activeEditor = vscode.window.activeTextEditor;
158+
if (!activeEditor) {
159+
return 'No Active File';
160+
}
161+
162+
// Get workspace information
163+
const workspaceName = vscode.workspace.name || 'Default Workspace';
164+
const workspaceFolder = vscode.workspace.getWorkspaceFolder(activeEditor.document.uri);
165+
166+
if (!workspaceFolder) {
167+
// File is outside any workspace folder
168+
return `External/${this.getExternalProjectName(activeEditor.document.uri)}`;
169+
}
170+
171+
// If we're in a multi-root workspace, prefix with workspace name
172+
if (workspaceFolders.length > 1) {
173+
return `${workspaceName}/${workspaceFolder.name}`;
174+
}
175+
176+
return workspaceFolder.name;
177+
}
178+
179+
private getExternalProjectName(uri: vscode.Uri): string {
180+
// Handle different scenarios for external files
181+
if (uri.scheme !== 'file') {
182+
return 'Virtual Files';
183+
}
184+
185+
// Get the parent folder name for external files
186+
const path = uri.fsPath;
187+
const parentFolder = path.split(/[\\/]/);
188+
189+
// Remove empty segments and file name
190+
const folders = parentFolder.filter(Boolean);
191+
if (folders.length >= 2) {
192+
// Return "ParentFolder/CurrentFolder"
193+
return `${folders[folders.length - 2]}/${folders[folders.length - 1]}`;
194+
}
195+
196+
return 'Other';
153197
}
154198

155199
getTodayTotal(): number {

0 commit comments

Comments
 (0)