Skip to content

Commit a628ae6

Browse files
committed
add @param for closure
1 parent 5535bda commit a628ae6

File tree

1 file changed

+7
-7
lines changed
  • src/main/java/com/tang/intellij/lua/codeInsight/intention

1 file changed

+7
-7
lines changed

src/main/java/com/tang/intellij/lua/codeInsight/intention/Intentions.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CreateParameterAnnotationIntention : BaseIntentionAction() {
4141
override fun isAvailable(project: Project, editor: Editor, psiFile: PsiFile): Boolean {
4242
val offset = editor.caretModel.offset
4343
val name = findParamName(psiFile, offset) ?: findParamName(psiFile, offset - 1)
44-
return name != null && name.funcBodyOwner !is LuaClosureExpr
44+
return name != null //&& name.funcBodyOwner !is LuaClosureExpr
4545
}
4646

4747
private fun findParamName(psiFile: PsiFile, offset:Int): LuaParamNameDef? {
@@ -62,13 +62,14 @@ class CreateParameterAnnotationIntention : BaseIntentionAction() {
6262
val parDef = findParamName(psiFile, offset) ?: findParamName(psiFile, offset - 1)
6363
parDef ?: return
6464

65-
val parametersOwner = parDef.owner
66-
if (parametersOwner is LuaCommentOwner) {
67-
val comment = parametersOwner.comment
65+
val owner = PsiTreeUtil.getParentOfType(parDef, LuaCommentOwner::class.java)
66+
if (owner != null) {
67+
val comment = owner.comment
6868

6969
val templateManager = TemplateManager.getInstance(project)
7070
val template = templateManager.createTemplate("", "")
71-
if (comment != null) template.addTextSegment("\n")
71+
if (comment != null)
72+
template.addTextSegment("\n")
7273
template.addTextSegment(String.format("---@param %s ", parDef.name))
7374
val name = MacroCallNode(SuggestTypeMacro())
7475
template.addVariable("type", name, TextExpression("table"), true)
@@ -77,8 +78,7 @@ class CreateParameterAnnotationIntention : BaseIntentionAction() {
7778
if (comment != null) {
7879
editor.caretModel.moveToOffset(comment.textOffset + comment.textLength)
7980
} else {
80-
val commentOwner:LuaCommentOwner = parametersOwner
81-
editor.caretModel.moveToOffset(commentOwner.node.startOffset)
81+
editor.caretModel.moveToOffset(owner.node.startOffset)
8282
template.addTextSegment("\n")
8383
}
8484

0 commit comments

Comments
 (0)