blob: e723a947a6a5863b7f83a606be32da8ad0b1b1e6 [file] [log] [blame]
import {
CancellationToken,
ProviderResult,
workspace,
Uri,
TextDocumentContentProvider,
} from "vscode";
import { PendingSnapshotsProvider } from "./PendingSnapshotsProvider";
export class InlineSnapshotProvider implements TextDocumentContentProvider {
constructor(private pendingSnapshotsProvider: PendingSnapshotsProvider) {}
provideTextDocumentContent(
uri: Uri,
token: CancellationToken
): ProviderResult<string> {
const snapshot = this.pendingSnapshotsProvider.getInlineSnapshot(uri);
if (!snapshot) {
throw new Error("Snapshot not found");
}
const inlineInfo = snapshot.inlineInfo!;
const contents =
inlineInfo[uri.path == "inline.snap" ? "oldSnapshot" : "newSnapshot"];
return `---\nsource: ${workspace.asRelativePath(snapshot.resourceUri!)}:${
inlineInfo.line
}\nexpression: ${JSON.stringify(inlineInfo.expression)}\nname: ${
inlineInfo.name || "unknown"
}\n---\n${contents}`;
}
}