Skip to content

Commit

Permalink
fix: fixes Some reference properties are skipped during the indexing …
Browse files Browse the repository at this point in the history
…process #68

Signed-off-by: Lorenzo Addazi <[email protected]>
  • Loading branch information
loradd committed Mar 7, 2024
1 parent 24d927e commit f0def9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {

dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.21")
implementation("com.strumenta.kolasu:kolasu-core:1.5.31")
implementation("com.strumenta.kolasu:kolasu-core:1.5.45")
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j:0.21.1")
implementation("org.apache.lucene:lucene-core:9.8.0")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.strumenta.kolasu.model.Point
import com.strumenta.kolasu.model.PossiblyNamed
import com.strumenta.kolasu.model.ReferenceByName
import com.strumenta.kolasu.model.children
import com.strumenta.kolasu.model.kReferenceByNameProperties
import com.strumenta.kolasu.parsing.ASTParser
import com.strumenta.kolasu.parsing.ParsingResult
import com.strumenta.kolasu.traversing.findByPosition
Expand Down Expand Up @@ -240,15 +241,23 @@ open class KolasuServer<T : Node>(protected open val parser: ASTParser<T>?, prot

if (node is PossiblyNamed && node.name != null) {
document.add(StringField("name", node.name, Field.Store.YES))
} else {
val referenceField = node::class.declaredMemberProperties.find { it.returnType.isSubtypeOf(typeOf<ReferenceByName<*>>()) }
referenceField?.javaField?.let { field ->
field.isAccessible = true
val value = field.get(node) as ReferenceByName<*>

if (value.referred is Node && uuid[value.referred as Node] != null) {
document.add(StringField("reference", uuid[value.referred as Node], Field.Store.YES))
}
}

// handle reference by name properties
node.kReferenceByNameProperties()
.mapNotNull { it.get(node) as? ReferenceByName<*> }
.mapNotNull { it.referred as? Node }
.mapNotNull { uuid[it] }
.map { StringField("reference", it, Field.Store.YES) }
.forEach(document::add)

val referenceField = node::class.declaredMemberProperties.find { it.returnType.isSubtypeOf(typeOf<ReferenceByName<*>>()) }
referenceField?.javaField?.let { field ->
field.isAccessible = true
val value = field.get(node) as ReferenceByName<*>

if (value.referred is Node && uuid[value.referred as Node] != null) {
document.add(StringField("reference", uuid[value.referred as Node], Field.Store.YES))
}
}

Expand Down

0 comments on commit f0def9e

Please sign in to comment.