Skip to content

Commit

Permalink
[prompt snippets]: minor types naming cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
legomushroom authored Nov 28, 2024
1 parent b5b7ae0 commit e75e673
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import { VSBuffer } from '../../../../../../base/common/buffer.js';
import { Disposable } from '../../../../../../base/common/lifecycle.js';
import { ReadableStream } from '../../../../../../base/common/stream.js';
import { ICodec } from '../../../../../../base/common/codecs/types/ICodec.js';
import { ChatbotPromptDecoder, TChatbotPromptToken } from './chatPromptDecoder.js';
import { ChatPromptDecoder, TChatPromptToken } from './chatPromptDecoder.js';

/**
* Codec that is capable to encode and decode syntax tokens of a AI chat bot prompt message.
* Codec that is capable to encode and decode syntax tokens of a AI chatbot prompt message.
*/
export class ChatbotPromptCodec extends Disposable implements ICodec<VSBuffer, TChatbotPromptToken> {
public encode(_: ReadableStream<TChatbotPromptToken>): ReadableStream<VSBuffer> {
export class ChatPromptCodec extends Disposable implements ICodec<VSBuffer, TChatPromptToken> {
public encode(_: ReadableStream<TChatPromptToken>): ReadableStream<VSBuffer> {
throw new Error('The `encode` method is not implemented.');
}

public decode(stream: ReadableStream<VSBuffer>): ChatbotPromptDecoder {
return this._register(new ChatbotPromptDecoder(stream));
public decode(stream: ReadableStream<VSBuffer>): ChatPromptDecoder {
return this._register(new ChatPromptDecoder(stream));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { Word } from '../../../../../../editor/common/codecs/simpleCodec/tokens/
import { SimpleDecoder, TSimpleToken } from '../../../../../../editor/common/codecs/simpleCodec/simpleDecoder.js';

/**
* Tokens handled by the `ChatbotPromptDecoder` decoder.
* Tokens handled by the `ChatPromptDecoder` decoder.
*/
export type TChatbotPromptToken = FileReference;
export type TChatPromptToken = FileReference;

/**
* Decoder for the common chatbot prompt message syntax.
* For instance, the file references `#file:./path/file.md` are handled by this decoder.
*/
export class ChatbotPromptDecoder extends BaseDecoder<TChatbotPromptToken, TSimpleToken> {
export class ChatPromptDecoder extends BaseDecoder<TChatPromptToken, TSimpleToken> {
constructor(
stream: ReadableStream<VSBuffer>,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/chat/common/promptFileReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Emitter } from '../../../../base/common/event.js';
import { extUri } from '../../../../base/common/resources.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { Location } from '../../../../editor/common/languages.js';
import { ChatbotPromptCodec } from './codecs/chatPromptCodec/chatPromptCodec.js';
import { ChatPromptCodec } from './codecs/chatPromptCodec/chatPromptCodec.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
import { FileOpenFailed, NonPromptSnippetFile, RecursiveReference } from './promptFileReferenceErrors.js';
import { FileChangesEvent, FileChangeType, IFileService, IFileStreamContent } from '../../../../platform/files/common/files.js';
Expand Down Expand Up @@ -75,7 +75,7 @@ export class PromptFileReference extends Disposable {
/**
* Chatbot prompt message codec helps to parse out prompt syntax.
*/
private readonly codec = this._register(new ChatbotPromptCodec());
private readonly codec = this._register(new ChatPromptCodec());

/**
* Child references of the current one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import { Range } from '../../../../../../editor/common/core/range.js';
import { newWriteableStream } from '../../../../../../base/common/stream.js';
import { TestDecoder } from '../../../../../../editor/test/common/utils/testDecoder.js';
import { FileReference } from '../../../common/codecs/chatPromptCodec/tokens/fileReference.js';
import { ChatbotPromptCodec } from '../../../common/codecs/chatPromptCodec/chatPromptCodec.js';
import { ChatPromptCodec } from '../../../common/codecs/chatPromptCodec/chatPromptCodec.js';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../base/test/common/utils.js';
import { ChatbotPromptDecoder, TChatbotPromptToken } from '../../../common/codecs/chatPromptCodec/chatPromptDecoder.js';
import { ChatPromptDecoder, TChatPromptToken } from '../../../common/codecs/chatPromptCodec/chatPromptDecoder.js';

/**
* A reusable test utility that asserts that a `ChatbotPromptDecoder` instance
* correctly decodes `inputData` into a stream of `TChatbotPromptToken` tokens.
* A reusable test utility that asserts that a `ChatPromptDecoder` instance
* correctly decodes `inputData` into a stream of `TChatPromptToken` tokens.
*
* ## Examples
*
* ```typescript
* // create a new test utility instance
* const test = testDisposables.add(new TestChatbotPromptCodec());
* const test = testDisposables.add(new TestChatPromptCodec());
*
* // run the test
* await test.run(
Expand All @@ -33,10 +33,10 @@ import { ChatbotPromptDecoder, TChatbotPromptToken } from '../../../common/codec
* ]
* );
*/
export class TestChatbotPromptCodec extends TestDecoder<TChatbotPromptToken, ChatbotPromptDecoder> {
export class TestChatPromptCodec extends TestDecoder<TChatPromptToken, ChatPromptDecoder> {
constructor() {
const stream = newWriteableStream<VSBuffer>(null);
const codec = new ChatbotPromptCodec();
const codec = new ChatPromptCodec();
const decoder = codec.decode(stream);

super(stream, decoder);
Expand All @@ -45,11 +45,11 @@ export class TestChatbotPromptCodec extends TestDecoder<TChatbotPromptToken, Cha
}
}

suite('ChatbotPromptCodec', () => {
suite('ChatPromptCodec', () => {
const testDisposables = ensureNoDisposablesAreLeakedInTestSuite();

test('produces expected tokens', async () => {
const test = testDisposables.add(new TestChatbotPromptCodec());
const test = testDisposables.add(new TestChatPromptCodec());

await test.run(
'#file:/etc/hosts some text\t\n for #file:./README.md\t testing\n ✔ purposes\n#file:LICENSE.md ✌ \t#file:.gitignore\n\n\n\t #file:/Users/legomushroom/repos/vscode ',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { newWriteableStream } from '../../../../../../base/common/stream.js';
import { TestDecoder } from '../../../../../../editor/test/common/utils/testDecoder.js';
import { FileReference } from '../../../common/codecs/chatPromptCodec/tokens/fileReference.js';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../base/test/common/utils.js';
import { ChatbotPromptDecoder, TChatbotPromptToken } from '../../../common/codecs/chatPromptCodec/chatPromptDecoder.js';
import { ChatPromptDecoder, TChatPromptToken } from '../../../common/codecs/chatPromptCodec/chatPromptDecoder.js';

/**
* A reusable test utility that asserts that a `ChatbotPromptDecoder` instance
* correctly decodes `inputData` into a stream of `TChatbotPromptToken` tokens.
* A reusable test utility that asserts that a `ChatPromptDecoder` instance
* correctly decodes `inputData` into a stream of `TChatPromptToken` tokens.
*
* ## Examples
*
* ```typescript
* // create a new test utility instance
* const test = testDisposables.add(new TestChatbotPromptDecoder());
* const test = testDisposables.add(new TestChatPromptDecoder());
*
* // run the test
* await test.run(
Expand All @@ -32,22 +32,22 @@ import { ChatbotPromptDecoder, TChatbotPromptToken } from '../../../common/codec
* ]
* );
*/
export class TestChatbotPromptDecoder extends TestDecoder<TChatbotPromptToken, ChatbotPromptDecoder> {
export class TestChatPromptDecoder extends TestDecoder<TChatPromptToken, ChatPromptDecoder> {
constructor(
) {
const stream = newWriteableStream<VSBuffer>(null);
const decoder = new ChatbotPromptDecoder(stream);
const decoder = new ChatPromptDecoder(stream);

super(stream, decoder);
}
}

suite('ChatbotPromptDecoder', () => {
suite('ChatPromptDecoder', () => {
const testDisposables = ensureNoDisposablesAreLeakedInTestSuite();

test('produces expected tokens', async () => {
const test = testDisposables.add(
new TestChatbotPromptDecoder(),
new TestChatPromptDecoder(),
);

await test.run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,9 @@ class TestPromptFileReference extends Disposable {
}
}

suite('ChatbotPromptReference (Unix)', function () {
suite('PromptFileReference (Unix)', function () {
const testDisposables = ensureNoDisposablesAreLeakedInTestSuite();

// let parser: ChatRequestParser;

// let varService: MockObject<IChatVariablesService>;
let instantiationService: TestInstantiationService;
setup(async () => {
const nullPolicyService = new NullPolicyService();
Expand Down

0 comments on commit e75e673

Please sign in to comment.