Skip to content

Commit a5ac1fa

Browse files
committed
Replace role: Int with isDefinition: Boolean in Kotlin visitor
1 parent 1d39c94 commit a5ac1fa

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class SemanticdbTextDocumentBuilder(
4646
firBasedSymbol: FirBasedSymbol<*>?,
4747
symbol: Symbol,
4848
element: KtSourceElement,
49-
role: Int,
49+
isDefinition: Boolean,
5050
context: CheckerContext,
5151
enclosingSource: KtSourceElement? = null,
5252
) {
53-
documentBuilder.addOccurrence(occurrence(symbol, element, role, enclosingSource))
54-
if (role == SymbolRole.Definition_VALUE) {
53+
documentBuilder.addOccurrence(occurrence(symbol, element, isDefinition, enclosingSource))
54+
if (isDefinition) {
5555
documentBuilder.addSymbol(symbolInformation(firBasedSymbol, symbol, element, context))
5656
}
5757
}
@@ -101,11 +101,11 @@ class SemanticdbTextDocumentBuilder(
101101
private fun occurrence(
102102
symbol: Symbol,
103103
element: KtSourceElement,
104-
role: Int,
104+
isDefinition: Boolean,
105105
enclosingSource: KtSourceElement?,
106106
): Occurrence = occurrence {
107107
this.symbol = symbol.toString()
108-
symbolRoles = role
108+
if (isDefinition) symbolRoles = SymbolRole.Definition.number
109109
range += range(element).asIterable()
110110
if (enclosingSource != null) {
111111
enclosingRange += enclosingRange(enclosingSource).asIterable()

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
1212
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
1313
import org.jetbrains.kotlin.name.FqName
1414
import org.scip_code.scip.Document
15-
import org.scip_code.scip.SymbolRole
1615

1716
/**
1817
* Per-file accumulator of SCIP occurrences and symbols. The FIR checkers in
@@ -39,12 +38,12 @@ class SemanticdbVisitor(
3938

4039
private fun Sequence<SymbolDescriptorPair>?.emitAll(
4140
element: KtSourceElement,
42-
role: Int,
41+
isDefinition: Boolean,
4342
context: CheckerContext,
4443
enclosingSource: KtSourceElement? = null,
4544
): List<Symbol>? =
4645
this?.onEach { (firBasedSymbol, symbol) ->
47-
documentBuilder.emitSemanticdbData(firBasedSymbol, symbol, element, role, context, enclosingSource)
46+
documentBuilder.emitSemanticdbData(firBasedSymbol, symbol, element, isDefinition, context, enclosingSource)
4847
}
4948
?.map { it.symbol }
5049
?.toList()
@@ -53,55 +52,55 @@ class SemanticdbVisitor(
5352
this.map { SymbolDescriptorPair(firBasedSymbol, it) }
5453

5554
fun visitPackage(pkg: FqName, element: KtSourceElement, context: CheckerContext) {
56-
cache[pkg].with(null).emitAll(element, SymbolRole.UnspecifiedSymbolRole_VALUE, context)
55+
cache[pkg].with(null).emitAll(element, isDefinition = false, context)
5756
}
5857

5958
fun visitClassReference(firClassSymbol: FirClassLikeSymbol<*>, element: KtSourceElement, context: CheckerContext) {
60-
cache[firClassSymbol].with(firClassSymbol).emitAll(element, SymbolRole.UnspecifiedSymbolRole_VALUE, context)
59+
cache[firClassSymbol].with(firClassSymbol).emitAll(element, isDefinition = false, context)
6160
}
6261

6362
fun visitCallableReference(firClassSymbol: FirCallableSymbol<*>, element: KtSourceElement, context: CheckerContext) {
64-
cache[firClassSymbol].with(firClassSymbol).emitAll(element, SymbolRole.UnspecifiedSymbolRole_VALUE, context)
63+
cache[firClassSymbol].with(firClassSymbol).emitAll(element, isDefinition = false, context)
6564
}
6665

6766
fun visitClassOrObject(firClass: FirClassLikeDeclaration, element: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
68-
cache[firClass.symbol].with(firClass.symbol).emitAll(element, SymbolRole.Definition_VALUE, context, enclosingSource)
67+
cache[firClass.symbol].with(firClass.symbol).emitAll(element, isDefinition = true, context, enclosingSource)
6968
}
7069

7170
fun visitPrimaryConstructor(firConstructor: FirConstructor, source: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
72-
cache[firConstructor.symbol].with(firConstructor.symbol).emitAll(source, SymbolRole.Definition_VALUE, context, enclosingSource)
71+
cache[firConstructor.symbol].with(firConstructor.symbol).emitAll(source, isDefinition = true, context, enclosingSource)
7372
}
7473

7574
fun visitSecondaryConstructor(firConstructor: FirConstructor, source: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
76-
cache[firConstructor.symbol].with(firConstructor.symbol).emitAll(source, SymbolRole.Definition_VALUE, context, enclosingSource)
75+
cache[firConstructor.symbol].with(firConstructor.symbol).emitAll(source, isDefinition = true, context, enclosingSource)
7776
}
7877

7978
fun visitNamedFunction(firFunction: FirFunction, source: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
80-
cache[firFunction.symbol].with(firFunction.symbol).emitAll(source, SymbolRole.Definition_VALUE, context, enclosingSource)
79+
cache[firFunction.symbol].with(firFunction.symbol).emitAll(source, isDefinition = true, context, enclosingSource)
8180
}
8281

8382
fun visitProperty(firProperty: FirProperty, source: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
84-
cache[firProperty.symbol].with(firProperty.symbol).emitAll(source, SymbolRole.Definition_VALUE, context, enclosingSource)
83+
cache[firProperty.symbol].with(firProperty.symbol).emitAll(source, isDefinition = true, context, enclosingSource)
8584
}
8685

8786
fun visitParameter(firParameter: FirValueParameter, source: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
88-
cache[firParameter.symbol].with(firParameter.symbol).emitAll(source, SymbolRole.Definition_VALUE, context, enclosingSource)
87+
cache[firParameter.symbol].with(firParameter.symbol).emitAll(source, isDefinition = true, context, enclosingSource)
8988
}
9089

9190
fun visitTypeParameter(firTypeParameter: FirTypeParameter, source: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
9291
cache[firTypeParameter.symbol]
9392
.with(firTypeParameter.symbol)
94-
.emitAll(source, SymbolRole.Definition_VALUE, context, enclosingSource)
93+
.emitAll(source, isDefinition = true, context, enclosingSource)
9594
}
9695

9796
fun visitTypeAlias(firTypeAlias: FirTypeAlias, source: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
98-
cache[firTypeAlias.symbol].with(firTypeAlias.symbol).emitAll(source, SymbolRole.Definition_VALUE, context, enclosingSource)
97+
cache[firTypeAlias.symbol].with(firTypeAlias.symbol).emitAll(source, isDefinition = true, context, enclosingSource)
9998
}
10099

101100
fun visitPropertyAccessor(firPropertyAccessor: FirPropertyAccessor, source: KtSourceElement, context: CheckerContext, enclosingSource: KtSourceElement? = null) {
102101
cache[firPropertyAccessor.symbol]
103102
.with(firPropertyAccessor.symbol)
104-
.emitAll(source, SymbolRole.Definition_VALUE, context, enclosingSource)
103+
.emitAll(source, isDefinition = true, context, enclosingSource)
105104
}
106105

107106
fun visitSimpleNameExpression(
@@ -110,6 +109,6 @@ class SemanticdbVisitor(
110109
) {
111110
cache[firResolvedNamedReference.resolvedSymbol]
112111
.with(firResolvedNamedReference.resolvedSymbol)
113-
.emitAll(source, SymbolRole.UnspecifiedSymbolRole_VALUE, context)
112+
.emitAll(source, isDefinition = false, context)
114113
}
115114
}

0 commit comments

Comments
 (0)