mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-16 19:44:36 +00:00
refactor: remove MCP group conditional rendering logic
This commit is contained in:
parent
38ed8c9bb5
commit
ea5827e48e
2 changed files with 29 additions and 41 deletions
|
|
@ -53,7 +53,7 @@ class SearchManager(
|
|||
FilesGroupItem(project, tagManager, fileSearchProvider),
|
||||
foldersGroupItem,
|
||||
if (GitFeatureAvailability.isAvailable) GitGroupItem(project) else null,
|
||||
MCPGroupItem(tagManager, FeatureType.AGENT),
|
||||
MCPGroupItem(tagManager),
|
||||
DiagnosticsGroupItem(tagManager),
|
||||
ImageActionItem(project, tagManager)
|
||||
).filter { it.enabled }
|
||||
|
|
@ -64,7 +64,7 @@ class SearchManager(
|
|||
if (GitFeatureAvailability.isAvailable) GitGroupItem(project) else null,
|
||||
HistoryGroupItem(),
|
||||
PersonasGroupItem(tagManager),
|
||||
MCPGroupItem(tagManager, featureType ?: FeatureType.CHAT),
|
||||
MCPGroupItem(tagManager),
|
||||
DiagnosticsGroupItem(tagManager),
|
||||
WebActionItem(tagManager),
|
||||
ImageActionItem(project, tagManager)
|
||||
|
|
@ -118,9 +118,12 @@ class SearchManager(
|
|||
|
||||
return try {
|
||||
fileGroup.getLookupItems(searchText)
|
||||
.filterIsInstance<LookupActionItem>()
|
||||
.filter { result ->
|
||||
result !is IncludeOpenFilesActionItem || matchesSearchText(result, searchText, matcher)
|
||||
result !is IncludeOpenFilesActionItem || matchesSearchText(
|
||||
result,
|
||||
searchText,
|
||||
matcher
|
||||
)
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
|
|
@ -130,27 +133,31 @@ class SearchManager(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun performDeferredHeavySearch(searchText: String): List<LookupActionItem> = coroutineScope {
|
||||
val deferredGroups = getDefaultGroups()
|
||||
.filter { it is FoldersGroupItem || it is GitGroupItem }
|
||||
suspend fun performDeferredHeavySearch(searchText: String): List<LookupActionItem> =
|
||||
coroutineScope {
|
||||
val deferredGroups = getDefaultGroups()
|
||||
.filter { it is FoldersGroupItem || it is GitGroupItem }
|
||||
|
||||
deferredGroups.map { group ->
|
||||
async {
|
||||
try {
|
||||
if (group is LookupGroupItem) {
|
||||
group.getLookupItems(searchText).filterIsInstance<LookupActionItem>()
|
||||
} else {
|
||||
deferredGroups.map { group ->
|
||||
async {
|
||||
try {
|
||||
if (group is LookupGroupItem) {
|
||||
group.getLookupItems(searchText).filterIsInstance<LookupActionItem>()
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
logger.error(
|
||||
"Error getting deferred results from ${group::class.simpleName}",
|
||||
e
|
||||
)
|
||||
emptyList()
|
||||
}
|
||||
} catch (e: CancellationException) {
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
logger.error("Error getting deferred results from ${group::class.simpleName}", e)
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
}.flatMap { it.await() }
|
||||
}
|
||||
}.flatMap { it.await() }
|
||||
}
|
||||
|
||||
fun mergeResults(
|
||||
primaryResults: List<LookupActionItem>,
|
||||
|
|
@ -228,6 +235,7 @@ class SearchManager(
|
|||
return when (result) {
|
||||
is ee.carlrobert.codegpt.ui.textarea.lookup.action.files.FileActionItem ->
|
||||
"file:${result.file.path}"
|
||||
|
||||
is ee.carlrobert.codegpt.ui.textarea.lookup.action.FolderActionItem ->
|
||||
"folder:${result.folder.path}"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,9 @@
|
|||
package ee.carlrobert.codegpt.ui.textarea.lookup.group
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import com.intellij.openapi.components.service
|
||||
import ee.carlrobert.codegpt.CodeGPTBundle
|
||||
import ee.carlrobert.codegpt.Icons
|
||||
import ee.carlrobert.codegpt.settings.mcp.McpSettings
|
||||
import ee.carlrobert.codegpt.settings.service.FeatureType
|
||||
import ee.carlrobert.codegpt.settings.models.ModelSettings
|
||||
import ee.carlrobert.codegpt.settings.service.ServiceType.CUSTOM_OPENAI
|
||||
import ee.carlrobert.codegpt.settings.service.ServiceType.OPENAI
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.McpTagDetails
|
||||
import ee.carlrobert.codegpt.ui.textarea.header.tag.TagManager
|
||||
import ee.carlrobert.codegpt.ui.textarea.lookup.LookupActionItem
|
||||
|
|
@ -19,24 +13,10 @@ import javax.swing.Icon
|
|||
|
||||
class MCPGroupItem(
|
||||
private val tagManager: TagManager,
|
||||
private val featureType: FeatureType = FeatureType.CHAT
|
||||
) : AbstractLookupGroupItem() {
|
||||
|
||||
override val displayName: String = CodeGPTBundle.get("suggestionGroupItem.mcp.displayName")
|
||||
override val icon: Icon = Icons.MCP
|
||||
override val enabled: Boolean = isEnabled()
|
||||
|
||||
fun isEnabled(): Boolean {
|
||||
if (featureType == FeatureType.AGENT) {
|
||||
return true
|
||||
}
|
||||
val serviceType = service<ModelSettings>().getServiceForFeature(featureType)
|
||||
return serviceType == OPENAI || serviceType == CUSTOM_OPENAI
|
||||
}
|
||||
|
||||
override fun setPresentation(element: LookupElement, presentation: LookupElementPresentation) {
|
||||
super.setPresentation(element, presentation)
|
||||
}
|
||||
|
||||
override suspend fun getLookupItems(searchText: String): List<LookupActionItem> {
|
||||
val mcpSettings = service<McpSettings>()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue