feat(redis): add command terminal autocomplete

This commit is contained in:
onenewcode authored and GitHub committed 2026-08-12 00:41:31 +08:00
1 parent 80bd8dac06
commit dbe3375739
13 files changed
+1865 -337

No files matched your search

@@ -3114,7 +3114,7 @@ function completionOptionForItem(item: QueryCompletionItem) {
markCompletionAccepted(item);
const replaceTo = "replaceClosingQuote" in item && item.replaceClosingQuote === view.state.sliceDoc(to, to + 1) ? to + 1 : to;
const insert = appendSqlCompletionSpace(item.apply ?? item.label, {
enabled: shouldInsertSqlCompletionSpace() && settingsStore.editorSettings.insertSpaceAfterCompletion,
enabled: ("appendSpace" in item && item.appendSpace === true) || (shouldInsertSqlCompletionSpace() && settingsStore.editorSettings.insertSpaceAfterCompletion),
itemType: item.type,
nextCharacter: view.state.sliceDoc(replaceTo, replaceTo + 1),
});
@@ -3157,11 +3157,22 @@ async function provideRedisCompletions(currentState: import("@codemirror/state")
const fullDoc = currentState.doc.toString();
if (!explicit && !shouldAutoOpenRedisCompletion(fullDoc, position)) return null;
const completionContext = getRedisCompletionContext(fullDoc, position);
let commands;
try {
commands = await connectionStore.listRedisCompletionCommandDocs(props.connectionId, props.database ?? "0");
} catch {
// Completion is deliberately instance-driven: do not substitute a bundled
// command list when the server does not expose command metadata.
return null;
}
if (epoch !== completionEpoch) return null;
const completionInput = { commands };
const completionContext = getRedisCompletionContext(fullDoc, position, completionInput);
// Key-name completion needs a reliable db index; props.database may briefly be "" on
// the New Query path before the active db resolves, and only key-argument commands warrant it.
let keys: string[] = [];
if (completionContext.mode === "argument" && props.database && takesKeyArgument(completionContext.mainCommand)) {
if (completionContext.mode === "argument" && props.database && takesKeyArgument(completionContext.commandName, completionInput, completionContext.argumentIndex, completionContext.argumentValues)) {
try {
keys = await connectionStore.listRedisCompletionKeys(props.connectionId, props.database);
} catch {
@@ -3172,6 +3183,7 @@ async function provideRedisCompletions(currentState: import("@codemirror/state")
const items = buildRedisCompletionItemsFromContext(completionContext, {
keys,
commands,
});
if (items.length === 0) return null;
// Use the built-in filter (the default) so typing narrows the list and moves