@@ -11,8 +11,12 @@ import ee.carlrobert.codegpt.ui.textarea.lookup.LookupGroupItem
1111import ee.carlrobert.codegpt.ui.textarea.lookup.action.DiagnosticsActionItem
1212import ee.carlrobert.codegpt.ui.textarea.lookup.action.ImageActionItem
1313import ee.carlrobert.codegpt.ui.textarea.lookup.action.WebActionItem
14+ import ee.carlrobert.codegpt.ui.textarea.lookup.action.files.IncludeOpenFilesActionItem
15+ import ee.carlrobert.codegpt.ui.textarea.lookup.action.git.IncludeCurrentChangesActionItem
1416import ee.carlrobert.codegpt.ui.textarea.lookup.group.*
1517import kotlinx.coroutines.CancellationException
18+ import kotlinx.coroutines.async
19+ import kotlinx.coroutines.coroutineScope
1620
1721data class SearchState (
1822 val isInSearchContext : Boolean = false ,
@@ -63,33 +67,83 @@ class SearchManager(
6367 ImageActionItem (project, tagManager)
6468 ).filter { it.enabled }
6569
66- suspend fun performGlobalSearch (searchText : String ): List <LookupActionItem > {
67- val allGroups =
68- getDefaultGroups().filterNot { it is WebActionItem || it is ImageActionItem }
69- val allResults = mutableListOf<LookupActionItem >()
70+ suspend fun performInstantSearch (searchText : String ): List <LookupActionItem > {
71+ val groups = getDefaultGroups()
72+ val results = mutableListOf<LookupActionItem >()
73+
74+ // Standalone action items that are normally buried inside heavy groups
75+ if (groups.any { it is FilesGroupItem }) {
76+ results.add(IncludeOpenFilesActionItem ())
77+ }
78+ if (GitFeatureAvailability .isAvailable && groups.any { it is GitGroupItem }) {
79+ results.add(IncludeCurrentChangesActionItem ())
80+ }
7081
71- allGroups.forEach { group ->
82+ // Lightweight groups (in-memory data only)
83+ val lightGroups = groups
84+ .filterNot { it is FilesGroupItem || it is FoldersGroupItem || it is GitGroupItem }
85+ .filterNot { it is WebActionItem || it is ImageActionItem }
86+
87+ lightGroups.forEach { group ->
7288 try {
7389 if (group is LookupGroupItem ) {
74- val lookupActionItems =
75- group.getLookupItems(" " ).filterIsInstance<LookupActionItem >()
76- allResults.addAll(lookupActionItems )
90+ results.addAll(
91+ group.getLookupItems(searchText ).filterIsInstance<LookupActionItem >()
92+ )
7793 }
7894 } catch (e: CancellationException ) {
7995 throw e
8096 } catch (e: Exception ) {
81- logger.error(" Error getting results from ${group::class .simpleName} " , e)
97+ logger.error(" Error getting instant results from ${group::class .simpleName} " , e)
8298 }
8399 }
84100
85101 if (featureType != FeatureType .INLINE_EDIT && featureType != FeatureType .AGENT ) {
86102 val webAction = WebActionItem (tagManager)
87103 if (webAction.enabled()) {
88- allResults .add(webAction)
104+ results .add(webAction)
89105 }
90106 }
91107
92- return filterAndSortResults(allResults, searchText)
108+ return filterAndSortResults(results, searchText)
109+ }
110+
111+ suspend fun performHeavySearch (searchText : String ): List <LookupActionItem > = coroutineScope {
112+ val heavyGroups = getDefaultGroups()
113+ .filter { it is FilesGroupItem || it is FoldersGroupItem || it is GitGroupItem }
114+
115+ heavyGroups.map { group ->
116+ async {
117+ try {
118+ if (group is LookupGroupItem ) {
119+ group.getLookupItems(searchText).filterIsInstance<LookupActionItem >()
120+ } else {
121+ emptyList()
122+ }
123+ } catch (e: CancellationException ) {
124+ throw e
125+ } catch (e: Exception ) {
126+ logger.error(" Error getting results from ${group::class .simpleName} " , e)
127+ emptyList()
128+ }
129+ }
130+ }.flatMap { it.await() }
131+ }
132+
133+ fun mergeResults (
134+ instantResults : List <LookupActionItem >,
135+ heavyResults : List <LookupActionItem >,
136+ searchText : String
137+ ): List <LookupActionItem > {
138+ val seenNames = instantResults.map { it.displayName }.toMutableSet()
139+ val dedupedHeavy = heavyResults.filter { seenNames.add(it.displayName) }
140+ return filterAndSortResults(instantResults + dedupedHeavy, searchText)
141+ }
142+
143+ suspend fun performGlobalSearch (searchText : String ): List <LookupActionItem > {
144+ val instant = performInstantSearch(searchText)
145+ val heavy = performHeavySearch(searchText)
146+ return mergeResults(instant, heavy, searchText)
93147 }
94148
95149 private fun filterAndSortResults (
0 commit comments