11import { useKeypress } from '#ui-ink/hooks/useKeypress'
22import { KEYPRESS_PRIORITY } from '#ui-ink/constants/keypressPriority'
33
4- import type {
5- CompletionContext ,
6- UnifiedSuggestion ,
4+ import {
5+ isLoadingSuggestion ,
6+ type CompletionContext ,
7+ type UnifiedSuggestion ,
78} from '#cli-utils/completion/types'
89import type { CompletionState } from './types'
910
@@ -63,6 +64,10 @@ export function useUnifiedCompletionNavigationKeys(args: {
6364 args . state . context
6465 ) {
6566 const context = args . state . context
67+ const selectedSuggestion =
68+ args . state . suggestions [ args . state . selectedIndex ]
69+ if ( isLoadingSuggestion ( selectedSuggestion ) ) return true
70+
6671 const isFileCompletion = context . type === 'file'
6772
6873 if ( isFileCompletion ) {
@@ -76,8 +81,6 @@ export function useUnifiedCompletionNavigationKeys(args: {
7681 return false
7782 } else {
7883 // Command/agent/other completion: fill the selected suggestion
79- const selectedSuggestion =
80- args . state . suggestions [ args . state . selectedIndex ]
8184 args . completeWith ( selectedSuggestion , context )
8285 args . resetCompletion ( )
8386 return true
@@ -94,6 +97,10 @@ export function useUnifiedCompletionNavigationKeys(args: {
9497 }
9598
9699 const suggestion = args . state . suggestions [ newIndex ]
100+ if ( isLoadingSuggestion ( suggestion ) ) {
101+ args . updateState ( { selectedIndex : newIndex } )
102+ return
103+ }
97104 const previewValue = getPreviewText ( suggestion , args . state . context )
98105
99106 if ( args . state . preview ?. isActive && args . state . context ) {
@@ -151,6 +158,8 @@ export function useUnifiedCompletionNavigationKeys(args: {
151158 if ( key . rightArrow ) {
152159 const selectedSuggestion =
153160 args . state . suggestions [ args . state . selectedIndex ]
161+ if ( isLoadingSuggestion ( selectedSuggestion ) ) return true
162+
154163 const isDirectory = selectedSuggestion . value . endsWith ( '/' )
155164
156165 if ( ! args . state . context ) return false
0 commit comments