feat(core): Add trailing space when completing an at completion suggestion (#5475)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
Sandy Tao 2025-08-04 11:30:59 -07:00 committed by GitHub
parent b9fe4fc263
commit d1bfba1abb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 9 deletions

View File

@ -7,7 +7,7 @@
/** @vitest-environment jsdom */ /** @vitest-environment jsdom */
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'; import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import { renderHook, act } from '@testing-library/react'; import { renderHook, act, waitFor } from '@testing-library/react';
import { useSlashCompletion } from './useSlashCompletion.js'; import { useSlashCompletion } from './useSlashCompletion.js';
import * as fs from 'fs/promises'; import * as fs from 'fs/promises';
import * as path from 'path'; import * as path from 'path';
@ -136,7 +136,7 @@ describe('useSlashCompletion', () => {
expect(result.current.isLoadingSuggestions).toBe(false); expect(result.current.isLoadingSuggestions).toBe(false);
}); });
it('should reset all state to default values', () => { it('should reset all state to default values', async () => {
const slashCommands = [ const slashCommands = [
{ {
name: 'help', name: 'help',
@ -165,6 +165,11 @@ describe('useSlashCompletion', () => {
result.current.resetCompletionState(); result.current.resetCompletionState();
}); });
// Wait for async suggestions clearing
await waitFor(() => {
expect(result.current.suggestions).toEqual([]);
});
expect(result.current.suggestions).toEqual([]); expect(result.current.suggestions).toEqual([]);
expect(result.current.activeSuggestionIndex).toBe(-1); expect(result.current.activeSuggestionIndex).toBe(-1);
expect(result.current.visibleStartIndex).toBe(0); expect(result.current.visibleStartIndex).toBe(0);
@ -1288,7 +1293,7 @@ describe('useSlashCompletion', () => {
result.current.handleAutocomplete(0); result.current.handleAutocomplete(0);
}); });
expect(result.current.textBuffer.text).toBe('@src/file1.txt'); expect(result.current.textBuffer.text).toBe('@src/file1.txt ');
}); });
it('should complete a file path when cursor is not at the end of the line', () => { it('should complete a file path when cursor is not at the end of the line', () => {
@ -1318,7 +1323,7 @@ describe('useSlashCompletion', () => {
result.current.handleAutocomplete(0); result.current.handleAutocomplete(0);
}); });
expect(result.current.textBuffer.text).toBe('@src/file1.txt le.txt'); expect(result.current.textBuffer.text).toBe('@src/file1.txt le.txt');
}); });
it('should complete the correct file path with multiple @-commands', () => { it('should complete the correct file path with multiple @-commands', () => {
@ -1347,7 +1352,7 @@ describe('useSlashCompletion', () => {
result.current.handleAutocomplete(0); result.current.handleAutocomplete(0);
}); });
expect(result.current.textBuffer.text).toBe('@file1.txt @src/file2.txt'); expect(result.current.textBuffer.text).toBe('@file1.txt @src/file2.txt ');
}); });
}); });

View File

@ -111,7 +111,7 @@ export function useSlashCompletion(
useEffect(() => { useEffect(() => {
if (commandIndex === -1 || reverseSearchActive) { if (commandIndex === -1 || reverseSearchActive) {
resetCompletionState(); setTimeout(resetCompletionState, 0);
return; return;
} }
@ -631,17 +631,17 @@ export function useSlashCompletion(
) { ) {
suggestionText = ' ' + suggestionText; suggestionText = ' ' + suggestionText;
} }
suggestionText += ' ';
} }
suggestionText += ' ';
buffer.replaceRangeByOffset( buffer.replaceRangeByOffset(
logicalPosToOffset(buffer.lines, cursorRow, completionStart.current), logicalPosToOffset(buffer.lines, cursorRow, completionStart.current),
logicalPosToOffset(buffer.lines, cursorRow, completionEnd.current), logicalPosToOffset(buffer.lines, cursorRow, completionEnd.current),
suggestionText, suggestionText,
); );
resetCompletionState();
}, },
[cursorRow, resetCompletionState, buffer, suggestions, commandIndex], [cursorRow, buffer, suggestions, commandIndex],
); );
return { return {