@@ -10,15 +10,19 @@ import com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider
1010import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder
1111import com.intellij.openapi.module.Module
1212import com.intellij.openapi.project.Project
13- import com.intellij.openapi.roots.ProjectRootManager
1413import com.intellij.openapi.util.IconLoader
15- import com.intellij.psi.*
14+ import com.intellij.psi.PsiAnnotation
15+ import com.intellij.psi.PsiElement
16+ import com.intellij.psi.PsiManager
1617import com.intellij.psi.search.GlobalSearchScope
1718import com.intellij.psi.util.firstLeaf
1819import com.intellij.util.IconUtil
1920import org.slf4j.Logger
2021import org.slf4j.LoggerFactory
2122
23+ /* *
24+ * line marker to navigate from mapping annotation (from interface) to the path in the OpenAPI document.
25+ */
2226class MappingAnnotationLineMarker : RelatedItemLineMarkerProvider () {
2327 private val log: Logger = LoggerFactory .getLogger(javaClass.name)
2428
@@ -41,11 +45,14 @@ class MappingAnnotationLineMarker: RelatedItemLineMarkerProvider() {
4145 }
4246
4347 val apiPath = match.path(element)
44- val module = findModule (element) ? : return null
48+ val modules = findModules (element)
4549
46- val scope = GlobalSearchScope .moduleScope(module)
47- val targets = findPsiElementsOfPath(apiPath!! , scope, element.project)
50+ var searchScope = GlobalSearchScope .EMPTY_SCOPE
51+ for (module in modules) {
52+ searchScope = searchScope.uniteWith(GlobalSearchScope .moduleScope(module))
53+ }
4854
55+ val targets = findPsiElementsOfPath(apiPath!! , searchScope, element.project)
4956 if (targets.isEmpty()) {
5057 log.warn(" found no targets!" )
5158 return null
@@ -62,18 +69,20 @@ class MappingAnnotationLineMarker: RelatedItemLineMarkerProvider() {
6269 return builder.createLineMarkerInfo(id)
6370 }
6471
65- private fun findModule (element : PsiElement ): Module ? {
66- val found = ProjectRootManager .getInstance(element.project)
67- .fileIndex
68- .getModuleForFile(element.containingFile.virtualFile)
72+ private fun findModules (element : PsiElement ): List <Module > {
73+ val finder = ModuleFinder (element.project)
74+ val modules = finder.findModules(element.containingFile.virtualFile.presentableUrl)
6975
70- if (found != null ) {
71- log.debug(" found module '{}' of file '{}'" , found.name, element.containingFile.name)
76+ if (modules.isNotEmpty()) {
77+ modules.forEach {
78+ log.debug(" related modules of file '{}'" , element.containingFile.name)
79+ log.debug(" found module '{}'" , it.name)
80+ }
7281 } else {
7382 log.debug(" could not find module of file '{}'" , element.containingFile.name)
7483 }
7584
76- return found
85+ return modules
7786 }
7887
7988 private fun findPsiElementsOfPath (path : String , searchScope : GlobalSearchScope , project : Project ): List <PsiElement > {
0 commit comments