src/vs/platform/agentHost/node/agentHostSlashCompletion.ts

86 LOC · 82 covered · 4 uncovered · 28 ranges · 1567 concepts · 17 introducers · 765 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- agentHostSlashCompletion.ts ×4
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 { matchesFuzzy2 } from '../../../base/common/filters.js';
7 >
8 > /**
9 > * A leading slash token in a user-message input.
10 > */
11 > export interface ILeadingSlashToken {
12 > /** The token including the leading slash. */
13 > readonly token: string;
14 > /** The typed token text after the slash. */
15 > readonly typed: string;
16 > /** The start offset of the token range to replace. */
17 > readonly rangeStart: number;
18 > /** The end offset of the token range to replace. */
19 > readonly rangeEnd: number;
20 > }
21 >
22 > /**
23 > * Extracts the leading `/word` token from the input, where the token is the
24 > * run of non-whitespace characters starting at offset 0. Returns `undefined`
25 > * if the input does not start with `/` or the cursor is past the token.
26 > */
27 > export function extractLeadingSlashToken(text: string, offset: number): ILeadingSlashToken | undefined {
28 > if (text.length === 0 || text.charCodeAt(0) !== 0x2f /* / */) { agentHostSlashCompletion.ts ×2
29 > return undefined; agentHostSlashCompletion.ts ×1
30 > }
32 > while (end < text.length) {
33 > if (isSlashTokenWhitespace(text.charCodeAt(end))) { agentHostSlashCompletion.ts ×2
35 > }
37 > }
38 > if (offset < 0 || offset > end) { agentHostSlashCompletion.ts ×2
39 > return undefined; agentHostSlashCompletion.ts ×1
40 > }
41 > const token = text.slice(0, end); agentHostSlashCompletion.ts ×1
42 > return { token, typed: token.slice(1), rangeStart: 0, rangeEnd: end };
43 > }
45 > /**
46 > * Extracts the slash token containing the cursor when the slash is either at
47 > * the start of the input or immediately follows whitespace.
48 > */
49 > export function extractWhitespaceDelimitedSlashToken(text: string, offset: number): ILeadingSlashToken | undefined {
50 > if (text.length === 0 || offset < 0 || offset > text.length) { agentHostSlashCompletion.ts ×4
51 return undefined;
52 }
54 > let start = offset;
55 > while (start > 0 && !isSlashTokenWhitespace(text.charCodeAt(start - 1))) {
57 > }
58 > if (start >= text.length || text.charCodeAt(start) !== 0x2f /* / */) { agentHostSlashCompletion.ts ×4
59 > return undefined; agentHostSlashCompletion.ts ×1
60 > }
62 > let end = start + 1;
63 > while (end < text.length && !isSlashTokenWhitespace(text.charCodeAt(end))) { agentHostSlashCompletion.ts ×4
65 > }
66 > if (offset > end) { agentHostSlashCompletion.ts ×3
67 return undefined;
68 }
70 > const token = text.slice(start, end);
71 > return { token, typed: token.slice(1), rangeStart: start, rangeEnd: end };
72 > }
74 > /**
75 > * Tests whether a slash completion name fuzzy matches the typed token text.
76 > */
77 > export function matchesSlashCompletion(typed: string, name: string): boolean {
78 > if (typed.length === 0 || name.toLowerCase().startsWith(typed.toLowerCase())) { agentHostSlashCompletion.ts ×2
80 > }
81 > return typed.length > 1 && matchesFuzzy2(typed, name) !== null; agentHostSlashCompletion.ts ×1
84 > function isSlashTokenWhitespace(ch: number): boolean { agentHostSlashCompletion.ts ×1
85 > return ch === 0x20 /* space */ || ch === 0x09 /* tab */ || ch === 0x0a /* \n */ || ch === 0x0d /* \r */;
86 > }