formatScratch

tcmts.studio.formatScratch · #bg6ocbii · term · runs on the server

uses tcmts.studio.editableCodebase, which uses tcmts.share.servedCodebase, which uses process

A scratch file's code (text) formatted as tcm formats what it saves (oxfmt, as the language server formats a file as it's saved); as it was, if it doesn't parse or isn't code.

import { formatText } from "#codebase/tcmts/cli/fmt";
import { editableCodebase, scratchPath } from "#codebase/tcmts/studio";

export async function formatScratch(file: string, text: string): Promise<string> {
  const cb = editableCodebase();
  const abs = scratchPath(cb, file, text);
  if (!/\.tsx?$/.test(file)) return text;
  try {
    return formatText(cb, text, abs) ?? text;
  } catch {
    return text;
  }
}

uses

used by