* chore: remove verified dead declarations Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * chore: narrow unused internal exports Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * chore: remove newly exposed dead helpers Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * chore: remove unused deep-link serializer Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * test: drop two tests that assert on copies of the code mainLayoutMobileSidebarMount read MainLayout.tsx and SessionSidebar.tsx as strings and asserted on source substrings down to exact indentation, so it failed on formatting rather than behaviour. useProjectSessionSelection.test reimplemented the hook's visitNodes logic inside the test file and asserted against that copy, so it could not observe the hook at all. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * test: repair sync suites that had rotted while unrunnable No runner executed packages/ui, so these drifted from the source unnoticed: two imported helpers that are no longer exported, one directory-store stub predated the session field routeMessage reads, and the WebSocket fake missed the mandatory url-token mint plus the close event the socket wrapper reads. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * test: stop the web suite failing on timeouts and a hand-copied mock The Git suites drive a real git binary, so the 5s default made a valid suite fail differently per run. The gitApiHttp mock listed ~70 export names by hand and fell behind the source; it now derives every stub from the real module, which the added shared-UI aliases make resolvable. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * test: run every suite from one command and in CI packages/ui (232 files) and packages/vscode (22) had no test script at all, CI ran neither, and 9 vscode files could never run because Node cannot resolve their extensionless TypeScript imports. Three electron files sat outside every script list, one of them importing vitest, which that package does not depend on. A runner gives each file its own process, since these suites keep module-level singletons and fail by load order when sharing one. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * chore: delete a superseded repro harness and a completed plan The issue-2638 harness needed lsof, overrode process.platform and spawned real servers, and nothing referenced it; event-stream/rebind.test.js now covers the same hub-pinned-to-the-old-port behaviour. The pairing v2 plan described relay and the pairing UI as out of scope, both of which shipped. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * docs: point at the theme tools and record the github barrel invariant convert-vscode-theme and harmonize-theme were referenced nowhere, so the theme-authoring reference now names them. The github barrel is loaded through await import('./index.js') and destructured per route, which no static report can see; documenting that is what stops the next cleanup from deleting it. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com> * test: repair merge drift in bridge and route-registry mocks upstream/main gained upsertProviderConfig on bridge-system-runtime and a PATCH scheduled-task route after this branch forked. Their test doubles were never updated to match: - bridge-system-runtime.test.js: add upsertProviderConfig to the opencodeConfig mock so the import resolves. - sse-routes.test.js: add app.patch to the route registry stub. --------- Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
117 lines
4.2 KiB
TypeScript
117 lines
4.2 KiB
TypeScript
/**
|
|
* Which autocomplete a caret position asks for.
|
|
*
|
|
* The composer has four pickers (command, skill, snippet, file/agent mention)
|
|
* and the rule that opens each of them used to be inlined in a single 90-line
|
|
* `updateAutocompleteState` callback, duplicating the boundary logic that
|
|
* `scanPrefixTokens` and `scanMentions` already own. This module answers the
|
|
* one question the composer actually asks — "given the text and the caret,
|
|
* what should be open?" — as a pure function, so the editor layer only has to
|
|
* report the caret and render the result.
|
|
*
|
|
* Exactly one trigger can be active, and order matters: the command palette
|
|
* (a leading `/`) outranks the inline skill picker, which outranks snippets,
|
|
* which outrank mentions. That precedence is the previous behavior, preserved.
|
|
*/
|
|
|
|
import {
|
|
getFileMentionAutocompleteQuery,
|
|
type FileMentionAutocompleteInputSource,
|
|
} from '../../fileMentionAutocompleteState';
|
|
|
|
export type AutocompleteKind = 'command' | 'skill' | 'snippet' | 'mention';
|
|
|
|
export interface AutocompleteTrigger {
|
|
kind: AutocompleteKind;
|
|
/** Text typed after the sigil, used to filter the picker. */
|
|
query: string;
|
|
}
|
|
|
|
export interface TriggerContext {
|
|
/** Shell mode (`!cmd`) disables every picker. */
|
|
inputMode: 'normal' | 'shell';
|
|
/** Whether the change that moved the caret came from a paste. */
|
|
inputSource?: FileMentionAutocompleteInputSource;
|
|
/** The text that change inserted, when known. */
|
|
insertedText?: string;
|
|
}
|
|
|
|
/**
|
|
* A sigil opens a picker only at a word boundary — the start of the text or
|
|
* directly after whitespace. This mirrors `scanPrefixTokens`, but works
|
|
* backwards from the caret because the token is still being typed.
|
|
*/
|
|
const isWordBoundaryBefore = (text: string, index: number): boolean =>
|
|
index <= 0 || /\s/.test(text[index - 1]);
|
|
|
|
/**
|
|
* The command palette is reserved for a `/` in the very first column, with the
|
|
* caret still inside the command word and no argument typed yet. Once a space
|
|
* appears the message is a command invocation, not a search.
|
|
*/
|
|
function matchCommandPalette(value: string, cursorPosition: number): AutocompleteTrigger | null {
|
|
if (!value.startsWith('/')) return null;
|
|
|
|
const firstSpace = value.indexOf(' ');
|
|
if (firstSpace !== -1) return null;
|
|
|
|
const firstNewline = value.indexOf('\n');
|
|
const commandEnd = firstNewline === -1 ? value.length : firstNewline;
|
|
if (cursorPosition > commandEnd) return null;
|
|
|
|
return { kind: 'command', query: value.substring(1, commandEnd) };
|
|
}
|
|
|
|
/**
|
|
* An inline `/skill` or `#snippet` still being typed: the nearest sigil before
|
|
* the caret, at a word boundary, with no separator between it and the caret.
|
|
*/
|
|
function matchInlineToken(
|
|
value: string,
|
|
cursorPosition: number,
|
|
sigil: '/' | '#',
|
|
kind: AutocompleteKind,
|
|
): AutocompleteTrigger | null {
|
|
const textBeforeCursor = value.substring(0, cursorPosition);
|
|
const sigilIndex = textBeforeCursor.lastIndexOf(sigil);
|
|
if (sigilIndex === -1) return null;
|
|
if (!isWordBoundaryBefore(textBeforeCursor, sigilIndex)) return null;
|
|
|
|
const query = textBeforeCursor.substring(sigilIndex + 1);
|
|
if (query.includes(' ') || query.includes('\n')) return null;
|
|
|
|
return { kind, query };
|
|
}
|
|
|
|
/**
|
|
* Resolve the single autocomplete that the caret asks for, or null when none
|
|
* applies. Pure: the caller supplies the text and caret, and decides what to
|
|
* do with the answer.
|
|
*/
|
|
export function resolveAutocompleteTrigger(
|
|
value: string,
|
|
cursorPosition: number,
|
|
context: TriggerContext,
|
|
): AutocompleteTrigger | null {
|
|
if (context.inputMode === 'shell') return null;
|
|
|
|
return matchCommandPalette(value, cursorPosition)
|
|
?? matchInlineToken(value, cursorPosition, '/', 'skill')
|
|
?? matchInlineToken(value, cursorPosition, '#', 'snippet')
|
|
?? matchMention(value, cursorPosition, context);
|
|
}
|
|
|
|
function matchMention(
|
|
value: string,
|
|
cursorPosition: number,
|
|
context: TriggerContext,
|
|
): AutocompleteTrigger | null {
|
|
const query = getFileMentionAutocompleteQuery({
|
|
value,
|
|
cursorPosition,
|
|
inputSource: context.inputSource,
|
|
insertedText: context.insertedText,
|
|
});
|
|
return query === null ? null : { kind: 'mention', query };
|
|
}
|