Skip to content

Commit d393bcc

Browse files
committed
debug(timer): add comprehensive logging and fix config access
Add detailed console logging throughout timer decoration creation to help diagnose rendering issues. Fix global configuration access by properly setting timerConfig instead of undefined global variables. - Add debug logs for each step of decoration creation process - Log file processing, task detection, and decoration count - Fix timerConfig initialization in taskTimerExtension function - Add test file with proper frontmatter for timer functionality - Enable troubleshooting of timer widget display issues
1 parent 51dc752 commit d393bcc

2 files changed

Lines changed: 47 additions & 5 deletions

File tree

src/editor-ext/taskTimer.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,18 +431,27 @@ const taskTimerStateField = StateField.define<DecorationSet>({
431431
* Create task timer decorations for the current state
432432
*/
433433
function createTaskTimerDecorations(state: EditorState): DecorationSet {
434+
console.log("[TaskTimer] Creating decorations, timerConfig:", timerConfig);
435+
434436
if (!timerConfig?.settings?.enabled) {
437+
console.log("[TaskTimer] Timer not enabled or no config");
435438
return Decoration.none;
436439
}
437440

438441
// Get editor info to access app and file information
439442
const editorInfo = state.field(editorInfoField);
440443
if (!editorInfo?.app) {
444+
console.log("[TaskTimer] No editor info or app");
441445
return Decoration.none;
442446
}
443447

444448
const file = editorInfo.app.workspace.getActiveFile();
445-
if (!file) return Decoration.none;
449+
if (!file) {
450+
console.log("[TaskTimer] No active file");
451+
return Decoration.none;
452+
}
453+
454+
console.log("[TaskTimer] Processing file:", file.path);
446455

447456
const metadataDetector = new TaskTimerMetadataDetector(
448457
editorInfo.app,
@@ -451,20 +460,27 @@ function createTaskTimerDecorations(state: EditorState): DecorationSet {
451460
);
452461

453462
if (!metadataDetector.isTimerEnabledForFile(file)) {
463+
console.log("[TaskTimer] Timer not enabled for file:", file.path);
454464
return Decoration.none;
455465
}
456466

467+
console.log("[TaskTimer] Timer enabled for file, processing...");
468+
457469
const timerManager = new TaskTimerManager(timerConfig.settings);
458470
const decorations: Range<Decoration>[] = [];
459471
const doc = state.doc;
460472

473+
console.log("[TaskTimer] Document has", doc.lines, "lines");
474+
461475
// Process all lines in the document
462476
for (let i = 1; i <= doc.lines; i++) {
463477
const line = doc.line(i);
464478
const lineText = line.text;
465479

466480
// Check if this line contains a task
467481
if (isTaskLine(lineText)) {
482+
console.log("[TaskTimer] Found task line:", lineText.trim());
483+
468484
// Use existing folding logic to check if this is a parent task
469485
const range = calculateRangeForTransform(state, {
470486
from: line.from,
@@ -476,6 +492,7 @@ function createTaskTimerDecorations(state: EditorState): DecorationSet {
476492
range.to > line.to &&
477493
hasSubTasks(doc.sliceString(range.from, range.to), lineText)
478494
) {
495+
console.log("[TaskTimer] Found parent task with subtasks");
479496
// Extract existing block reference if present
480497
const existingBlockId = extractBlockRef(lineText);
481498

@@ -496,10 +513,12 @@ function createTaskTimerDecorations(state: EditorState): DecorationSet {
496513

497514
// Add decoration at the start of the line
498515
decorations.push(timerDeco.range(line.from));
516+
console.log("[TaskTimer] Added timer decoration for line:", i);
499517
}
500518
}
501519
}
502520

521+
console.log("[TaskTimer] Created", decorations.length, "timer decorations");
503522
return Decoration.set(decorations, true);
504523
}
505524

@@ -571,10 +590,11 @@ export function taskTimerExtension(
571590
settings: TaskTimerSettings,
572591
metadataCache: MetadataCache
573592
) {
574-
// Set global references for StateField access
575-
globalApp = app;
576-
globalSettings = settings;
577-
globalMetadataCache = metadataCache;
593+
// Set global configuration for StateField access
594+
timerConfig = {
595+
settings,
596+
metadataCache
597+
};
578598

579599
return [taskTimerStateField];
580600
}

test-timer.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
task-timer: true
3+
---
4+
5+
# Task Timer Test
6+
7+
## Project Tasks
8+
9+
- [ ] Parent task with subtasks
10+
- [ ] Subtask 1
11+
- [ ] Subtask 2
12+
- [ ] Subtask 3
13+
14+
- [ ] Another parent task
15+
- [ ] Nested subtask A
16+
- [ ] Nested subtask B
17+
18+
- [ ] Simple task without subtasks
19+
20+
## Notes
21+
22+
This file should show timer widgets above parent tasks when the task timer plugin is enabled.

0 commit comments

Comments
 (0)