Skip to content

refactor: UnresolvedWikilink に displayPath field を追加 (#253)#254

Merged
ymnao merged 1 commit into
mainfrom
refactor/unresolved-wikilink-display-path-#253
Jun 28, 2026
Merged

refactor: UnresolvedWikilink に displayPath field を追加 (#253)#254
ymnao merged 1 commit into
mainfrom
refactor/unresolved-wikilink-display-path-#253

Conversation

@ymnao

@ymnao ymnao commented Jun 28, 2026

Copy link
Copy Markdown
Owner

概要

PR #252 (BacklinkSource に displayName / displayPath 追加) の波及。UnresolvedWikilink.references の各要素に displayPath field を追加し、UnresolvedLinksPanel.tsx の毎-render toRelativePath 計算を scan-time に hoist。

合わせて /simplify Reuse 角度の採用として、e2e mock の wsPrefix + slice 計算 (本 PR の scanUnresolvedWikilinks 側 + 既存 scanBacklinks 側) を mockDisplayPath helper に集約 (2 箇所重複解消)。

関連 Issue

closes #253

移行 Stage

本 PR は migration plan の Stage とは独立 (Stage 6 完了後の継続改善)。

変更内容

  • src/types/wikilink.ts: UnresolvedWikilinkReference extends WikilinkReference { displayPath: string } を追加、UnresolvedWikilink.references の型を更新
  • electron/main/ipc/search.ts: scanUnresolvedWikilinksImpl で file 単位 hoist で displayPath = toDisplayPath(workspacePath, inFiles[idx]) を 1 度算出し、callback push 時に { ...ref, displayPath }UnresolvedWikilinkReference を構築。map 型を Map<string, UnresolvedWikilinkReference[]> に更新
  • src/components/search/UnresolvedLinksPanel.tsx: toRelativePath import 削除、per-render relativePath 計算削除、reference.displayPath を直接読み (return → 直接 JSX 構文に変換)
  • e2e/helpers/electron-api-mock.ts: installApiMock 内 helper として mockDisplayPath(workspacePath, absolutePath) を追加 (本番 toDisplayPath と同等を / 区切り前提で再現)。scanUnresolvedWikilinks / scanBacklinks の inline wsPrefix + startsWith / slice 計算 2 箇所を helper 呼び出しに統一
  • src/stores/wikilink.test.ts: mockLinks の reference に displayPath: "note.md" を追加 (1 site)

設計判断: Option B (UnresolvedWikilinkReference 専用型)

検討した Option A (WikilinkReference 自体に displayPath を common 追加) と Option B (本採用: UnresolvedWikilinkReference extends WikilinkReference { displayPath: string } 新型) の比較:

  • Option A: BacklinkSource.references[i].displayPath が source.displayPath と redundant (常に sourceFile == reference.filePath なので)
  • Option B 採用根拠: BacklinkSource は変更不要 / scope 最小 / redundancy なし

/code-review low

(none) — production hunk 3 file (wikilink.ts 型追加 / search.ts の file 単位 hoist + spread copy / UnresolvedLinksPanel.tsx の per-render 計算削除) に runtime correctness bug / duplicate / dead code 該当なし。

/simplify pass 1

動作確認

  • pnpm test (unit): 2230 pass / 2 skipped ✅
  • tsc --noEmit -p tsconfig.web.json: clean ✅
  • tsc --noEmit -p tsconfig.node.json: clean ✅
  • tsc --noEmit -p tsconfig.e2e.json: clean ✅
  • biome check: 変更 5 file clean ✅ (既存の recommended deprecated info / version mismatch info は本 PR と無関係)
  • 実 Electron e2e: CI で確認

スクリーンショット

UI の見た目は変わらない (per-render toRelativePath() の結果 = reference.displayPath で表示文字列同等)。再 render 時の string allocation だけが削減される。

- IPC 境界 type に UnresolvedWikilinkReference extends WikilinkReference { displayPath: string } を追加
- scanUnresolvedWikilinksImpl で file 単位 hoist で displayPath を 1 度だけ算出 (PR #252 BacklinkSource と同 pattern)
- UnresolvedLinksPanel の per-render toRelativePath 計算を削除し reference.displayPath を直接読み
- e2e mock の displayPath 計算 (scanUnresolvedWikilinks / scanBacklinks の 2 箇所) を mockDisplayPath helper に集約 (/simplify Reuse 採用)
- test mock 1 site に displayPath 追加

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ymnao ymnao merged commit 7119d27 into main Jun 28, 2026
9 checks passed
@ymnao ymnao deleted the refactor/unresolved-wikilink-display-path-#253 branch June 28, 2026 00:42
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: UnresolvedWikilink.references に displayPath field を追加し UnresolvedLinksPanel の毎-render 計算を削減

1 participant