p-doom/crowd-code-dataset-0.2 huggingface dataset:
[tab] src/extension/completions-core/vscode-node/lib/src/prompt/components/completionsContext.tsx (typescriptreact)
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
//** @jsxRuntime automatic */
/** @jsxImportSource ../../../../prompt/jsx-runtime/ */

import { PromptElementProps, PromptSnapshotNode } from '../../../../prompt/src/components/components';

/**
 * A component that marks the context part of the prompt
 */
export function CompletionsContext(props: PromptElementProps) {
	return props.children;
}

/**
 * A component that marks the context part of the prompt that is stable across requests,
 * and should be located earlier in the prompt to maximize cache hits.
 */
export function StableCompletionsContext(props: PromptElementProps) {
	return props.children;
}

/**
 * A component that marks the context part of the prompt that is subject to change quickly across requests,
 * and should be located further down in the prompt.
 */
export function AdditionalCompletionsContext(props: PromptElementProps) {
	return props.children;
}

export function isContextNode(node: PromptSnapshotNode): boolean {
	return (
		node.name === CompletionsContext.name ||
		node.name === StableCompletionsContext.name ||
		node.name === AdditionalCompletionsContext.name
	);
}
[tab] src/extension/completions-core/vscode-node/lib/src/prompt/components/marker.tsx (typescriptreact)
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
/** @jsxRuntime automatic */
/** @jsxImportSource ../../../../prompt/jsx-runtime/ */

import { ComponentContext, PromptElementProps, Text } from '../../../../prompt/src/components/components';
import { getLanguageMarker, getPathMarker } from '../../../../prompt/src/languageMarker';
import { DocumentInfo } from '../../../../prompt/src/prompt';
import { ICompletionsContextService } from '../../context';
import { TextDocumentManager } from '../../textDocumentManager';
import {
	CompletionRequestDocument,
	isCompletionRequestData,
} from '../completionsPromptFactory/componentsCompletionsPromptFactory';

type DocumentMarkerProps = {
	ctx: ICompletionsContextService;
} & PromptElementProps;

export const DocumentMarker = (props: DocumentMarkerProps, context: ComponentContext) => {
	const [document, setDocument] = context.useState<CompletionRequestDocument>();

	context.useData(isCompletionRequestData, request => {
		if (request.document.uri !== document?.uri) {
			setDocument(request.document);
		}
	});

	if (document) {
		const tdm = props.ctx.get(TextDocumentManager);
		const relativePath = tdm.getRelativePath(document);
		const docInfo: DocumentInfo = {
			uri: document.uri,
			source: document.getText(),
			relativePath,
			languageId: document.detectedLanguageId,
		};
		const notebook = tdm.findNotebook(document);
		if (docInfo.relativePath && !notebook) {
			return <PathMarker docInfo={docInfo} />;
		}
		return <LanguageMarker docInfo={docInfo} />;
	}
};

const PathMarker = (props: { docInfo: DocumentInfo }) => {
	return <Text>{getPathMarker(props.docInfo)}</Text>;
};

const LanguageMarker = (props: { docInfo: DocumentInfo }) => {
	return <Text>{getLanguageMarker(props.docInfo)}</Text>;
};
[tab] src/extension/completions-core/vscode-node/lib/src/prompt/components/traits.tsx (typescriptreact)
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
/** @jsxRuntime automatic */
/** @jsxImportSource ../../../../prompt/jsx-runtime/ */

import { ComponentContext, PromptElementProps, Text } from '../../../../prompt/src/components/components';
import { normalizeLanguageId } from '../../../../prompt/src/prompt';
import {
	CompletionRequestData,
	isCompletionRequestData,
} from '../completionsPromptFactory/componentsCompletionsPromptFactory';
import { TraitWithId } from '../contextProviders/contextItemSchemas';

export const Traits = (_props: PromptElementProps, context: ComponentContext) => {
	const [traits, setTraits] = context.useState<TraitWithId[]>();
	const [languageId, setLanguageId] = context.useState<string>();

	context.useData(isCompletionRequestData, (data: CompletionRequestData) => {
		if (data.traits !== traits) {
			setTraits(data.traits);
		}

		const normalizedLanguageId = normalizeLanguageId(data.document.detectedLanguageId);
		if (normalizedLanguageId !== languageId) {
			setLanguageId(normalizedLanguageId);
		}
	});

	if (!traits || traits.length === 0 || !languageId) {
		return;
	}

	// TODO: use a `KeepTogether` elision that removes the header if no traits are present
	return (
		<>
			<Text>{'Consider this related information:
'}</Text>
			{...traits.map(trait => (
				<Text key={trait.id} source={trait}>
					{`${trait.name}: ${trait.value}`}
				</Text>
			))}
		</>
	);
};