Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a53c9e1

Browse files
committedOct 17, 2024·
fix: fix definition resolution for cross-file references
1 parent 94f6cb7 commit a53c9e1

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed
 

‎src/main/kotlin/com/mclaughlinconnor/ij_inspector/application/DefinitionService.kt

+25-10
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ package com.mclaughlinconnor.ij_inspector.application
22

33
import com.intellij.openapi.application.Application
44
import com.intellij.openapi.application.ApplicationManager
5-
import com.intellij.openapi.editor.Document
65
import com.intellij.openapi.project.Project
7-
import com.intellij.psi.PsiDocumentManager
8-
import com.intellij.psi.PsiElement
9-
import com.intellij.psi.PsiNameIdentifierOwner
10-
import com.intellij.psi.PsiReference
6+
import com.intellij.openapi.vfs.findDocument
7+
import com.intellij.psi.*
118
import com.intellij.refactoring.suggested.endOffset
129
import com.intellij.refactoring.suggested.startOffset
1310
import com.mclaughlinconnor.ij_inspector.application.Utils.Companion.createDocument
1411
import com.mclaughlinconnor.ij_inspector.application.lsp.*
1512

13+
1614
class DefinitionService(private val myProject: Project) {
1715
private val connection: Connection = Connection.getInstance()
1816
private val messageFactory: MessageFactory = MessageFactory()
@@ -37,16 +35,33 @@ class DefinitionService(private val myProject: Project) {
3735
return@invokeLater
3836
}
3937

40-
val resolved = element.resolve() ?: return@invokeLater
41-
val location = resolvedToLocation(resolved, document)
42-
43-
val response = Response(requestId, location)
38+
val locations: MutableList<Location> = mutableListOf()
39+
40+
val references = element.references
41+
for (ref in references) {
42+
if (ref is PsiPolyVariantReference) {
43+
val resolved = ref.multiResolve(true)
44+
for (r in resolved) {
45+
if (r.element != null) {
46+
locations.add(resolvedToLocation(r.element!!))
47+
}
48+
}
49+
continue
50+
}
51+
52+
val resolved = ref.resolve()
53+
if (resolved != null) {
54+
locations.add(resolvedToLocation(resolved))
55+
}
56+
}
4457

58+
val response = Response(requestId, locations)
4559
connection.write(messageFactory.newMessage(response))
4660
}
4761
}
4862

49-
private fun resolvedToLocation(resolved: PsiElement, document: Document): Location {
63+
private fun resolvedToLocation(resolved: PsiElement): Location {
64+
val document = resolved.containingFile.virtualFile.findDocument()!!
5065
val target = getNameIdentifier(resolved)
5166

5267
val startOffset = target.startOffset

0 commit comments

Comments
 (0)
Please sign in to comment.