@@ -13,9 +13,7 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
13
13
import com.intellij.openapi.application.ApplicationManager
14
14
import com.intellij.openapi.application.runReadAction
15
15
import com.intellij.openapi.diagnostic.logger
16
- import com.intellij.openapi.progress.ProgressIndicator
17
- import com.intellij.openapi.progress.ProgressManager
18
- import com.intellij.openapi.progress.Task
16
+ import com.intellij.openapi.project.IndexNotReadyException
19
17
import com.intellij.openapi.wm.ToolWindowManager
20
18
import com.intellij.temporary.getElementToAction
21
19
@@ -41,31 +39,29 @@ class CodeCompleteChatAction : AnAction() {
41
39
val suffixText = document?.text?.substring(lineEndOffset) ? : " "
42
40
43
41
val editor = e.getData(CommonDataKeys .EDITOR ) ? : return
44
- ApplicationManager .getApplication().invokeLater {
45
42
46
- // ProgressManager.getInstance()
47
- // .run(object : Task.Backgroundable(project, "Building contextual call graph", true) {
48
- // override fun run(indicator: ProgressIndicator) {
49
- val prompter = ContextPrompter .prompter(file?.language?.displayName ? : " " )
43
+ ApplicationManager .getApplication().runReadAction {
44
+ try {
45
+ val prompter = ContextPrompter .prompter(file?.language?.displayName ? : " " )
50
46
51
- val element = runReadAction { getElementToAction(project, editor) }
52
- prompter.initContext(
53
- ChatActionType .CODE_COMPLETE , prefixText, file, project, caretModel?.offset ? : 0 , element
54
- )
47
+ val element = getElementToAction(project, editor)
48
+ prompter.initContext(
49
+ ChatActionType .CODE_COMPLETE , prefixText, file, project, caretModel?.offset ? : 0 , element
50
+ )
55
51
56
- val actionType = ChatActionType .CODE_COMPLETE
57
- val chatCodingService = ChatCodingService (actionType, project)
58
- val toolWindowManager =
59
- ToolWindowManager .getInstance(project).getToolWindow(AutoDevToolWindowFactory .Util .id) ? : run {
60
- logger<ChatCodingService >().warn(" Tool window not found" )
61
- return @invokeLater
62
- }
52
+ val actionType = ChatActionType .CODE_COMPLETE
53
+ val chatCodingService = ChatCodingService (actionType, project)
54
+ val toolWindowManager =
55
+ ToolWindowManager .getInstance(project).getToolWindow(AutoDevToolWindowFactory .Util .id) ? : run {
56
+ logger<ChatCodingService >().warn(" Tool window not found" )
57
+ return @runReadAction
58
+ }
63
59
64
- val contentManager = toolWindowManager.contentManager
65
- val contentPanel = ChatCodingPanel (chatCodingService, toolWindowManager.disposable)
60
+ val contentManager = toolWindowManager.contentManager
61
+ val contentPanel = ChatCodingPanel (chatCodingService, toolWindowManager.disposable)
66
62
67
- runReadAction {
68
- val content = contentManager.factory.createContent(contentPanel, chatCodingService.getLabel(), false )
63
+ val content =
64
+ contentManager.factory.createContent(contentPanel, chatCodingService.getLabel(), false )
69
65
contentManager.removeAllContents(true )
70
66
contentManager.addContent(content)
71
67
@@ -75,9 +71,9 @@ class CodeCompleteChatAction : AnAction() {
75
71
)
76
72
chatCodingService.handlePromptAndResponse(contentPanel, prompter, chatContext)
77
73
}
74
+ } catch (ignore: IndexNotReadyException ) {
75
+ return @runReadAction
78
76
}
79
- // }
80
- // })
81
77
}
82
78
}
83
79
}
0 commit comments