1
>
/*---------------------------------------------------------------------------------------------
agentHostRenameCommand.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { CancellationToken } from '../../../base/common/cancellation.js';
7
>
import { localize } from '../../../nls.js';
8
>
import type { URI } from '../common/state/protocol/common/state.js';
9
>
import { CompletionItem, CompletionItemKind, CompletionsParams } from '../common/state/protocol/commands.js';
10
>
import { MessageAttachmentKind } from '../common/state/protocol/state.js';
11
>
import { toCommandCompletionAttachmentMeta } from '../common/meta/agentCompletionAttachmentMeta.js';
12
>
import { CompletionTriggerCharacter, IAgentHostCompletionItemProvider } from './agentHostCompletions.js';
13
>
import { extractLeadingSlashToken, matchesSlashCompletion } from './agentHostSlashCompletion.js';
14
>
15
>
/** The generic, agent-agnostic `/rename` slash command name. */
16
>
export const RENAME_SLASH_COMMAND = 'rename';
17
>
18
>
/**
19
>
* Parses a leading `/rename [title]` command at the very start of `prompt`.
20
>
*
21
>
* Mirrors `parseLeadingSlashCommand` (the Copilot CLI slash parser): the
22
>
* command must be `/rename`, followed either by end-of-input or at least one
23
>
* whitespace character. `/renamed`, `/rename-foo`, or a leading-space
24
>
* `/rename` all return `undefined`. Match is case-sensitive.
25
>
*
26
>
* Returns the trimmed new title (possibly an empty string when no title is
27
>
* supplied) when the prompt is a rename command, or `undefined` when it is not.
28
>
* Callers MUST distinguish "not a rename command" (`undefined`) from "rename
29
>
* with empty title" (`''`).
30
>
*/
31
>
export function parseRenameCommand(prompt: string): string | undefined {
32
const match = /^\/rename(?:$|\s+([\s\S]*))/.exec(prompt);
33
if (!match) {