p-doom/crowd-code-dataset-0.2 huggingface dataset:
[tab] src/extension/completions-core/vscode-node/prompt/src/components/virtualPrompt.ts (typescript)
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import type { PromptElement, PromptSnapshotNode, Status } from './components';
import { VirtualPromptNode, VirtualPromptReconciler } from './reconciler';
import { CancellationToken } from 'vscode-languageserver-protocol';

type PromptSnapshot = Status & { snapshot: PromptSnapshotNode | undefined };

/**
 * The `VirtualPrompt` class holds the in-memory representation of the prompt, and is responsible for updating it with context, and generating immutable snapshots which can be passed to a prompt renderer.
 */
export class VirtualPrompt {
	private reconciler: VirtualPromptReconciler;

	constructor(prompt: PromptElement) {
		this.reconciler = new VirtualPromptReconciler(prompt);
	}

	private snapshotNode(
		node: VirtualPromptNode,
		cancellationToken?: CancellationToken
	): PromptSnapshotNode | 'cancelled' | undefined {
		if (!node) {
			return;
		}

		if (cancellationToken?.isCancellationRequested) {
			return 'cancelled';
		}

		const children = [];
		for (const child of node.children ?? []) {
			const result = this.snapshotNode(child, cancellationToken);
			if (result === 'cancelled') {
				return 'cancelled';
			}
			if (result !== undefined) {
				children.push(result);
			}
		}

		return {
			value: node.props?.value?.toString(),
			name: node.name,
			path: node.path,
			props: node.props,
			children,
			statistics: {
				updateDataTimeMs: node.lifecycle?.lifecycleData.getUpdateTimeMsAndReset(),
			},
		};
	}

	snapshot(cancellationToken?: CancellationToken): PromptSnapshot {
		try {
			const vTree = this.reconciler.reconcile(cancellationToken);

			if (cancellationToken?.isCancellationRequested) {
				return { snapshot: undefined, status: 'cancelled' };
			}

			if (!vTree) {
				throw new Error('Invalid virtual prompt tree');
			}

			const snapshotNode = this.snapshotNode(vTree, cancellationToken);

			if (snapshotNode === 'cancelled' || cancellationToken?.isCancellationRequested) {
				return { snapshot: undefined, status: 'cancelled' };
			}

			return { snapshot: snapshotNode, status: 'ok' };
		} catch (e) {
			return { snapshot: undefined, status: 'error', error: e as Error };
		}
	}

	createPipe(): DataPipe {
		return this.reconciler.createPipe();
	}
}
/**
 * A data pipe is a one-way channel to get external data into the prompt. Pumping unsupported data types into the pipe will result in no-op.
 */
export interface DataPipe {
	pump(data: unknown): Promise<void>;
}
[tab] src/extension/completions-core/vscode-node/lib/src/test/completionsPrompt.ts (typescript)
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { CancellationTokenSource, Position } from 'vscode-languageserver-protocol';
import { ServicesAccessor } from '../../../../../../util/vs/platform/instantiation/common/instantiation';
import {
	CompletionRequestData,
	CompletionRequestDocument,
} from '../prompt/completionsPromptFactory/componentsCompletionsPromptFactory';
import { CodeSnippetWithId, TraitWithId } from '../prompt/contextProviders/contextItemSchemas';
import { TelemetryWithExp } from '../telemetry';

export function createCompletionRequestData(
	accessor: ServicesAccessor,
	doc: CompletionRequestDocument,
	position: Position,
	codeSnippets?: CodeSnippetWithId[],
	traits?: TraitWithId[],
	turnOffSimilarFiles?: boolean,
	suffixMatchThreshold?: number,
	maxPromptLength?: number
): CompletionRequestData {
	return {
		document: doc,
		position,
		telemetryData: TelemetryWithExp.createEmptyConfigForTesting(),
		cancellationToken: new CancellationTokenSource().token,
		codeSnippets,
		traits,
		turnOffSimilarFiles,
		suffixMatchThreshold,
		maxPromptTokens: maxPromptLength ?? 1000,
	};
}
[tab] src/extension/completions-core/vscode-node/prompt/src/test/components/jsx-runtime.test.ts.off (plaintext)
import {Fragment, jsx} from '#jsx/jsx-runtime';
import {ComponentContext} from '#prompt/components/components';
import * as assert from 'assert';

suite('JSX/TSX', function () {
    test('Produces element from functional component', function () {
        const fn = (props: unknown, context: ComponentContext) => [];
        const element = jsx(fn, {children: ['Hello world']});

        assert.deepStrictEqual(element.type, fn);
        assert.deepStrictEqual(element.props, {
            children: ['Hello world'],
        });
    });

    test('Produces element from functional component with key', function () {
        const fn = (props: unknown, context: ComponentContext) => [];
        const element = jsx(fn, {children: ['Hello world']}, 'key');

        assert.deepStrictEqual(element.type, fn);
        assert.deepStrictEqual(element.props, {
            children: ['Hello world'],
            key: 'key',
        });
    });

    test('Produces fragment function', function () {
        const element = Fragment(['Hello world']);

        assert.deepStrictEqual(element.type, 'f');
        assert.deepStrictEqual(element.children, ['Hello world']);
    });
});