Skip to content

Commit 7c60472

Browse files
committed
feat(endpoints): update provider to use new API and filter available providers #287
1 parent e275a30 commit 7c60472

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

exts/ext-endpoints/src/main/kotlin/cc/unitmesh/endpoints/provider/EndpointsContextProvider.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,32 @@ package cc.unitmesh.endpoints.provider
33
import cc.unitmesh.devti.provider.context.ChatContextItem
44
import cc.unitmesh.devti.provider.context.ChatContextProvider
55
import cc.unitmesh.devti.provider.context.ChatCreationContext
6-
import com.intellij.microservices.endpoints.EndpointsProjectModel
6+
import com.intellij.microservices.endpoints.EndpointsProvider
7+
import com.intellij.openapi.application.runReadAction
78
import com.intellij.openapi.project.Project
89

910
class EndpointsContextProvider : ChatContextProvider {
1011
override fun isApplicable(project: Project, creationContext: ChatCreationContext): Boolean {
11-
// todo: update to new api
12-
return EndpointsProjectModel.EP_NAME.extensionList.isNotEmpty()
12+
return runReadAction { EndpointsProvider.getAvailableProviders(project).toList() }.isNotEmpty()
1313
}
1414

1515
override suspend fun collect(
1616
project: Project,
1717
creationContext: ChatCreationContext
1818
): List<ChatContextItem> {
19-
val model = EndpointsProjectModel.EP_NAME.extensionList.firstOrNull()
20-
if (model == null) return emptyList()
19+
val model = runReadAction { EndpointsProvider.getAvailableProviders(project).toList() }
20+
if (model.isEmpty()) return emptyList()
21+
22+
val availableProviders = model.filter { it.getStatus(project) == EndpointsProvider.Status.HAS_ENDPOINTS }
23+
24+
if (availableProviders.isNotEmpty()) {
25+
val infos = availableProviders.mapNotNull {
26+
val text = "This project has endpoints from ${it.javaClass.simpleName}"
27+
return@mapNotNull ChatContextItem(EndpointsContextProvider::class, text)
28+
}.toList()
29+
30+
return infos
31+
}
2132

2233
return emptyList()
2334
}

0 commit comments

Comments
 (0)