@@ -3,21 +3,32 @@ package cc.unitmesh.endpoints.provider
3
3
import cc.unitmesh.devti.provider.context.ChatContextItem
4
4
import cc.unitmesh.devti.provider.context.ChatContextProvider
5
5
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
7
8
import com.intellij.openapi.project.Project
8
9
9
10
class EndpointsContextProvider : ChatContextProvider {
10
11
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()
13
13
}
14
14
15
15
override suspend fun collect (
16
16
project : Project ,
17
17
creationContext : ChatCreationContext
18
18
): 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
+ }
21
32
22
33
return emptyList()
23
34
}
0 commit comments