Skip to content

Commit cd4a20e

Browse files
committed
add safe checks of workspace process status before making calls
1 parent 19931e5 commit cd4a20e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextController.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class ProjectContextController(private val project: Project, private val cs: Cor
5252
fun getProjectContextIndexComplete() = projectContextProvider.isIndexComplete.get()
5353

5454
suspend fun queryChat(prompt: String, timeout: Long?): List<RelevantDocument> {
55+
if (!getProjectContextIndexComplete()) {
56+
logger.warn { "attempt to query project context while index for ${project.name} isn't ready" }
57+
return emptyList()
58+
}
5559
try {
5660
return projectContextProvider.query(prompt, timeout)
5761
} catch (e: Exception) {
@@ -60,8 +64,13 @@ class ProjectContextController(private val project: Project, private val cs: Cor
6064
}
6165
}
6266

63-
suspend fun queryInline(query: String, filePath: String): List<InlineBm25Chunk> =
64-
try {
67+
suspend fun queryInline(query: String, filePath: String): List<InlineBm25Chunk> {
68+
if (!getProjectContextIndexComplete()) {
69+
logger.warn { "attempt to query project context while index for ${project.name} isn't ready" }
70+
return emptyList()
71+
}
72+
73+
return try {
6574
projectContextProvider.queryInline(query, filePath, InlineContextTarget.CODEMAP)
6675
} catch (e: Exception) {
6776
var logStr = "error while querying inline for project context $e.message"
@@ -71,9 +80,14 @@ class ProjectContextController(private val project: Project, private val cs: Cor
7180
logger.warn { logStr }
7281
emptyList()
7382
}
83+
}
7484

7585
@RequiresBackgroundThread
7686
fun updateIndex(filePaths: List<String>, mode: IndexUpdateMode) {
87+
if (!getProjectContextIndexComplete()) {
88+
return
89+
}
90+
7791
try {
7892
return projectContextProvider.updateIndex(filePaths, mode)
7993
} catch (e: Exception) {

0 commit comments

Comments
 (0)