@@ -50,18 +50,22 @@ class JavaScriptLivingDocumentation : LivingDocumentation {
50
50
LivingDocumentationType .COMMENT -> {
51
51
val existingComment = JSDocumentationUtils .findOwnDocComment(target)
52
52
? : findDocFallback(target)
53
+ val fromSuggestion = LivingDocumentation .buildDocFromSuggestion(newDoc, " /**" , " */" )
53
54
54
55
try {
55
- didInsertComment(newDoc, target, existingComment)
56
- } catch (e : Exception ) {
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 )
56
+ val createJSDocComment : PsiElement =
57
+ JSPsiElementFactory .createJSDocComment(fromSuggestion, target)
58
+
59
+ if (existingComment != null ) {
60
+ existingComment.replace(createJSDocComment)
61
+ } else {
62
+ val parent = target.parent
63
+ parent.addBefore(createJSDocComment, target )
64
+ JSChangeUtil .addWs(parent.node, target.node, " \n " )
64
65
}
66
+ } catch (e: Exception ) {
67
+ editor.document.insertString(startOffset, newDoc)
68
+ codeStyleManager.reformatText(target.containingFile, startOffset, newEndOffset)
65
69
}
66
70
}
67
71
@@ -78,18 +82,6 @@ class JavaScriptLivingDocumentation : LivingDocumentation {
78
82
})
79
83
}
80
84
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
-
93
85
private fun findDocFallback (documentationTarget : PsiElement ): JSDocComment ? {
94
86
val parentOfDestructuring: PsiElement ? by lazy {
95
87
var context = documentationTarget.context
0 commit comments