chore: add debug logging to autocomplete suggestion system

Added session tracking and logging to help diagnose why autocomplete
filtering stops working after the first use. Logs show:
- When items() is called with query and result count
- When onStart/onUpdate/onExit are called
- Session IDs to track suggestion lifecycle
This commit is contained in:
Claude
2026-01-20 16:58:30 +00:00
parent b2b5346abe
commit 19add5dce6

View File

@@ -318,20 +318,31 @@ function createSuggestionConfig<T>(
config: SuggestionConfig<T>, config: SuggestionConfig<T>,
handleSubmitRef: React.MutableRefObject<(editor: unknown) => void>, handleSubmitRef: React.MutableRefObject<(editor: unknown) => void>,
): Omit<SuggestionOptions<T>, "editor"> { ): Omit<SuggestionOptions<T>, "editor"> {
// Track session for debugging
let sessionId = 0;
return { return {
char: config.char, char: config.char,
allowSpaces: config.allowSpaces ?? false, allowSpaces: config.allowSpaces ?? false,
allow: config.allow, allow: config.allow,
items: async ({ query }) => { items: async ({ query }) => {
return await config.search(query); const results = await config.search(query);
console.log(
`[Suggestion ${config.char}] items called: query="${query}" results=${results.length} session=${sessionId}`,
);
return results;
}, },
render: () => { render: () => {
let component: ReactRenderer<SuggestionListHandle>; let component: ReactRenderer<SuggestionListHandle>;
let popup: TippyInstance[]; let popup: TippyInstance[];
let editorRef: unknown; let editorRef: unknown;
const currentSession = ++sessionId;
return { return {
onStart: (props) => { onStart: (props) => {
console.log(
`[Suggestion ${config.char}] onStart: session=${currentSession} items=${props.items?.length}`,
);
editorRef = props.editor; editorRef = props.editor;
component = new ReactRenderer(config.component as never, { component = new ReactRenderer(config.component as never, {
props: { props: {
@@ -357,6 +368,9 @@ function createSuggestionConfig<T>(
}, },
onUpdate(props) { onUpdate(props) {
console.log(
`[Suggestion ${config.char}] onUpdate: session=${currentSession} items=${props.items?.length}`,
);
component.updateProps({ component.updateProps({
items: props.items, items: props.items,
command: props.command, command: props.command,
@@ -389,6 +403,9 @@ function createSuggestionConfig<T>(
}, },
onExit() { onExit() {
console.log(
`[Suggestion ${config.char}] onExit: session=${currentSession}`,
);
popup[0]?.destroy(); popup[0]?.destroy();
component.destroy(); component.destroy();
}, },