Skip to content

Commit b0c8eb3

Browse files
nicolas-guichardantonsviridov-src
authored andcommitted
Fix import as
1 parent cc68fc9 commit b0c8eb3

File tree

2 files changed

+72
-5
lines changed

2 files changed

+72
-5
lines changed

semanticdb-kotlinc/src/main/kotlin/com/sourcegraph/semanticdb_kotlinc/AnalyzerCheckers.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import kotlin.contracts.ExperimentalContracts
55
import org.jetbrains.kotlin.*
66
import org.jetbrains.kotlin.com.intellij.lang.LighterASTNode
77
import org.jetbrains.kotlin.com.intellij.util.diff.FlyweightCapableTreeStructure
8-
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
9-
import org.jetbrains.kotlin.diagnostics.collectDescendantsOfType
10-
import org.jetbrains.kotlin.diagnostics.findChildByType
11-
import org.jetbrains.kotlin.diagnostics.findLastDescendant
8+
import org.jetbrains.kotlin.diagnostics.*
129
import org.jetbrains.kotlin.fir.FirSession
1310
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
1411
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
@@ -141,7 +138,7 @@ open class AnalyzerCheckers(session: FirSession) : FirAdditionalCheckersExtensio
141138
val source = import.source ?: return@forEach
142139
val fqName = import.importedFqName ?: return@forEach
143140

144-
val names = source.treeStructure.findLastDescendant(source.lighterASTNode) { true }
141+
val names = source.treeStructure.findDescendantByType(source.lighterASTNode, KtNodeTypes.DOT_QUALIFIED_EXPRESSION)
145142
if (names != null) {
146143
eachFqNameElement(fqName, source.treeStructure, names) { fqName, name ->
147144
val symbolProvider = context.session.symbolProvider

semanticdb-kotlinc/src/test/kotlin/com/sourcegraph/semanticdb_kotlinc/test/AnalyzerTest.kt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,76 @@ class AnalyzerTest {
122122
assertSoftly(document.symbolsList) { withClue(this) { symbols.forEach(::shouldContain) } }
123123
}
124124

125+
@Test
126+
fun imports(@TempDir path: Path) {
127+
val document =
128+
compileSemanticdb(
129+
path,
130+
"""
131+
package sample
132+
133+
import kotlin.Boolean
134+
import kotlin.Int as KInt
135+
""")
136+
137+
val occurrences =
138+
arrayOf(
139+
SymbolOccurrence {
140+
role = Role.REFERENCE
141+
symbol = "sample/"
142+
range {
143+
startLine = 0
144+
startCharacter = 8
145+
endLine = 0
146+
endCharacter = 14
147+
}
148+
},
149+
SymbolOccurrence {
150+
role = Role.REFERENCE
151+
symbol = "kotlin/"
152+
range {
153+
startLine = 2
154+
startCharacter = 7
155+
endLine = 2
156+
endCharacter = 13
157+
}
158+
},
159+
SymbolOccurrence {
160+
role = Role.REFERENCE
161+
symbol = "kotlin/Boolean#"
162+
range {
163+
startLine = 2
164+
startCharacter = 14
165+
endLine = 2
166+
endCharacter = 21
167+
}
168+
},
169+
SymbolOccurrence {
170+
role = Role.REFERENCE
171+
symbol = "kotlin/"
172+
range {
173+
startLine = 3
174+
startCharacter = 7
175+
endLine = 3
176+
endCharacter = 13
177+
}
178+
},
179+
SymbolOccurrence {
180+
role = Role.REFERENCE
181+
symbol = "kotlin/Int#"
182+
range {
183+
startLine = 3
184+
startCharacter = 14
185+
endLine = 3
186+
endCharacter = 17
187+
}
188+
},
189+
)
190+
assertSoftly(document.occurrencesList) {
191+
withClue(this) { occurrences.forEach(::shouldContain) }
192+
}
193+
}
194+
125195
@Test
126196
fun overrides(@TempDir path: Path) {
127197
val document =

0 commit comments

Comments
 (0)