Skip to content

Commit 01e7aca

Browse files
committed
fix dao.Xxx completion
1 parent e604634 commit 01e7aca

File tree

1 file changed

+14
-1
lines changed
  • src/main/kotlin/com/github/oldmegit/goframehelper/callUtil/orm

1 file changed

+14
-1
lines changed

src/main/kotlin/com/github/oldmegit/goframehelper/callUtil/orm/OrmUtil.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.oldmegit.goframehelper.callUtil.orm
22

33
import com.github.oldmegit.goframehelper.callUtil.CallUtil
4+
import com.goide.parser.GoParser.ReferenceExpression
45
import com.goide.psi.*
56
import com.goide.psi.impl.GoPsiUtil
67
import com.intellij.psi.PsiComment
@@ -9,6 +10,7 @@ import com.intellij.psi.ResolveState
910
import com.intellij.psi.util.PsiTreeUtil
1011
import com.intellij.util.ObjectUtils
1112

13+
1214
object OrmUtil : CallUtil() {
1315
override fun getData(psiElement: PsiElement): Map<String, Set<PsiElement>> {
1416
return try {
@@ -125,6 +127,7 @@ object OrmUtil : CallUtil() {
125127
// handle type GoAssignmentStatement
126128
// for example:
127129
// db = db.Xxx
130+
// db = dao.Xxx
128131
private fun doAssignmentStatement(assignmentStatement: GoAssignmentStatement): GoStatement? {
129132
for (expression in assignmentStatement.leftHandExprList.expressionList) {
130133
val psiElementRoot = expression.reference?.resolve()
@@ -139,13 +142,23 @@ object OrmUtil : CallUtil() {
139142
// db.Xxx or dao.Xxx
140143
private fun doSimpleStatement(simpleStatement: GoSimpleStatement): GoStatement? {
141144
val declaration = simpleStatement.shortVarDeclaration
145+
142146
// direct return if db := db.Xxx
143147
if (declaration != null) {
144148
return simpleStatement
145149
}
146150

147-
// db.Xxx
151+
// get GoReferenceExpression list
148152
val list = PsiTreeUtil.findChildrenOfType(simpleStatement, GoReferenceExpression::class.java)
153+
for (one in list) {
154+
// dao.Xxx
155+
// if statement contain dao
156+
if (one.text == "dao") {
157+
return simpleStatement
158+
}
159+
}
160+
161+
// db.Xxx
149162
val last = list.last()
150163
if (last.resolve() is GoVarDefinition) {
151164
return getStatementContainDao(last.resolve() as GoVarDefinition)

0 commit comments

Comments
 (0)