agentHostFileCompletionProvider.ts ×7

Frontier kind: Code frontier

unlabeled · c_f7e6451b82b2

503 tests · 20183 LOC · 93 files · introduces 0 tests · 76 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
7 ranges76 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1872 ranges20183 lines · 93 files · Browse complete extent
All tests (intent)
503 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 76 introduced LOC across 7 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/agentHostFileCompletionProvider.ts 76 introduced LOC · 7 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- agentHostFileCompletionProvider.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 { 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;
61 return undefined;
62 }
64 > /**
65 > * Item-accessor that exposes a {@link URI} as basename / parent-directory /
66 > * relative path for the {@link scoreItemFuzzy} family.
67 > */
68 > class UriAccessor implements IItemAccessor<URI> {
69 > constructor(private readonly _workingDirectory: URI) { }
70 >
71 > getItemLabel(item: URI): string {
72 return basename(item);
73 }
75 > getItemDescription(item: URI): string | undefined {
76 const rel = relativePath(this._workingDirectory, item);
77 if (!rel) {
81 return idx > 0 ? rel.slice(0, idx) : undefined;
82 }
84 > getItemPath(item: URI): string | undefined {
85 const rel = relativePath(this._workingDirectory, item);
86 return rel ?? item.fsPath;
87 }
89 >
90 > /**
91 > * Generic completion provider that contributes workspace file references
92 > * for a {@link CompletionItemKind.UserMessage} input — typically used for
93 > * `@`-mentions in the user message composer.
94 > *
95 > * When the user has typed an `@`-prefixed token at the cursor position,
96 > * this provider enumerates files under the session's working directory
97 > * (via {@link AgentHostWorkspaceFiles}, which uses ripgrep and respects
98 > * `.gitignore`), ranks them with the same fuzzy scorer used by the
99 > * VS Code Quick Open file picker, and returns up to {@link MAX_RESULTS}
100 > * matches.
101 > */
102 > export class AgentHostFileCompletionProvider implements IAgentHostCompletionItemProvider {
103 >
104 > readonly kinds: ReadonlySet<CompletionItemKind> = new Set([CompletionItemKind.UserMessage]);
105 >
106 > readonly triggerCharacters: readonly string[] = [CompletionTriggerCharacter.File, CompletionTriggerCharacter.Hash];
107 >
108 > constructor(
109 private readonly _stateManager: AgentHostStateManager,
110 private readonly _workspaceFiles: AgentHostWorkspaceFiles,
111 ) { }
113 > async provideCompletionItems(params: CompletionsParams, token: CancellationToken): Promise<readonly CompletionItem[]> {
114 const workingDirectoryStr = this._stateManager.getSessionState(params.channel)?.workingDirectories?.[0];
115 if (!workingDirectoryStr) {