Skip to content

Commit 30f301e

Browse files
committed
fix(typescript): refactor JSDoc comment creation and insertion logic to handle null values and exceptions more gracefully.
1 parent dfc3840 commit 30f301e

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/provider/JavaScriptLivingDocumentation.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@ class JavaScriptLivingDocumentation : LivingDocumentation {
5151
val existingComment = JSDocumentationUtils.findOwnDocComment(target)
5252
?: findDocFallback(target)
5353

54-
val createJSDocComment: PsiElement = JSPsiElementFactory.createJSDocComment(newDoc, target)
55-
56-
if (existingComment != null) {
57-
existingComment.replace(createJSDocComment)
58-
} else {
59-
val parent = target.parent
60-
parent.addBefore(createJSDocComment, target)
61-
JSChangeUtil.addWs(parent.node, target.node, "\n")
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+
}
64+
} catch (e: Exception) {
65+
editor.document.insertString(startOffset, newDoc)
66+
codeStyleManager.reformatText(target.containingFile, startOffset, newEndOffset)
6267
}
6368
}
6469

0 commit comments

Comments
 (0)