Skip to content

Commit b222741

Browse files
committed
refactor: use top most call expression
1 parent 870c8eb commit b222741

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

marker/jvm-marker/src/main/kotlin/spp/jetbrains/marker/jvm/service/JVMArtifactScopeService.kt

+19-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import spp.jetbrains.artifact.service.ArtifactTypeService
4343
import spp.jetbrains.artifact.service.define.IArtifactScopeService
4444
import spp.jetbrains.artifact.service.isGroovy
4545
import spp.jetbrains.artifact.service.isKotlin
46+
import spp.jetbrains.artifact.service.toArtifact
4647
import spp.jetbrains.marker.SourceMarkerUtils
4748
import spp.jetbrains.marker.SourceMarkerUtils.doOnReadThread
4849

@@ -108,7 +109,24 @@ class JVMArtifactScopeService : IArtifactScopeService {
108109

109110
override fun getCalls(element: PsiElement): List<PsiElement> {
110111
return when {
111-
ArtifactTypeService.isKotlin(element) -> element.descendantsOfType<KtCallExpression>().toList()
112+
ArtifactTypeService.isKotlin(element) -> {
113+
//use top most call expression (e.g. `bar()` becomes `foo.bar()`)
114+
val callExpressions = element.descendantsOfType<KtCallExpression>().toList()
115+
callExpressions.map {
116+
val selfArtifact = it.toArtifact()
117+
var returnValue: PsiElement = it
118+
while (selfArtifact != null && returnValue.parent != null) {
119+
val parentArtifact = returnValue.parent!!.toArtifact()
120+
if (parentArtifact != null) {
121+
if (parentArtifact::class == selfArtifact::class) {
122+
returnValue = parentArtifact.psiElement
123+
} else break
124+
} else break
125+
}
126+
returnValue
127+
}.toSet().toList()
128+
}
129+
112130
else -> element.descendantsOfType<PsiCallExpression>().toList()
113131
}
114132
}

0 commit comments

Comments
 (0)