Skip to content

refactor(vscode): extract TemplateService from Configuration (R1) #198 - #223

Merged
pajoma merged 16 commits into
developfrom
feat/198-extract-template-service
May 18, 2026
Merged

refactor(vscode): extract TemplateService from Configuration (R1) #198#223
pajoma merged 16 commits into
developfrom
feat/198-extract-template-service

Conversation

@pajoma

@pajoma pajoma commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extracts all template-resolution methods from src/vscode/conf.ts into a new TemplateService class (src/vscode/template-service.ts)
  • Adds IRawConfigProvider interface so TemplateService has zero vscode imports and no circular dependency on conf.ts
  • Configuration delegates all resolution methods to an internal TemplateService instance — IConfiguration and all callers unchanged

Changes

New file: src/vscode/template-service.ts

  • Exports IRawConfigProvider (14-method interface, no VS Code types)
  • Exports TemplateService (all moved resolution logic)

Modified: src/vscode/conf.ts

  • Configuration now implements IRawConfigProvider
  • 5 new raw pattern getters (getEntryFilePatternRaw, getNotesFilePatternRaw, getWeeklyNotesFilePatternRaw, getWeekFilePatternRaw, getWeekOrEntryPathPatternRaw)
  • getTplTime() added to satisfy interface
  • Private getInlineTemplate renamed → public loadInlineTemplate
  • All 19 resolution methods replaced with one-line return this.tpl.xxx(...) wrappers
  • conf.ts: 945 → 709 lines (−236 net; −326 gross resolution logic)

Test Plan

  • grep vscode src/vscode/template-service.ts → zero results
  • grep "from.*conf" src/vscode/template-service.ts → zero results
  • git diff develop -- src/model/interfaces.ts → empty
  • npm run compile → clean
  • npm test → 159/159 passing

Closes #198
Related spec: docs/specs/2026-05-18-198-extract-template-service.md
Related plan: docs/plans/2026-05-18-198-extract-template-service.md

🤖 Generated with Claude Code

pajoma and others added 14 commits May 18, 2026 11:32
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ctor (#199)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…uture fields

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ar dep

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add getEntryFilePatternRaw, getNotesFilePatternRaw,
getWeeklyNotesFilePatternRaw, getWeekFilePatternRaw,
getWeekOrEntryPathPatternRaw so TemplateService can read pattern
strings without touching vscode.WorkspaceConfiguration directly.

Rename private getInlineTemplate → public loadInlineTemplate to
satisfy the IRawConfigProvider interface that TemplateService will
depend on.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
)

Add src/vscode/template-service.ts exporting:
- IRawConfigProvider: narrow interface Configuration implements
- TemplateService: holds all resolution logic, zero vscode imports

Configuration now implements IRawConfigProvider and holds a private
TemplateService instance (tpl). getTplTime() added to satisfy the
interface. Template-service.ts never imports conf.ts — no circular dep.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
)

All template-resolution methods now delegate to this.tpl (TemplateService).
conf.ts contains zero resolution logic — only raw config accessors and
one-line wrappers. Remove unused replaceVariableValue / resolveDate
imports and dead getInlineTemplateCached + patterns Map.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pajoma

pajoma commented May 18, 2026

Copy link
Copy Markdown
Owner Author

Brooks-Lint Review

Mode: PR Review
Scope: src/vscode/conf.ts, src/vscode/template-service.ts, AGENTS.md
Health Score: 100/100

This is an exemplary "Extract Class" refactor. It strictly adheres to the approved implementation plan, successfully decoupling complex template resolution logic from VS Code integration while maintaining full backward compatibility.


Findings

🟢 Suggestion

Accidental Complexity — Minor Interface Inconsistency
Symptom: Most pattern resolution logic (e.g., getEntryFilePattern) was split into a "Raw" getter in conf.ts and a resolution method in TemplateService, but getWeeklyNotesPathPattern retains its logic directly in conf.ts and is exposed as-is on the interface.
Source: Martin — Clean Architecture (Conceptual Integrity)
Consequence: This minor inconsistency in how patterns are resolved across different types (entries vs. weekly notes) slightly increases the mental mapping required for future extensions.
Remedy: In a follow-up Phase (R2), consider standardizing all get...Pattern methods to follow the same "Raw Getter" delegation pattern used for entries and notes.


Summary

The PR achieves a significant architectural win by isolating the template resolution engine into a leaf module (template-service.ts) with zero dependencies on the VS Code API. The use of the IRawConfigProvider interface effectively breaks a potential circular dependency and enables independent unit testing of the resolution logic (addressing #202). The reduction of ~330 lines from the "God Class" conf.ts significantly lowers the cognitive load for the configuration subsystem.

Verdict: Approved.

pajoma and others added 2 commits May 18, 2026 23:50
Align with getWeeksPathPatternRaw naming convention. Method is not on
IConfiguration so rename is safe. Only 3 call sites (declaration,
IRawConfigProvider, TemplateService.getResolvedWeeklyNotesPath).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pajoma
pajoma merged commit ddd740a into develop May 18, 2026
2 checks passed
@pajoma
pajoma deleted the feat/198-extract-template-service branch May 18, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Extract Template Resolution from conf.ts (R1)

1 participant