@@ -43,7 +43,13 @@ class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConf
43
43
val withRange = elementWithRange(editor, file, project) ? : return
44
44
val selectedText = withRange.first
45
45
val psiElement = withRange.second
46
- val prompt: CustomIntentionPrompt = constructCustomPrompt(psiElement!! , selectedText)
46
+ val beforeCursor = editor.document.text.substring(0 , editor.caretModel.offset)
47
+ val afterCursor = editor.document.text.substring(editor.caretModel.offset)
48
+
49
+ val prompt: CustomIntentionPrompt = constructCustomPrompt(
50
+ psiElement!! , selectedText,
51
+ beforeCursor, afterCursor
52
+ )
47
53
48
54
if (intentionConfig.autoInvoke) {
49
55
sendToChatPanel(project, getActionType(), object : ContextPrompter () {
@@ -62,7 +68,12 @@ class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConf
62
68
}
63
69
}
64
70
65
- private fun constructCustomPrompt (psiElement : PsiElement , selectedText : @NlsSafe String ): CustomIntentionPrompt {
71
+ private fun constructCustomPrompt (
72
+ psiElement : PsiElement ,
73
+ selectedText : @NlsSafe String ,
74
+ beforeCursor : String ,
75
+ afterCursor : String
76
+ ): CustomIntentionPrompt {
66
77
val velocityContext = VelocityContext ()
67
78
68
79
val variableResolvers = arrayOf(
@@ -81,6 +92,11 @@ class CustomActionBaseIntention(private val intentionConfig: CustomIntentionConf
81
92
velocityContext.put(variableType, value)
82
93
}
83
94
95
+ velocityContext.put(" beforeCursor" , beforeCursor)
96
+ velocityContext.put(" afterCursor" , afterCursor)
97
+ val filePath = psiElement.containingFile.virtualFile.path
98
+ velocityContext.put(" filePath" , filePath)
99
+
84
100
val oldContextClassLoader = Thread .currentThread().getContextClassLoader()
85
101
Thread .currentThread().setContextClassLoader(CustomActionBaseIntention ::class .java.getClassLoader())
86
102
0 commit comments