Skip to content

Commit 9bda9e7

Browse files
committed
feat(completion): add timeout for toolchain command completion
Replace blocking call with CompletableFuture to add 10s timeout for toolchain command completion, preventing UI freezes during long operations.
1 parent 77def35 commit 9bda9e7

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/provider/ToolchainCommandCompletion.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,30 @@ import com.intellij.codeInsight.lookup.LookupElement
88
import com.intellij.codeInsight.lookup.LookupElementBuilder
99
import com.intellij.util.ProcessingContext
1010
import kotlinx.coroutines.runBlocking
11+
import java.util.concurrent.CompletableFuture
12+
import java.util.concurrent.TimeUnit
13+
import java.util.concurrent.TimeoutException
1114

1215
class ToolchainCommandCompletion : CompletionProvider<CompletionParameters>() {
1316
override fun addCompletions(
1417
parameters: CompletionParameters,
1518
context: ProcessingContext,
1619
result: CompletionResultSet,
1720
) {
18-
runBlocking {
19-
BuiltinCommand.allToolchains(parameters.originalFile.project).forEach {
20-
val lookupElement = createCommandCompletionCandidate(it)
21-
result.addElement(lookupElement)
22-
}
21+
try {
22+
CompletableFuture.supplyAsync {
23+
runBlocking {
24+
BuiltinCommand.allToolchains(parameters.originalFile.project).forEach {
25+
val lookupElement = createCommandCompletionCandidate(it)
26+
result.addElement(lookupElement)
27+
}
28+
}
29+
null
30+
}.get(10, TimeUnit.SECONDS)
31+
} catch (e: TimeoutException) {
32+
// Handle timeout exception
33+
} catch (e: Exception) {
34+
// Handle other exceptions
2335
}
2436
}
2537

0 commit comments

Comments
 (0)