@@ -52,18 +52,16 @@ class JavaScriptLivingDocumentation : LivingDocumentation {
52
52
? : findDocFallback(target)
53
53
54
54
try {
55
- val createJSDocComment: PsiElement = JSPsiElementFactory .createJSDocComment(newDoc, target)
56
-
57
- if (existingComment != null ) {
58
- existingComment.replace(createJSDocComment)
59
- } else {
60
- val parent = target.parent
61
- parent.addBefore(createJSDocComment, target)
62
- JSChangeUtil .addWs(parent.node, target.node, " \n " )
63
- }
55
+ didInsertComment(newDoc, target, existingComment)
64
56
} catch (e: Exception ) {
65
- editor.document.insertString(startOffset, newDoc)
66
- codeStyleManager.reformatText(target.containingFile, startOffset, newEndOffset)
57
+ // second attempt
58
+ val fromSuggestion = LivingDocumentation .buildDocFromSuggestion(newDoc, " /**" , " */" )
59
+ try {
60
+ didInsertComment(fromSuggestion, target, existingComment)
61
+ } catch (e: Exception ) {
62
+ editor.document.insertString(startOffset, newDoc)
63
+ codeStyleManager.reformatText(target.containingFile, startOffset, newEndOffset)
64
+ }
67
65
}
68
66
}
69
67
@@ -80,6 +78,18 @@ class JavaScriptLivingDocumentation : LivingDocumentation {
80
78
})
81
79
}
82
80
81
+ private fun didInsertComment (newDoc : String , target : PsiElement , existingComment : JSDocComment ? ) {
82
+ val createJSDocComment: PsiElement = JSPsiElementFactory .createJSDocComment(newDoc, target)
83
+
84
+ if (existingComment != null ) {
85
+ existingComment.replace(createJSDocComment)
86
+ } else {
87
+ val parent = target.parent
88
+ parent.addBefore(createJSDocComment, target)
89
+ JSChangeUtil .addWs(parent.node, target.node, " \n " )
90
+ }
91
+ }
92
+
83
93
private fun findDocFallback (documentationTarget : PsiElement ): JSDocComment ? {
84
94
val parentOfDestructuring: PsiElement ? by lazy {
85
95
var context = documentationTarget.context
0 commit comments