analyzedScratch

tcmts.studio.analyzedScratch · #uoiwsmd3 · term · runs anywhere

The scratch file abs analyzed as it holds text (in this process, as the language server analyzes it), or as it was last if nothing's changed since: the text, or the codebase.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import type { Analysis } from "#codebase/tcmts/core/analyze";
import { scratchAnalyses } from "#codebase/tcmts/studio";

export function analyzedScratch(cb: Codebase, abs: string, text: string): Analysis {
  const key = `${cb.store.head()}\0${text}`;
  const kept = scratchAnalyses.get(abs);
  if (kept?.key === key) return kept.a;
  cb.refreshShim();
  const a = cb.analyze(abs, cb.scratchSalts(), [], new Map([[abs, text]]));
  scratchAnalyses.set(abs, { key, a });
  return a;
}

uses

used by