Skip to content

Commit

Permalink
fix(typescript): refactor JSDoc comment creation and insertion logic …
Browse files Browse the repository at this point in the history
…to handle null values and exceptions more gracefully.
  • Loading branch information
phodal committed Apr 10, 2024
1 parent dfc3840 commit 30f301e
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ class JavaScriptLivingDocumentation : LivingDocumentation {
val existingComment = JSDocumentationUtils.findOwnDocComment(target)
?: findDocFallback(target)

val createJSDocComment: PsiElement = JSPsiElementFactory.createJSDocComment(newDoc, target)

if (existingComment != null) {
existingComment.replace(createJSDocComment)
} else {
val parent = target.parent
parent.addBefore(createJSDocComment, target)
JSChangeUtil.addWs(parent.node, target.node, "\n")
try {
val createJSDocComment: PsiElement = JSPsiElementFactory.createJSDocComment(newDoc, target)

if (existingComment != null) {
existingComment.replace(createJSDocComment)
} else {
val parent = target.parent
parent.addBefore(createJSDocComment, target)
JSChangeUtil.addWs(parent.node, target.node, "\n")
}
} catch (e: Exception) {
editor.document.insertString(startOffset, newDoc)
codeStyleManager.reformatText(target.containingFile, startOffset, newEndOffset)
}
}

Expand Down

0 comments on commit 30f301e

Please sign in to comment.