Skip to content

Commit def4c2a

Browse files
authored
Merge pull request #238 from pajoma/refactor/234-phase4-feature-folders
refactor: package-by-feature layout + events bus (Phase 4, #234)
2 parents bf78814 + d117b26 commit def4c2a

97 files changed

Lines changed: 294 additions & 300 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/container.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919
'use strict';
2020

2121
import * as vscode from 'vscode';
22-
import { IConfiguration, IFileSystem, ILogger, IWorkspaceConfigReader, JournalController } from '../model';
23-
import { Configuration } from '../vscode/conf';
24-
import { Parser } from '../journal/parser';
25-
import { Writer } from '../journal/writer';
26-
import { Reader } from '../journal/reader';
27-
import { Inject } from '../journal/inject';
28-
import { Dialogues } from '../vscode/dialogues';
29-
import { VscodeFileSystem } from '../vscode/vscode-fs';
22+
import { IConfiguration, IFileSystem, ILogger, IWorkspaceConfigReader, JournalController } from '../shared/model/index';
23+
import { Configuration } from '../shared/config/configuration';
24+
import { Parser } from '../features/smart-input/parser';
25+
import { Writer } from '../features/entries/writer';
26+
import { Reader } from '../features/entries/reader';
27+
import { Inject } from '../features/entries/inject';
28+
import { Dialogues } from '../features/smart-input/dialogues';
29+
import { VscodeFileSystem } from '../shared/fs/vscode-fs';
30+
import { JournalEvents } from '../shared/events';
31+
import { getWeekFromURIAndConfig } from '../shared/paths';
32+
import { SyncDailyLinks } from '../features/weekly/sync-daily-links';
3033

3134
/**
3235
* Builds the logger once the configuration is available. The logger needs the
@@ -51,6 +54,7 @@ export class Container implements JournalController {
5154
public readonly ui: Dialogues;
5255
public readonly writer: Writer;
5356
public readonly reader: Reader;
57+
public readonly events: JournalEvents;
5458

5559
constructor(configSource: IWorkspaceConfigReader, loggerFactory: LoggerFactory) {
5660
this.config = new Configuration(configSource);
@@ -62,5 +66,25 @@ export class Container implements JournalController {
6266
this.writer = new Writer(this.config, this.logger, this.inject, this.fs,
6367
async (path) => vscode.workspace.openTextDocument(vscode.Uri.file(path)));
6468
this.reader = new Reader(this.config, this.logger, this.writer, this.ui, this.fs);
69+
this.events = new JournalEvents();
70+
71+
// Cross-feature: when an entry opens, the weekly feature refreshes its
72+
// daily-entry links. Wired here (composition root) so the entries
73+
// feature need not import the weekly feature.
74+
this.events.onEntryOpened(({ doc }) => this.syncWeeklyOnEntryOpened(doc));
75+
}
76+
77+
private syncWeeklyOnEntryOpened(doc: vscode.TextDocument): void {
78+
// Fire-and-forget — must never reject the open flow.
79+
getWeekFromURIAndConfig(doc.uri, this.config)
80+
.then(weekInfo => {
81+
if (weekInfo && this.config.getWeeklySyncConfig().enabled) {
82+
const scopeId = weekInfo.scope === 'default' ? undefined : weekInfo.scope;
83+
new SyncDailyLinks(this)
84+
.sync(doc, weekInfo.week, weekInfo.year, scopeId)
85+
.catch(err => this.logger.error("entryOpened weekly sync failed:", err));
86+
}
87+
})
88+
.catch(err => this.logger.error("entryOpened getWeekFromURIAndConfig failed:", err));
6589
}
6690
}

src/app/register.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@
2020

2121
import * as vscode from 'vscode';
2222
import { Container } from './container';
23-
import {
24-
OpenJournalWorkspaceCommand, OpenNextEntryCommand, OpenPreviousEntryCommand,
25-
PrintDurationCommand, PrintSumCommand, PrintTimeCommand, ShiftTaskCommand,
26-
ShowEntryForInputCommand, ShowEntryForTodayCommand, ShowEntryForTomorrowCommand,
27-
ShowEntryForYesterdayCommand, ShowNoteCommand,
28-
} from '../commands';
29-
import { SyncDailyLinks, SyncNoteLinks, WeeklyEntryWatcher } from '../features';
30-
import { CompletedTaskActions, OpenTaskActions } from '../ui';
23+
import { OpenJournalWorkspaceCommand } from '../features/tools/commands/open-journal-workspace';
24+
import { PrintTimeCommand } from '../features/tools/commands/print-current-time';
25+
import { PrintDurationCommand } from '../features/tools/commands/print-duration-between-selected-times';
26+
import { PrintSumCommand } from '../features/tools/commands/print-sum-of-selected-numbers';
27+
import { CopyTaskCommand as ShiftTaskCommand } from '../features/tasks/commands/copy-task';
28+
import { OpenNextEntryCommand } from '../features/navigation/commands/open-next-entry';
29+
import { OpenPreviousEntryCommand } from '../features/navigation/commands/open-previous-entry';
30+
import { ShowEntryForInputCommand } from '../features/entries/commands/show-entry-for-input';
31+
import { ShowEntryForTodayCommand } from '../features/entries/commands/show-entry-for-today';
32+
import { ShowEntryForTomorrowCommand } from '../features/entries/commands/show-entry-for-tomorrow';
33+
import { ShowEntryForYesterdayCommand } from '../features/entries/commands/show-entry-for-yesterday';
34+
import { ShowNoteCommand } from '../features/notes/commands/show-note';
35+
import { WeeklyEntryWatcher } from '../features/weekly/weekly-entry-watcher';
36+
import { SyncDailyLinks } from '../features/weekly/sync-daily-links';
37+
import { SyncNoteLinks } from '../features/notes/sync-note-links';
38+
import { CompletedTaskActions } from '../features/tasks/codeactions/for-completed-tasks';
39+
import { OpenTaskActions } from '../features/tasks/codeactions/for-open-tasks';
3140

3241
const MARKDOWN_SELECTOR: vscode.DocumentSelector = { scheme: 'file', language: 'markdown' };
3342

src/app/startup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import * as vscode from 'vscode';
2222
import * as Path from 'path';
23-
import { isNullOrUndefined, ConsoleLogger } from '../util';
24-
import { Configuration } from '../vscode/conf';
23+
import { isNullOrUndefined, ConsoleLogger } from '../shared/index';
24+
import { Configuration } from '../shared/config/configuration';
2525
import { Container } from './container';
2626
import { registerCacheInvalidation, registerCodeActions, registerCommands } from './register';
2727

src/commands/index.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121

2222
import * as vscode from 'vscode';
23-
import { Configuration } from './vscode';
24-
import { Startup } from './app';
23+
import { Configuration } from './shared/config/configuration';
24+
import { Startup } from './app/index';
2525

2626
export var journalStartup: Startup;
2727
export var journalConfiguration: Configuration;

src/commands/show-entry-for-date.ts renamed to src/features/entries/commands/show-entry-for-date.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
'use strict';
1919

2020
import * as vscode from 'vscode';
21-
import { LoadNotes } from '../features';
22-
import { JournalController, Input } from '../model';
23-
import { NoteInput, SelectedInput, ScopedTemplate } from '../model';
24-
import { getWeekFromURIAndConfig, isRemoteSession, toLocalFileUri } from '../journal/paths';
25-
import { SyncDailyLinks } from '../features/sync/sync-daily-links';
21+
import { LoadNotes } from '../../notes/load-note';
22+
import { JournalController, Input } from '../../../shared/model/index';
23+
import { NoteInput, SelectedInput, ScopedTemplate } from '../../../shared/model/index';
24+
import { isRemoteSession, toLocalFileUri } from '../../../shared/paths';
2625

2726

2827
export class AbstractLoadEntryForDateCommand implements vscode.Disposable {
@@ -131,17 +130,8 @@ export class AbstractLoadEntryForDateCommand implements vscode.Disposable {
131130
return this.ctrl.reader.loadEntryForInput(input)
132131
.then((doc: vscode.TextDocument) => this.ctrl.inject.injectInput(doc, input))
133132
.then((doc: vscode.TextDocument) => {
134-
// Fire-and-forget weekly sync — must never reject loadPageForInput.
135-
getWeekFromURIAndConfig(doc.uri, this.ctrl.config)
136-
.then(weekInfo => {
137-
if (weekInfo && this.ctrl.config.getWeeklySyncConfig().enabled) {
138-
const scopeId = weekInfo.scope === 'default' ? undefined : weekInfo.scope;
139-
new SyncDailyLinks(this.ctrl)
140-
.sync(doc, weekInfo.week, weekInfo.year, scopeId)
141-
.catch(err => this.ctrl.logger.error("loadPageForInput: weekly sync failed:", err));
142-
}
143-
})
144-
.catch(err => this.ctrl.logger.error("loadPageForInput: getWeekFromURIAndConfig failed:", err));
133+
// Notify other features (e.g. weekly daily-link sync) without importing them.
134+
this.ctrl.events.fireEntryOpened({ doc });
145135
return doc;
146136
});
147137
}

src/commands/show-entry-for-input.ts renamed to src/features/entries/commands/show-entry-for-input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'use strict';
1919

2020
import * as vscode from 'vscode';
21-
import { JournalController, Input } from '../model';
21+
import { JournalController, Input } from '../../../shared/model/index';
2222
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';
2323

2424

src/commands/show-entry-for-today.ts renamed to src/features/entries/commands/show-entry-for-today.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'use strict';
1919

2020
import * as vscode from 'vscode';
21-
import { JournalController, Input } from '../model';
21+
import { JournalController, Input } from '../../../shared/model/index';
2222
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';
2323

2424

src/commands/show-entry-for-tomorrow.ts renamed to src/features/entries/commands/show-entry-for-tomorrow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'use strict';
1919

2020
import * as vscode from 'vscode';
21-
import { JournalController, Input } from '../model';
21+
import { JournalController, Input } from '../../../shared/model/index';
2222
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';
2323

2424

src/commands/show-entry-for-yesterday.ts renamed to src/features/entries/commands/show-entry-for-yesterday.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'use strict';
1919

2020
import * as vscode from 'vscode';
21-
import { JournalController, Input } from '../model';
21+
import { JournalController, Input } from '../../../shared/model/index';
2222
import { AbstractLoadEntryForDateCommand } from './show-entry-for-date';
2323

2424

0 commit comments

Comments
 (0)