@@ -222,25 +222,33 @@ export interface AutocompleteSuggestion {
222222 */
223223export async function getSuggestions (
224224 query : string ,
225- _role : string
225+ role : string
226226) : Promise < AutocompleteSuggestion [ ] > {
227- // This is a placeholder implementation for the test
228- // In a real implementation, this would call the Tauri backend
227+ const { invoke } = await import ( '@tauri-apps/api/tauri' ) ;
229228 const suggestions : AutocompleteSuggestion [ ] = [ ] ;
230229
231230 // Parse the input to see if it contains operators
232231 const parsed = parseSearchInput ( query ) ;
233232
234- // For now, return mock suggestions that match the test expectations
235- if ( query . includes ( 'rust' ) ) {
236- suggestions . push (
237- { term : 'rust' , type : 'term' , description : 'Rust programming language' } ,
238- { term : 'rust-lang' , type : 'term' , description : 'Rust language documentation' }
239- ) ;
233+ try {
234+ // Call the Tauri backend for autocomplete suggestions
235+ const backendSuggestions = await invoke ( 'get_autocomplete_suggestions' , {
236+ query : query . trim ( ) ,
237+ role : role
238+ } ) ;
239+
240+ // Handle undefined or null responses
241+ if ( Array . isArray ( backendSuggestions ) ) {
242+ suggestions . push ( ...backendSuggestions ) ;
243+ }
244+ } catch ( error ) {
245+ // Fallback to empty suggestions if backend call fails
246+ console . warn ( 'Failed to get autocomplete suggestions:' , error ) ;
240247 }
241248
242249 // Add operator suggestions for complete terms (length >= 3)
243- if ( query . length >= 3 && ! query . includes ( ' AND ' ) && ! query . includes ( ' OR ' ) ) {
250+ // Only add operator suggestions if there's no operator in the query
251+ if ( query . length >= 3 && ! parsed . hasOperator ) {
244252 const lastTerm = parsed . terms [ parsed . terms . length - 1 ] ;
245253 if ( lastTerm && lastTerm . length >= 3 ) {
246254 suggestions . push (
@@ -258,5 +266,6 @@ export async function getSuggestions(
258266 }
259267 }
260268
261- return suggestions ;
269+ // Limit suggestions to reasonable number for UX (max 10)
270+ return suggestions . slice ( 0 , 10 ) ;
262271}
0 commit comments