generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts): init basic doc writing listener
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
webstorm/src/main/kotlin/cc/unitmesh/ide/webstorm/provider/JavaScriptLivingDocumentation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package cc.unitmesh.ide.webstorm.provider | ||
|
||
import cc.unitmesh.devti.custom.document.LivingDocumentationType | ||
import cc.unitmesh.devti.provider.LivingDocumentation | ||
import com.intellij.codeInsight.daemon.impl.CollectHighlightsUtil | ||
import com.intellij.lang.javascript.psi.JSFunction | ||
import com.intellij.lang.javascript.psi.ecmal4.JSClass | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.editor.SelectionModel | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiNameIdentifierOwner | ||
import com.intellij.psi.util.PsiTreeUtil | ||
|
||
class JavaScriptLivingDocumentation : LivingDocumentation { | ||
override val forbiddenRules: List<String> = listOf( | ||
"do not return example code", | ||
"do not use @author and @version tags" | ||
) | ||
|
||
override fun startEndString(type: LivingDocumentationType): Pair<String, String> { | ||
return when (type) { | ||
LivingDocumentationType.COMMENT -> Pair("/**", "*/") | ||
LivingDocumentationType.ANNOTATED -> Pair("", "") | ||
LivingDocumentationType.CUSTOM -> Pair("", "") | ||
} | ||
} | ||
|
||
override fun updateDoc(target: PsiElement, newDoc: String, type: LivingDocumentationType, editor: Editor) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun findNearestDocumentationTarget(psiElement: PsiElement): PsiNameIdentifierOwner? { | ||
if (psiElement is JSFunction || psiElement is JSClass) return psiElement as PsiNameIdentifierOwner | ||
|
||
val closestIdentifierOwner = PsiTreeUtil.getParentOfType(psiElement, PsiNameIdentifierOwner::class.java) | ||
if (closestIdentifierOwner !is JSFunction) { | ||
return PsiTreeUtil.getParentOfType(psiElement, JSFunction::class.java) ?: closestIdentifierOwner | ||
} | ||
|
||
return closestIdentifierOwner | ||
} | ||
|
||
override fun findDocTargetsInSelection( | ||
root: PsiElement, | ||
selectionModel: SelectionModel | ||
): List<PsiNameIdentifierOwner> { | ||
val findCommonParent = CollectHighlightsUtil.findCommonParent( | ||
root, | ||
selectionModel.selectionStart, | ||
selectionModel.selectionEnd | ||
) ?: return emptyList() | ||
|
||
return emptyList() | ||
} | ||
|
||
private fun containsElement(selectionModel: SelectionModel, element: PsiElement): Boolean { | ||
return selectionModel.selectionStart <= element.textRange.startOffset && element.textRange.endOffset <= selectionModel.selectionEnd | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters