@m4ike1/ion-tui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -0
- package/dist/alt-screen-search.d.ts +46 -0
- package/dist/alt-screen-search.d.ts.map +1 -0
- package/dist/alt-screen-search.js +282 -0
- package/dist/alt-screen-search.js.map +1 -0
- package/dist/autocomplete.d.ts +75 -0
- package/dist/autocomplete.d.ts.map +1 -0
- package/dist/autocomplete.js +749 -0
- package/dist/autocomplete.js.map +1 -0
- package/dist/components/alt-screen-flash.d.ts +13 -0
- package/dist/components/alt-screen-flash.d.ts.map +1 -0
- package/dist/components/alt-screen-flash.js +37 -0
- package/dist/components/alt-screen-flash.js.map +1 -0
- package/dist/components/box.d.ts +24 -0
- package/dist/components/box.d.ts.map +1 -0
- package/dist/components/box.js +133 -0
- package/dist/components/box.js.map +1 -0
- package/dist/components/cancellable-loader.d.ts +22 -0
- package/dist/components/cancellable-loader.d.ts.map +1 -0
- package/dist/components/cancellable-loader.js +35 -0
- package/dist/components/cancellable-loader.js.map +1 -0
- package/dist/components/editor.d.ts +266 -0
- package/dist/components/editor.d.ts.map +1 -0
- package/dist/components/editor.js +2087 -0
- package/dist/components/editor.js.map +1 -0
- package/dist/components/h-stack.d.ts +7 -0
- package/dist/components/h-stack.d.ts.map +1 -0
- package/dist/components/h-stack.js +43 -0
- package/dist/components/h-stack.js.map +1 -0
- package/dist/components/image.d.ts +28 -0
- package/dist/components/image.d.ts.map +1 -0
- package/dist/components/image.js +90 -0
- package/dist/components/image.js.map +1 -0
- package/dist/components/input.d.ts +48 -0
- package/dist/components/input.d.ts.map +1 -0
- package/dist/components/input.js +417 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/loader.d.ts +33 -0
- package/dist/components/loader.d.ts.map +1 -0
- package/dist/components/loader.js +76 -0
- package/dist/components/loader.js.map +1 -0
- package/dist/components/markdown.d.ts +103 -0
- package/dist/components/markdown.d.ts.map +1 -0
- package/dist/components/markdown.js +858 -0
- package/dist/components/markdown.js.map +1 -0
- package/dist/components/mouse-region.d.ts +12 -0
- package/dist/components/mouse-region.d.ts.map +1 -0
- package/dist/components/mouse-region.js +21 -0
- package/dist/components/mouse-region.js.map +1 -0
- package/dist/components/scroll-view.d.ts +68 -0
- package/dist/components/scroll-view.d.ts.map +1 -0
- package/dist/components/scroll-view.js +199 -0
- package/dist/components/scroll-view.js.map +1 -0
- package/dist/components/select-list.d.ts +53 -0
- package/dist/components/select-list.d.ts.map +1 -0
- package/dist/components/select-list.js +206 -0
- package/dist/components/select-list.js.map +1 -0
- package/dist/components/settings-list.d.ts +60 -0
- package/dist/components/settings-list.d.ts.map +1 -0
- package/dist/components/settings-list.js +252 -0
- package/dist/components/settings-list.js.map +1 -0
- package/dist/components/spacer.d.ts +12 -0
- package/dist/components/spacer.d.ts.map +1 -0
- package/dist/components/spacer.js +23 -0
- package/dist/components/spacer.js.map +1 -0
- package/dist/components/stack.d.ts +32 -0
- package/dist/components/stack.d.ts.map +1 -0
- package/dist/components/stack.js +111 -0
- package/dist/components/stack.js.map +1 -0
- package/dist/components/text.d.ts +19 -0
- package/dist/components/text.d.ts.map +1 -0
- package/dist/components/text.js +90 -0
- package/dist/components/text.js.map +1 -0
- package/dist/components/truncated-text.d.ts +13 -0
- package/dist/components/truncated-text.d.ts.map +1 -0
- package/dist/components/truncated-text.js +51 -0
- package/dist/components/truncated-text.js.map +1 -0
- package/dist/components/v-stack.d.ts +8 -0
- package/dist/components/v-stack.d.ts.map +1 -0
- package/dist/components/v-stack.js +26 -0
- package/dist/components/v-stack.js.map +1 -0
- package/dist/components/virtual-list.d.ts +51 -0
- package/dist/components/virtual-list.d.ts.map +1 -0
- package/dist/components/virtual-list.js +170 -0
- package/dist/components/virtual-list.js.map +1 -0
- package/dist/editor-component.d.ts +39 -0
- package/dist/editor-component.d.ts.map +1 -0
- package/dist/editor-component.js +2 -0
- package/dist/editor-component.js.map +1 -0
- package/dist/fuzzy.d.ts +16 -0
- package/dist/fuzzy.d.ts.map +1 -0
- package/dist/fuzzy.js +110 -0
- package/dist/fuzzy.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/keybindings.d.ts +366 -0
- package/dist/keybindings.d.ts.map +1 -0
- package/dist/keybindings.js +331 -0
- package/dist/keybindings.js.map +1 -0
- package/dist/keys.d.ts +184 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +1174 -0
- package/dist/keys.js.map +1 -0
- package/dist/kill-ring.d.ts +28 -0
- package/dist/kill-ring.d.ts.map +1 -0
- package/dist/kill-ring.js +44 -0
- package/dist/kill-ring.js.map +1 -0
- package/dist/latex.d.ts +10 -0
- package/dist/latex.d.ts.map +1 -0
- package/dist/latex.js +1285 -0
- package/dist/latex.js.map +1 -0
- package/dist/layout-node.d.ts +59 -0
- package/dist/layout-node.d.ts.map +1 -0
- package/dist/layout-node.js +12 -0
- package/dist/layout-node.js.map +1 -0
- package/dist/layout.d.ts +42 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +404 -0
- package/dist/layout.js.map +1 -0
- package/dist/native-modifiers.d.ts +4 -0
- package/dist/native-modifiers.d.ts.map +1 -0
- package/dist/native-modifiers.js +13 -0
- package/dist/native-modifiers.js.map +1 -0
- package/dist/native-module-path.d.ts +7 -0
- package/dist/native-module-path.d.ts.map +1 -0
- package/dist/native-module-path.js +19 -0
- package/dist/native-module-path.js.map +1 -0
- package/dist/native-platform.d.ts +18 -0
- package/dist/native-platform.d.ts.map +1 -0
- package/dist/native-platform.js +42 -0
- package/dist/native-platform.js.map +1 -0
- package/dist/pty-host.d.ts +224 -0
- package/dist/pty-host.d.ts.map +1 -0
- package/dist/pty-host.js +347 -0
- package/dist/pty-host.js.map +1 -0
- package/dist/stdin-buffer.d.ts +56 -0
- package/dist/stdin-buffer.d.ts.map +1 -0
- package/dist/stdin-buffer.js +366 -0
- package/dist/stdin-buffer.js.map +1 -0
- package/dist/terminal-colors.d.ts +10 -0
- package/dist/terminal-colors.d.ts.map +1 -0
- package/dist/terminal-colors.js +59 -0
- package/dist/terminal-colors.js.map +1 -0
- package/dist/terminal-image.d.ts +118 -0
- package/dist/terminal-image.d.ts.map +1 -0
- package/dist/terminal-image.js +550 -0
- package/dist/terminal-image.js.map +1 -0
- package/dist/terminal.d.ts +123 -0
- package/dist/terminal.d.ts.map +1 -0
- package/dist/terminal.js +442 -0
- package/dist/terminal.js.map +1 -0
- package/dist/tui-alt-screen.d.ts +165 -0
- package/dist/tui-alt-screen.d.ts.map +1 -0
- package/dist/tui-alt-screen.js +1515 -0
- package/dist/tui-alt-screen.js.map +1 -0
- package/dist/tui-main-screen.d.ts +39 -0
- package/dist/tui-main-screen.d.ts.map +1 -0
- package/dist/tui-main-screen.js +594 -0
- package/dist/tui-main-screen.js.map +1 -0
- package/dist/tui.d.ts +431 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/tui.js +1142 -0
- package/dist/tui.js.map +1 -0
- package/dist/undo-stack.d.ts +17 -0
- package/dist/undo-stack.d.ts.map +1 -0
- package/dist/undo-stack.js +25 -0
- package/dist/undo-stack.js.map +1 -0
- package/dist/utils.d.ts +98 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1200 -0
- package/dist/utils.js.map +1 -0
- package/dist/word-navigation.d.ts +25 -0
- package/dist/word-navigation.d.ts.map +1 -0
- package/dist/word-navigation.js +96 -0
- package/dist/word-navigation.js.map +1 -0
- package/native/clipboard.h +170 -0
- package/native/darwin/README.md +22 -0
- package/native/darwin/build.sh +69 -0
- package/native/darwin/prebuilds/darwin-arm64/darwin-platform.node +0 -0
- package/native/darwin/prebuilds/darwin-x64/darwin-platform.node +0 -0
- package/native/darwin/src/darwin-platform.m +93 -0
- package/native/linux/README.md +23 -0
- package/native/linux/build.sh +65 -0
- package/native/linux/prebuilds/linux-arm64/linux-platform-x11.node +0 -0
- package/native/linux/prebuilds/linux-x64/linux-platform-x11.node +0 -0
- package/native/linux/src/clipboard-worker.h +70 -0
- package/native/linux/src/linux-platform-x11.c +274 -0
- package/native/napi.h +89 -0
- package/native/win32/README.md +31 -0
- package/native/win32/build.mjs +232 -0
- package/native/win32/prebuilds/win32-arm64/win32-platform.node +0 -0
- package/native/win32/prebuilds/win32-x64/win32-platform.node +0 -0
- package/native/win32/src/win32-platform.c +241 -0
- package/package.json +62 -0
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { readdirSync, statSync } from "fs";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { basename, dirname, join } from "path";
|
|
5
|
+
import { fuzzyFilter } from "./fuzzy.js";
|
|
6
|
+
const PATH_DELIMITERS = new Set([" ", "\t", '"', "'", "="]);
|
|
7
|
+
function toDisplayPath(value) {
|
|
8
|
+
return value.replace(/\\/g, "/");
|
|
9
|
+
}
|
|
10
|
+
function escapeRegex(value) {
|
|
11
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
12
|
+
}
|
|
13
|
+
function buildFdPathQuery(query) {
|
|
14
|
+
const normalized = toDisplayPath(query);
|
|
15
|
+
if (!normalized.includes("/")) {
|
|
16
|
+
return normalized;
|
|
17
|
+
}
|
|
18
|
+
const hasTrailingSeparator = normalized.endsWith("/");
|
|
19
|
+
const trimmed = normalized.replace(/^\/+|\/+$/g, "");
|
|
20
|
+
if (!trimmed) {
|
|
21
|
+
return normalized;
|
|
22
|
+
}
|
|
23
|
+
const separatorPattern = "[\\\\/]";
|
|
24
|
+
const segments = trimmed
|
|
25
|
+
.split("/")
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.map((segment) => escapeRegex(segment));
|
|
28
|
+
if (segments.length === 0) {
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
let pattern = segments.join(separatorPattern);
|
|
32
|
+
if (hasTrailingSeparator) {
|
|
33
|
+
pattern += separatorPattern;
|
|
34
|
+
}
|
|
35
|
+
return pattern;
|
|
36
|
+
}
|
|
37
|
+
function findLastDelimiter(text) {
|
|
38
|
+
for (let i = text.length - 1; i >= 0; i -= 1) {
|
|
39
|
+
if (PATH_DELIMITERS.has(text[i] ?? "")) {
|
|
40
|
+
return i;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return -1;
|
|
44
|
+
}
|
|
45
|
+
function findUnclosedQuoteStart(text) {
|
|
46
|
+
let inQuotes = false;
|
|
47
|
+
let quoteStart = -1;
|
|
48
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
49
|
+
if (text[i] === '"') {
|
|
50
|
+
inQuotes = !inQuotes;
|
|
51
|
+
if (inQuotes) {
|
|
52
|
+
quoteStart = i;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return inQuotes ? quoteStart : null;
|
|
57
|
+
}
|
|
58
|
+
function isTokenStart(text, index) {
|
|
59
|
+
return index === 0 || PATH_DELIMITERS.has(text[index - 1] ?? "");
|
|
60
|
+
}
|
|
61
|
+
function extractQuotedPrefix(text) {
|
|
62
|
+
const quoteStart = findUnclosedQuoteStart(text);
|
|
63
|
+
if (quoteStart === null) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (quoteStart > 0 && text[quoteStart - 1] === "@") {
|
|
67
|
+
if (!isTokenStart(text, quoteStart - 1)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return text.slice(quoteStart - 1);
|
|
71
|
+
}
|
|
72
|
+
if (!isTokenStart(text, quoteStart)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return text.slice(quoteStart);
|
|
76
|
+
}
|
|
77
|
+
function parsePathPrefix(prefix) {
|
|
78
|
+
if (prefix.startsWith('@"')) {
|
|
79
|
+
return { rawPrefix: prefix.slice(2), isAtPrefix: true, isQuotedPrefix: true };
|
|
80
|
+
}
|
|
81
|
+
if (prefix.startsWith('"')) {
|
|
82
|
+
return { rawPrefix: prefix.slice(1), isAtPrefix: false, isQuotedPrefix: true };
|
|
83
|
+
}
|
|
84
|
+
if (prefix.startsWith("@")) {
|
|
85
|
+
return { rawPrefix: prefix.slice(1), isAtPrefix: true, isQuotedPrefix: false };
|
|
86
|
+
}
|
|
87
|
+
return { rawPrefix: prefix, isAtPrefix: false, isQuotedPrefix: false };
|
|
88
|
+
}
|
|
89
|
+
function buildCompletionValue(path, options) {
|
|
90
|
+
const needsQuotes = options.isQuotedPrefix || path.includes(" ");
|
|
91
|
+
const prefix = options.isAtPrefix ? "@" : "";
|
|
92
|
+
if (!needsQuotes) {
|
|
93
|
+
return `${prefix}${path}`;
|
|
94
|
+
}
|
|
95
|
+
const openQuote = `${prefix}"`;
|
|
96
|
+
const closeQuote = '"';
|
|
97
|
+
return `${openQuote}${path}${closeQuote}`;
|
|
98
|
+
}
|
|
99
|
+
// Use fd to walk directory tree (fast, respects .gitignore)
|
|
100
|
+
async function walkDirectoryWithFd(baseDir, fdPath, query, maxResults, signal, maxDepth) {
|
|
101
|
+
const args = [
|
|
102
|
+
"--base-directory",
|
|
103
|
+
baseDir,
|
|
104
|
+
"--max-results",
|
|
105
|
+
String(maxResults),
|
|
106
|
+
"--type",
|
|
107
|
+
"f",
|
|
108
|
+
"--type",
|
|
109
|
+
"d",
|
|
110
|
+
"--follow",
|
|
111
|
+
"--hidden",
|
|
112
|
+
"--exclude",
|
|
113
|
+
".git",
|
|
114
|
+
"--exclude",
|
|
115
|
+
".git/*",
|
|
116
|
+
"--exclude",
|
|
117
|
+
".git/**",
|
|
118
|
+
];
|
|
119
|
+
if (maxDepth !== undefined) {
|
|
120
|
+
args.push("--max-depth", String(maxDepth));
|
|
121
|
+
}
|
|
122
|
+
if (toDisplayPath(query).includes("/")) {
|
|
123
|
+
args.push("--full-path");
|
|
124
|
+
}
|
|
125
|
+
if (query) {
|
|
126
|
+
args.push(buildFdPathQuery(query));
|
|
127
|
+
}
|
|
128
|
+
return await new Promise((resolve) => {
|
|
129
|
+
if (signal.aborted) {
|
|
130
|
+
resolve([]);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const child = spawn(fdPath, args, {
|
|
134
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
135
|
+
});
|
|
136
|
+
let stdout = "";
|
|
137
|
+
let resolved = false;
|
|
138
|
+
const finish = (results) => {
|
|
139
|
+
if (resolved)
|
|
140
|
+
return;
|
|
141
|
+
resolved = true;
|
|
142
|
+
signal.removeEventListener("abort", onAbort);
|
|
143
|
+
resolve(results);
|
|
144
|
+
};
|
|
145
|
+
const onAbort = () => {
|
|
146
|
+
if (child.exitCode === null) {
|
|
147
|
+
child.kill("SIGKILL");
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
151
|
+
child.stdout.setEncoding("utf-8");
|
|
152
|
+
child.stdout.on("data", (chunk) => {
|
|
153
|
+
stdout += chunk;
|
|
154
|
+
});
|
|
155
|
+
child.on("error", () => {
|
|
156
|
+
finish([]);
|
|
157
|
+
});
|
|
158
|
+
child.on("close", (code) => {
|
|
159
|
+
if (signal.aborted || code !== 0 || !stdout) {
|
|
160
|
+
finish([]);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const lines = stdout.trim().split("\n").filter(Boolean);
|
|
164
|
+
const results = [];
|
|
165
|
+
for (const line of lines) {
|
|
166
|
+
const displayLine = toDisplayPath(line);
|
|
167
|
+
const hasTrailingSeparator = displayLine.endsWith("/");
|
|
168
|
+
const normalizedPath = hasTrailingSeparator ? displayLine.slice(0, -1) : displayLine;
|
|
169
|
+
if (normalizedPath === ".git" || normalizedPath.startsWith(".git/") || normalizedPath.includes("/.git/")) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
results.push({
|
|
173
|
+
path: displayLine,
|
|
174
|
+
isDirectory: hasTrailingSeparator,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
finish(results);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
// Combined provider that handles both slash commands and file paths
|
|
182
|
+
export class CombinedAutocompleteProvider {
|
|
183
|
+
commands;
|
|
184
|
+
basePath;
|
|
185
|
+
fdPath;
|
|
186
|
+
skillCompletions;
|
|
187
|
+
triggerCharacters;
|
|
188
|
+
constructor(commands = [], basePath, fdPath = null, skillCompletions) {
|
|
189
|
+
this.commands = commands;
|
|
190
|
+
this.basePath = basePath;
|
|
191
|
+
this.fdPath = fdPath;
|
|
192
|
+
this.skillCompletions = skillCompletions;
|
|
193
|
+
// : for colon commands, @ for scope statements ({@path}), $ for skill references
|
|
194
|
+
this.triggerCharacters = [":", "@", "$"];
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Build suggestion items from skill candidates. Returns null when nothing should
|
|
198
|
+
* be suggested: no candidates, or the typed partial already exactly names the only
|
|
199
|
+
* candidate (lets Enter submit right after completing a full `$name` token).
|
|
200
|
+
* Labels show the bare skill name; the trigger symbol is already in the prompt.
|
|
201
|
+
*/
|
|
202
|
+
buildSkillItems(candidates, partial, format) {
|
|
203
|
+
if (candidates.length === 0)
|
|
204
|
+
return null;
|
|
205
|
+
if (partial !== "" && candidates.length === 1 && candidates[0].name === partial)
|
|
206
|
+
return null;
|
|
207
|
+
return candidates.map((candidate) => ({
|
|
208
|
+
value: format(candidate.name),
|
|
209
|
+
label: candidate.name,
|
|
210
|
+
description: candidate.description,
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
async getSuggestions(lines, cursorLine, cursorCol, options) {
|
|
214
|
+
const currentLine = lines[cursorLine] || "";
|
|
215
|
+
const textBeforeCursor = currentLine.slice(0, cursorCol);
|
|
216
|
+
const atPrefix = this.extractAtPrefix(textBeforeCursor);
|
|
217
|
+
if (atPrefix) {
|
|
218
|
+
const { rawPrefix, isQuotedPrefix } = parsePathPrefix(atPrefix);
|
|
219
|
+
const suggestions = await this.getFuzzyFileSuggestions(rawPrefix, {
|
|
220
|
+
isQuotedPrefix,
|
|
221
|
+
signal: options.signal,
|
|
222
|
+
});
|
|
223
|
+
if (suggestions.length === 0)
|
|
224
|
+
return null;
|
|
225
|
+
return {
|
|
226
|
+
items: suggestions,
|
|
227
|
+
prefix: atPrefix,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
// $name and {$name skill references — always insert braced form {$name}
|
|
231
|
+
const skillMatch = /\{?\$([A-Za-z0-9_-]*)$/.exec(textBeforeCursor);
|
|
232
|
+
if (skillMatch && this.skillCompletions) {
|
|
233
|
+
const items = this.buildSkillItems(this.skillCompletions(skillMatch[1] ?? ""), skillMatch[1] ?? "", (name) => `{$${name}}`);
|
|
234
|
+
if (!items)
|
|
235
|
+
return null;
|
|
236
|
+
return { items, prefix: skillMatch[0] };
|
|
237
|
+
}
|
|
238
|
+
// hidden /skill:name alias completion (never listed in the / menu itself).
|
|
239
|
+
// Value omits the leading "/" because applyCompletion's command branch adds it.
|
|
240
|
+
const aliasMatch = /^\/skill:([A-Za-z0-9_-]*)$/.exec(textBeforeCursor);
|
|
241
|
+
if (aliasMatch && this.skillCompletions) {
|
|
242
|
+
const items = this.buildSkillItems(this.skillCompletions(aliasMatch[1] ?? ""), aliasMatch[1] ?? "", (name) => `skill:${name}`);
|
|
243
|
+
if (!items)
|
|
244
|
+
return null;
|
|
245
|
+
return { items, prefix: aliasMatch[0] };
|
|
246
|
+
}
|
|
247
|
+
if (!options.force && (textBeforeCursor.startsWith(":") || textBeforeCursor.startsWith("/"))) {
|
|
248
|
+
const spaceIndex = textBeforeCursor.indexOf(" ");
|
|
249
|
+
if (spaceIndex === -1) {
|
|
250
|
+
// Colon commands only respond to `:`, non-colon commands only to `/`.
|
|
251
|
+
// For colon commands, show name without : prefix but insert with :
|
|
252
|
+
const isColonInput = textBeforeCursor.startsWith(":");
|
|
253
|
+
const prefix = textBeforeCursor;
|
|
254
|
+
const commandItems = this.commands
|
|
255
|
+
.map((cmd) => {
|
|
256
|
+
const name = "name" in cmd ? cmd.name : cmd.value;
|
|
257
|
+
const isColonCommand = name.startsWith(":");
|
|
258
|
+
if (isColonInput !== isColonCommand)
|
|
259
|
+
return null;
|
|
260
|
+
const displayName = isColonCommand ? name.slice(1) : name;
|
|
261
|
+
const hint = "argumentHint" in cmd && cmd.argumentHint ? cmd.argumentHint : undefined;
|
|
262
|
+
const desc = cmd.description ?? "";
|
|
263
|
+
const fullDesc = hint ? (desc ? `${hint} — ${desc}` : hint) : desc;
|
|
264
|
+
const group = "group" in cmd && cmd.group ? cmd.group : undefined;
|
|
265
|
+
return {
|
|
266
|
+
name,
|
|
267
|
+
label: displayName,
|
|
268
|
+
description: fullDesc || undefined,
|
|
269
|
+
...(group && { group }),
|
|
270
|
+
};
|
|
271
|
+
})
|
|
272
|
+
.filter((item) => item !== null);
|
|
273
|
+
const filtered = fuzzyFilter(commandItems, prefix, (item) => item.name).map((item) => ({
|
|
274
|
+
value: item.name,
|
|
275
|
+
label: item.label,
|
|
276
|
+
...(item.description && { description: item.description }),
|
|
277
|
+
...(item.group && { group: item.group }),
|
|
278
|
+
}));
|
|
279
|
+
if (filtered.length === 0)
|
|
280
|
+
return null;
|
|
281
|
+
return {
|
|
282
|
+
items: filtered,
|
|
283
|
+
prefix: textBeforeCursor,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
const commandName = textBeforeCursor.startsWith(":")
|
|
287
|
+
? textBeforeCursor.slice(0, spaceIndex)
|
|
288
|
+
: textBeforeCursor.slice(1, spaceIndex);
|
|
289
|
+
const argumentText = textBeforeCursor.slice(spaceIndex + 1);
|
|
290
|
+
const command = this.commands.find((cmd) => {
|
|
291
|
+
const name = "name" in cmd ? cmd.name : cmd.value;
|
|
292
|
+
return name === commandName;
|
|
293
|
+
});
|
|
294
|
+
if (!command || !("getArgumentCompletions" in command) || !command.getArgumentCompletions) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
const argumentSuggestions = await command.getArgumentCompletions(argumentText);
|
|
298
|
+
if (!Array.isArray(argumentSuggestions) || argumentSuggestions.length === 0) {
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
items: argumentSuggestions,
|
|
303
|
+
prefix: argumentText,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
// Don't trigger file path autocomplete for / at line start (command position)
|
|
307
|
+
if (textBeforeCursor.startsWith("/") && !textBeforeCursor.includes(" ")) {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
const pathMatch = this.extractPathPrefix(textBeforeCursor, options.force ?? false);
|
|
311
|
+
if (pathMatch === null) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
const suggestions = this.getFileSuggestions(pathMatch);
|
|
315
|
+
if (suggestions.length === 0)
|
|
316
|
+
return null;
|
|
317
|
+
return {
|
|
318
|
+
items: suggestions,
|
|
319
|
+
prefix: pathMatch,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
|
|
323
|
+
const currentLine = lines[cursorLine] || "";
|
|
324
|
+
const beforePrefix = currentLine.slice(0, cursorCol - prefix.length);
|
|
325
|
+
const afterCursor = currentLine.slice(cursorCol);
|
|
326
|
+
const isQuotedPrefix = prefix.startsWith('"') || prefix.startsWith('@"');
|
|
327
|
+
const hasLeadingQuoteAfterCursor = afterCursor.startsWith('"');
|
|
328
|
+
const hasTrailingQuoteInItem = item.value.endsWith('"');
|
|
329
|
+
const adjustedAfterCursor = isQuotedPrefix && hasTrailingQuoteInItem && hasLeadingQuoteAfterCursor ? afterCursor.slice(1) : afterCursor;
|
|
330
|
+
// Check if we're completing a slash command (prefix starts with "/" but NOT a file path)
|
|
331
|
+
// Slash commands are at the start of the line and don't contain path separators after the first /
|
|
332
|
+
const isSlashCommand = prefix.startsWith("/") && beforePrefix.trim() === "" && !prefix.slice(1).includes("/");
|
|
333
|
+
if (isSlashCommand) {
|
|
334
|
+
// This is a command name completion
|
|
335
|
+
const newLine = `${beforePrefix}/${item.value} ${adjustedAfterCursor}`;
|
|
336
|
+
const newLines = [...lines];
|
|
337
|
+
newLines[cursorLine] = newLine;
|
|
338
|
+
return {
|
|
339
|
+
lines: newLines,
|
|
340
|
+
cursorLine,
|
|
341
|
+
cursorCol: beforePrefix.length + item.value.length + 2, // +2 for "/" and space
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
// Check if we're completing a scope path (prefix starts with "@")
|
|
345
|
+
// Typing @ inserts a standalone scope statement. Picking a directory
|
|
346
|
+
// closes it right away ({@dir/}); picking a file leaves the brace open
|
|
347
|
+
// ({@file) so the Cue provider can offer the : range and } close flow.
|
|
348
|
+
if (prefix.startsWith("@")) {
|
|
349
|
+
const isDirectory = item.label.endsWith("/");
|
|
350
|
+
let insert = item.value;
|
|
351
|
+
if (insert.startsWith("@"))
|
|
352
|
+
insert = insert.slice(1);
|
|
353
|
+
if (insert.startsWith('"'))
|
|
354
|
+
insert = insert.slice(1);
|
|
355
|
+
if (insert.endsWith('"'))
|
|
356
|
+
insert = insert.slice(0, -1);
|
|
357
|
+
const suffix = isDirectory ? "} " : "";
|
|
358
|
+
const newLine = `${beforePrefix}{@${insert}${suffix}${adjustedAfterCursor}`;
|
|
359
|
+
const newLines = [...lines];
|
|
360
|
+
newLines[cursorLine] = newLine;
|
|
361
|
+
return {
|
|
362
|
+
lines: newLines,
|
|
363
|
+
cursorLine,
|
|
364
|
+
cursorCol: beforePrefix.length + 2 + insert.length + suffix.length,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
// {$name} skill references — closing brace is already in the value, no trailing space
|
|
368
|
+
if (prefix.startsWith("$") || prefix.startsWith("{$")) {
|
|
369
|
+
const newLine = `${beforePrefix}${item.value}${adjustedAfterCursor}`;
|
|
370
|
+
const newLines = [...lines];
|
|
371
|
+
newLines[cursorLine] = newLine;
|
|
372
|
+
return {
|
|
373
|
+
lines: newLines,
|
|
374
|
+
cursorLine,
|
|
375
|
+
cursorCol: beforePrefix.length + item.value.length,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
// Check if we're in a slash command context (beforePrefix contains "/command ")
|
|
379
|
+
const textBeforeCursor = currentLine.slice(0, cursorCol);
|
|
380
|
+
if (textBeforeCursor.includes("/") && textBeforeCursor.includes(" ")) {
|
|
381
|
+
// This is likely a command argument completion
|
|
382
|
+
const newLine = beforePrefix + item.value + adjustedAfterCursor;
|
|
383
|
+
const newLines = [...lines];
|
|
384
|
+
newLines[cursorLine] = newLine;
|
|
385
|
+
const isDirectory = item.label.endsWith("/");
|
|
386
|
+
const hasTrailingQuote = item.value.endsWith('"');
|
|
387
|
+
const cursorOffset = isDirectory && hasTrailingQuote ? item.value.length - 1 : item.value.length;
|
|
388
|
+
return {
|
|
389
|
+
lines: newLines,
|
|
390
|
+
cursorLine,
|
|
391
|
+
cursorCol: beforePrefix.length + cursorOffset,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
// For file paths, complete the path
|
|
395
|
+
const newLine = beforePrefix + item.value + adjustedAfterCursor;
|
|
396
|
+
const newLines = [...lines];
|
|
397
|
+
newLines[cursorLine] = newLine;
|
|
398
|
+
const isDirectory = item.label.endsWith("/");
|
|
399
|
+
const hasTrailingQuote = item.value.endsWith('"');
|
|
400
|
+
const cursorOffset = isDirectory && hasTrailingQuote ? item.value.length - 1 : item.value.length;
|
|
401
|
+
return {
|
|
402
|
+
lines: newLines,
|
|
403
|
+
cursorLine,
|
|
404
|
+
cursorCol: beforePrefix.length + cursorOffset,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
// Extract @ prefix for fuzzy file suggestions
|
|
408
|
+
extractAtPrefix(text) {
|
|
409
|
+
const quotedPrefix = extractQuotedPrefix(text);
|
|
410
|
+
if (quotedPrefix?.startsWith('@"')) {
|
|
411
|
+
return quotedPrefix;
|
|
412
|
+
}
|
|
413
|
+
const lastDelimiterIndex = findLastDelimiter(text);
|
|
414
|
+
const tokenStart = lastDelimiterIndex === -1 ? 0 : lastDelimiterIndex + 1;
|
|
415
|
+
if (text[tokenStart] === "@") {
|
|
416
|
+
return text.slice(tokenStart);
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
// Extract a path-like prefix from the text before cursor
|
|
421
|
+
extractPathPrefix(text, forceExtract = false) {
|
|
422
|
+
const quotedPrefix = extractQuotedPrefix(text);
|
|
423
|
+
if (quotedPrefix) {
|
|
424
|
+
return quotedPrefix;
|
|
425
|
+
}
|
|
426
|
+
const lastDelimiterIndex = findLastDelimiter(text);
|
|
427
|
+
const pathPrefix = lastDelimiterIndex === -1 ? text : text.slice(lastDelimiterIndex + 1);
|
|
428
|
+
// For forced extraction (Tab key), always return something
|
|
429
|
+
if (forceExtract) {
|
|
430
|
+
return pathPrefix;
|
|
431
|
+
}
|
|
432
|
+
// For natural triggers, return if it looks like a path, ends with /, starts with ~/, .
|
|
433
|
+
// Only return empty string if the text looks like it's starting a path context
|
|
434
|
+
if (pathPrefix.includes("/") || pathPrefix.startsWith(".") || pathPrefix.startsWith("~/")) {
|
|
435
|
+
return pathPrefix;
|
|
436
|
+
}
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
// Expand home directory (~/) to actual home path
|
|
440
|
+
expandHomePath(path) {
|
|
441
|
+
if (path.startsWith("~/")) {
|
|
442
|
+
const expandedPath = join(homedir(), path.slice(2));
|
|
443
|
+
// Preserve trailing slash if original path had one
|
|
444
|
+
return path.endsWith("/") && !expandedPath.endsWith("/") ? `${expandedPath}/` : expandedPath;
|
|
445
|
+
}
|
|
446
|
+
else if (path === "~") {
|
|
447
|
+
return homedir();
|
|
448
|
+
}
|
|
449
|
+
return path;
|
|
450
|
+
}
|
|
451
|
+
resolveScopedFuzzyQuery(rawQuery) {
|
|
452
|
+
const normalizedQuery = toDisplayPath(rawQuery);
|
|
453
|
+
const slashIndex = normalizedQuery.lastIndexOf("/");
|
|
454
|
+
if (slashIndex === -1) {
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
const displayBase = normalizedQuery.slice(0, slashIndex + 1);
|
|
458
|
+
const query = normalizedQuery.slice(slashIndex + 1);
|
|
459
|
+
let baseDir;
|
|
460
|
+
if (displayBase.startsWith("~/")) {
|
|
461
|
+
baseDir = this.expandHomePath(displayBase);
|
|
462
|
+
}
|
|
463
|
+
else if (displayBase.startsWith("/")) {
|
|
464
|
+
baseDir = displayBase;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
baseDir = join(this.basePath, displayBase);
|
|
468
|
+
}
|
|
469
|
+
try {
|
|
470
|
+
if (!statSync(baseDir).isDirectory()) {
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
return null;
|
|
476
|
+
}
|
|
477
|
+
return { baseDir, query, displayBase };
|
|
478
|
+
}
|
|
479
|
+
scopedPathForDisplay(displayBase, relativePath) {
|
|
480
|
+
const normalizedRelativePath = toDisplayPath(relativePath);
|
|
481
|
+
if (displayBase === "/") {
|
|
482
|
+
return `/${normalizedRelativePath}`;
|
|
483
|
+
}
|
|
484
|
+
return `${toDisplayPath(displayBase)}${normalizedRelativePath}`;
|
|
485
|
+
}
|
|
486
|
+
// Get file/directory suggestions for a given path prefix
|
|
487
|
+
getFileSuggestions(prefix) {
|
|
488
|
+
try {
|
|
489
|
+
let searchDir;
|
|
490
|
+
let searchPrefix;
|
|
491
|
+
const { rawPrefix, isAtPrefix, isQuotedPrefix } = parsePathPrefix(prefix);
|
|
492
|
+
let expandedPrefix = rawPrefix;
|
|
493
|
+
// Handle home directory expansion
|
|
494
|
+
if (expandedPrefix.startsWith("~")) {
|
|
495
|
+
expandedPrefix = this.expandHomePath(expandedPrefix);
|
|
496
|
+
}
|
|
497
|
+
const isRootPrefix = rawPrefix === "" ||
|
|
498
|
+
rawPrefix === "./" ||
|
|
499
|
+
rawPrefix === "../" ||
|
|
500
|
+
rawPrefix === "~" ||
|
|
501
|
+
rawPrefix === "~/" ||
|
|
502
|
+
rawPrefix === "/" ||
|
|
503
|
+
(isAtPrefix && rawPrefix === "");
|
|
504
|
+
if (isRootPrefix) {
|
|
505
|
+
// Complete from specified position
|
|
506
|
+
if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
|
|
507
|
+
searchDir = expandedPrefix;
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
searchDir = join(this.basePath, expandedPrefix);
|
|
511
|
+
}
|
|
512
|
+
searchPrefix = "";
|
|
513
|
+
}
|
|
514
|
+
else if (rawPrefix.endsWith("/")) {
|
|
515
|
+
// If prefix ends with /, show contents of that directory
|
|
516
|
+
if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
|
|
517
|
+
searchDir = expandedPrefix;
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
searchDir = join(this.basePath, expandedPrefix);
|
|
521
|
+
}
|
|
522
|
+
searchPrefix = "";
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
// Split into directory and file prefix
|
|
526
|
+
const dir = dirname(expandedPrefix);
|
|
527
|
+
const file = basename(expandedPrefix);
|
|
528
|
+
if (rawPrefix.startsWith("~") || expandedPrefix.startsWith("/")) {
|
|
529
|
+
searchDir = dir;
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
searchDir = join(this.basePath, dir);
|
|
533
|
+
}
|
|
534
|
+
searchPrefix = file;
|
|
535
|
+
}
|
|
536
|
+
const entries = readdirSync(searchDir, { withFileTypes: true });
|
|
537
|
+
const suggestions = [];
|
|
538
|
+
for (const entry of entries) {
|
|
539
|
+
if (!entry.name.toLowerCase().startsWith(searchPrefix.toLowerCase())) {
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
// Check if entry is a directory (or a symlink pointing to a directory)
|
|
543
|
+
let isDirectory = entry.isDirectory();
|
|
544
|
+
if (!isDirectory && entry.isSymbolicLink()) {
|
|
545
|
+
try {
|
|
546
|
+
const fullPath = join(searchDir, entry.name);
|
|
547
|
+
isDirectory = statSync(fullPath).isDirectory();
|
|
548
|
+
}
|
|
549
|
+
catch {
|
|
550
|
+
// Broken symlink or permission error - treat as file
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
let relativePath;
|
|
554
|
+
const name = entry.name;
|
|
555
|
+
const displayPrefix = rawPrefix;
|
|
556
|
+
if (displayPrefix.endsWith("/")) {
|
|
557
|
+
// If prefix ends with /, append entry to the prefix
|
|
558
|
+
relativePath = displayPrefix + name;
|
|
559
|
+
}
|
|
560
|
+
else if (displayPrefix.includes("/") || displayPrefix.includes("\\")) {
|
|
561
|
+
// Preserve ~/ format for home directory paths
|
|
562
|
+
if (displayPrefix.startsWith("~/")) {
|
|
563
|
+
const homeRelativeDir = displayPrefix.slice(2); // Remove ~/
|
|
564
|
+
const dir = dirname(homeRelativeDir);
|
|
565
|
+
relativePath = `~/${dir === "." ? name : join(dir, name)}`;
|
|
566
|
+
}
|
|
567
|
+
else if (displayPrefix.startsWith("/")) {
|
|
568
|
+
// Absolute path - construct properly
|
|
569
|
+
const dir = dirname(displayPrefix);
|
|
570
|
+
if (dir === "/") {
|
|
571
|
+
relativePath = `/${name}`;
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
relativePath = `${dir}/${name}`;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
relativePath = join(dirname(displayPrefix), name);
|
|
579
|
+
// path.join normalizes away ./ prefix, preserve it
|
|
580
|
+
if (displayPrefix.startsWith("./") && !relativePath.startsWith("./")) {
|
|
581
|
+
relativePath = `./${relativePath}`;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
// For standalone entries, preserve ~/ if original prefix was ~/
|
|
587
|
+
if (displayPrefix.startsWith("~")) {
|
|
588
|
+
relativePath = `~/${name}`;
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
relativePath = name;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
relativePath = toDisplayPath(relativePath);
|
|
595
|
+
const pathValue = isDirectory ? `${relativePath}/` : relativePath;
|
|
596
|
+
const value = buildCompletionValue(pathValue, {
|
|
597
|
+
isDirectory,
|
|
598
|
+
isAtPrefix,
|
|
599
|
+
isQuotedPrefix,
|
|
600
|
+
});
|
|
601
|
+
suggestions.push({
|
|
602
|
+
value,
|
|
603
|
+
label: name + (isDirectory ? "/" : ""),
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
// Sort directories first, then alphabetically
|
|
607
|
+
suggestions.sort((a, b) => {
|
|
608
|
+
const aIsDir = a.value.endsWith("/");
|
|
609
|
+
const bIsDir = b.value.endsWith("/");
|
|
610
|
+
if (aIsDir && !bIsDir)
|
|
611
|
+
return -1;
|
|
612
|
+
if (!aIsDir && bIsDir)
|
|
613
|
+
return 1;
|
|
614
|
+
return a.label.localeCompare(b.label);
|
|
615
|
+
});
|
|
616
|
+
return suggestions;
|
|
617
|
+
}
|
|
618
|
+
catch (_e) {
|
|
619
|
+
// Directory doesn't exist or not accessible
|
|
620
|
+
return [];
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
// Score an entry against the query (higher = better match)
|
|
624
|
+
// isDirectory adds bonus to prioritize folders
|
|
625
|
+
scoreEntry(filePath, query, isDirectory) {
|
|
626
|
+
const fileName = basename(filePath);
|
|
627
|
+
const lowerFileName = fileName.toLowerCase();
|
|
628
|
+
const lowerQuery = query.toLowerCase();
|
|
629
|
+
let score = 0;
|
|
630
|
+
// Exact filename match (highest)
|
|
631
|
+
if (lowerFileName === lowerQuery)
|
|
632
|
+
score = 100;
|
|
633
|
+
// Filename starts with query
|
|
634
|
+
else if (lowerFileName.startsWith(lowerQuery))
|
|
635
|
+
score = 80;
|
|
636
|
+
// Substring match in filename
|
|
637
|
+
else if (lowerFileName.includes(lowerQuery))
|
|
638
|
+
score = 50;
|
|
639
|
+
// Substring match in full path
|
|
640
|
+
else if (filePath.toLowerCase().includes(lowerQuery))
|
|
641
|
+
score = 30;
|
|
642
|
+
// Directories get a bonus to appear first
|
|
643
|
+
if (isDirectory && score > 0)
|
|
644
|
+
score += 10;
|
|
645
|
+
return score;
|
|
646
|
+
}
|
|
647
|
+
async getBaseDirSuggestions(baseDir, query, signal) {
|
|
648
|
+
if (!this.fdPath || signal.aborted) {
|
|
649
|
+
return [];
|
|
650
|
+
}
|
|
651
|
+
return await walkDirectoryWithFd(baseDir, this.fdPath, query, 100, signal, 1);
|
|
652
|
+
}
|
|
653
|
+
// Fuzzy file search using fd (fast, respects .gitignore)
|
|
654
|
+
async getFuzzyFileSuggestions(query, options) {
|
|
655
|
+
if (!this.fdPath || options.signal.aborted) {
|
|
656
|
+
return [];
|
|
657
|
+
}
|
|
658
|
+
try {
|
|
659
|
+
const scopedQuery = this.resolveScopedFuzzyQuery(query);
|
|
660
|
+
const fdBaseDir = scopedQuery?.baseDir ?? this.basePath;
|
|
661
|
+
const fdQuery = scopedQuery?.query ?? query;
|
|
662
|
+
const baseDirEntries = await this.getBaseDirSuggestions(fdBaseDir, fdQuery, options.signal);
|
|
663
|
+
const recursiveEntries = await walkDirectoryWithFd(fdBaseDir, this.fdPath, fdQuery, 100, options.signal);
|
|
664
|
+
const seenPaths = new Set(baseDirEntries.map((entry) => entry.path));
|
|
665
|
+
const entries = [
|
|
666
|
+
...baseDirEntries,
|
|
667
|
+
...recursiveEntries.filter((entry) => {
|
|
668
|
+
if (seenPaths.has(entry.path))
|
|
669
|
+
return false;
|
|
670
|
+
seenPaths.add(entry.path);
|
|
671
|
+
return true;
|
|
672
|
+
}),
|
|
673
|
+
];
|
|
674
|
+
if (options.signal.aborted) {
|
|
675
|
+
return [];
|
|
676
|
+
}
|
|
677
|
+
const scoredEntries = entries
|
|
678
|
+
.map((entry) => ({
|
|
679
|
+
...entry,
|
|
680
|
+
score: fdQuery ? this.scoreEntry(entry.path, fdQuery, entry.isDirectory) : 1,
|
|
681
|
+
}))
|
|
682
|
+
.filter((entry) => entry.score > 0);
|
|
683
|
+
scoredEntries.sort((a, b) => {
|
|
684
|
+
const scoreDiff = b.score - a.score;
|
|
685
|
+
if (scoreDiff !== 0)
|
|
686
|
+
return scoreDiff;
|
|
687
|
+
const aDepth = toDisplayPath(a.path).split("/").filter(Boolean).length;
|
|
688
|
+
const bDepth = toDisplayPath(b.path).split("/").filter(Boolean).length;
|
|
689
|
+
const depthDiff = aDepth - bDepth;
|
|
690
|
+
if (depthDiff !== 0)
|
|
691
|
+
return depthDiff;
|
|
692
|
+
const lengthDiff = a.path.length - b.path.length;
|
|
693
|
+
if (lengthDiff !== 0)
|
|
694
|
+
return lengthDiff;
|
|
695
|
+
return a.path.localeCompare(b.path);
|
|
696
|
+
});
|
|
697
|
+
const topEntries = scoredEntries.slice(0, 20);
|
|
698
|
+
const suggestions = [];
|
|
699
|
+
for (const { path: entryPath, isDirectory } of topEntries) {
|
|
700
|
+
const pathWithoutSlash = isDirectory ? entryPath.slice(0, -1) : entryPath;
|
|
701
|
+
const displayPath = scopedQuery
|
|
702
|
+
? this.scopedPathForDisplay(scopedQuery.displayBase, pathWithoutSlash)
|
|
703
|
+
: pathWithoutSlash;
|
|
704
|
+
const entryName = basename(pathWithoutSlash);
|
|
705
|
+
const completionPath = isDirectory ? `${displayPath}/` : displayPath;
|
|
706
|
+
const value = buildCompletionValue(completionPath, {
|
|
707
|
+
isDirectory,
|
|
708
|
+
isAtPrefix: true,
|
|
709
|
+
isQuotedPrefix: options.isQuotedPrefix,
|
|
710
|
+
});
|
|
711
|
+
suggestions.push({
|
|
712
|
+
value,
|
|
713
|
+
label: entryName + (isDirectory ? "/" : ""),
|
|
714
|
+
description: displayPath,
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
return suggestions;
|
|
718
|
+
}
|
|
719
|
+
catch {
|
|
720
|
+
return [];
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
// Mid-word trigger: ":" completing "/skill" opens the alias suggestion list
|
|
724
|
+
// without requiring a Tab press (mirrors how "/" opens the slash menu)
|
|
725
|
+
shouldTriggerMidWord(textBeforeCursor, char) {
|
|
726
|
+
return char === ":" && /^\/skill:$/.test(textBeforeCursor);
|
|
727
|
+
}
|
|
728
|
+
// Check if we should trigger file completion (called on Tab key)
|
|
729
|
+
shouldTriggerFileCompletion(lines, cursorLine, cursorCol) {
|
|
730
|
+
const currentLine = lines[cursorLine] || "";
|
|
731
|
+
const textBeforeCursor = currentLine.slice(0, cursorCol);
|
|
732
|
+
// Don't trigger if we're typing a slash command at the start of the line
|
|
733
|
+
if (textBeforeCursor.trim().startsWith("/") && !textBeforeCursor.trim().includes(" ")) {
|
|
734
|
+
return false;
|
|
735
|
+
}
|
|
736
|
+
// Only offer file completion in an actual path context: an `@` prefix,
|
|
737
|
+
// an unclosed quoted path, or a path-like token (contains a separator
|
|
738
|
+
// or starts with `.` / `~/`). A plain word or text ending in a space
|
|
739
|
+
// is not a path context — Tab should do nothing there.
|
|
740
|
+
if (this.extractAtPrefix(textBeforeCursor))
|
|
741
|
+
return true;
|
|
742
|
+
if (extractQuotedPrefix(textBeforeCursor))
|
|
743
|
+
return true;
|
|
744
|
+
const lastDelimiterIndex = findLastDelimiter(textBeforeCursor);
|
|
745
|
+
const token = textBeforeCursor.slice(lastDelimiterIndex + 1);
|
|
746
|
+
return token.includes("/") || token.startsWith(".") || token.startsWith("~/");
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
//# sourceMappingURL=autocomplete.js.map
|