@@ -6,6 +6,7 @@ import com.goide.psi.*
6
6
import com.intellij.openapi.editor.Editor
7
7
import com.intellij.openapi.editor.SelectionModel
8
8
import com.goide.psi.impl.GoPsiUtil
9
+ import com.intellij.openapi.application.runReadAction
9
10
import com.intellij.openapi.command.WriteCommandAction
10
11
import com.intellij.psi.*
11
12
import com.intellij.psi.codeStyle.CodeStyleManager
@@ -21,24 +22,26 @@ class GoLivingDocumentationProvider : LivingDocumentation {
21
22
override fun startEndString (type : LivingDocumentationType ): Pair <String , String > = " /*" to " */"
22
23
23
24
override fun updateDoc (target : PsiElement , newDoc : String , type : LivingDocumentationType , editor : Editor ) {
24
- val project = target.project
25
+ val project = runReadAction { target.project }
25
26
val codeStyleManager = CodeStyleManager .getInstance(project)
26
27
WriteCommandAction .runWriteCommandAction(project, " Living Document" , " cc.unitmesh.livingDoc" , {
28
+ val doc = newDoc + " \n "
27
29
val startOffset = target.textRange.startOffset
28
- val newEndOffset = startOffset + newDoc .length
30
+ val newEndOffset = startOffset + doc .length
29
31
30
32
when (type) {
31
33
LivingDocumentationType .COMMENT -> {
32
-
34
+ editor.document.insertString(startOffset, doc)
35
+ codeStyleManager.reformatText(target.containingFile, startOffset, newEndOffset)
33
36
}
34
37
35
38
LivingDocumentationType .ANNOTATED -> {
36
- editor.document.insertString(startOffset, newDoc )
39
+ editor.document.insertString(startOffset, doc )
37
40
codeStyleManager.reformatText(target.containingFile, startOffset, newEndOffset)
38
41
}
39
42
40
43
LivingDocumentationType .CUSTOM -> {
41
- editor.document.insertString(startOffset, newDoc )
44
+ editor.document.insertString(startOffset, doc )
42
45
codeStyleManager.reformatText(target.containingFile, startOffset, newEndOffset)
43
46
}
44
47
}
0 commit comments