MCPcopy Create free account
hub / github.com/modem-dev/hunk / ensureHighlightedDiffLoaded

Function ensureHighlightedDiffLoaded

src/ui/diff/useHighlightedDiff.ts:104–136  ·  view source on GitHub ↗

Start one shared highlight request unless the cache or an in-flight promise already has it.

(
  file: DiffFile,
  theme: AppTheme,
  cacheKey = buildCacheKey(theme, file),
)

Source from the content-addressed store, hash-verified

102
103/** Start one shared highlight request unless the cache or an in-flight promise already has it. */
104function ensureHighlightedDiffLoaded(
105 file: DiffFile,
106 theme: AppTheme,
107 cacheKey = buildCacheKey(theme, file),
108) {
109 const cached = SHARED_HIGHLIGHTED_DIFF_CACHE.get(cacheKey);
110 if (cached) {
111 return Promise.resolve(cached);
112 }
113
114 const existing = SHARED_HIGHLIGHT_PROMISES.get(cacheKey);
115 if (existing) {
116 return existing;
117 }
118
119 let pending: Promise<HighlightedDiffCode>;
120 pending = loadHighlightedDiff(file, theme)
121 .then((nextHighlighted) => {
122 commitHighlightResult(cacheKey, pending, nextHighlighted);
123 return nextHighlighted;
124 })
125 .catch(() => {
126 const fallback = {
127 deletionLines: [],
128 additionLines: [],
129 } satisfies HighlightedDiffCode;
130 commitHighlightResult(cacheKey, pending, fallback);
131 return fallback;
132 });
133
134 SHARED_HIGHLIGHT_PROMISES.set(cacheKey, pending);
135 return pending;
136}
137
138/** Queue syntax highlighting for one file without mounting its diff rows first. */
139export function prefetchHighlightedDiff({ file, theme }: { file: DiffFile; theme: AppTheme }) {

Callers 2

prefetchHighlightedDiffFunction · 0.85
useHighlightedDiffFunction · 0.85

Calls 3

loadHighlightedDiffFunction · 0.90
buildCacheKeyFunction · 0.85
commitHighlightResultFunction · 0.85

Tested by

no test coverage detected