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 { isCancellationError } from '../../../base/common/errors.js';
8
>
import { compareItemsByFuzzyScore, FuzzyScorerCache, IItemAccessor, prepareQuery, scoreItemFuzzy } from '../../../base/common/fuzzyScorer.js';
9
>
import { Schemas } from '../../../base/common/network.js';
10
>
import { basename, relativePath } from '../../../base/common/resources.js';
11
>
import { URI } from '../../../base/common/uri.js';
12
>
import { CompletionItem, CompletionItemKind, CompletionsParams } from '../common/state/protocol/commands.js';
13
>
import { MessageAttachmentKind } from '../common/state/protocol/state.js';
14
>
import { CompletionTriggerCharacter, IAgentHostCompletionItemProvider } from './agentHostCompletions.js';
15
>
import { AgentHostStateManager } from './agentHostStateManager.js';
16
>
import { AgentHostWorkspaceFiles } from './agentHostWorkspaceFiles.js';
17
>
18
>
/** Maximum number of completion items returned per call. */
19
>
const MAX_RESULTS = 50;
20
>
21
>
/**
22
>
* Result of {@link extractAtToken}.
23
>
*/
24
>
interface IAtToken {
25
>
readonly token: string;
26
>
readonly triggerChar: string;
27
>
readonly rangeStart: number;
28
>
readonly rangeEnd: number;
29
>
}
30
>
31
>
/**
32
>
* Walk back from `offset` to find the most recent `@` that is preceded by
33
>
* whitespace (or start-of-string) and not interrupted by whitespace. Returns
34
>
* the substring after `@` together with the range to replace, or `undefined`
35
>
* if no `@`-token is being typed at `offset`.
36
>
*
37
>
* Exported for unit testing.
38
>
*/
39
>
export function extractAtToken(text: string, offset: number): IAtToken | undefined {
40
if (offset < 0 || offset > text.length) {
41
return undefined;