Skip to content

Commit

Permalink
Fixes #68 some reference properties are skipped during the indexing p…
Browse files Browse the repository at this point in the history
…rocess (#71)

* fix: fixes Some reference properties are skipped during the indexing process #68

---------

Signed-off-by: Lorenzo Addazi <[email protected]>
  • Loading branch information
loradd authored Mar 8, 2024
1 parent 24d927e commit ed70462
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 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 @@ -89,10 +90,6 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.util.UUID
import java.util.concurrent.CompletableFuture
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.full.isSubtypeOf
import kotlin.reflect.jvm.javaField
import kotlin.reflect.typeOf
import kotlin.system.exitProcess

open class KolasuServer<T : Node>(protected open val parser: ASTParser<T>?, protected open val language: String = "", protected open val extensions: List<String> = listOf(), protected open val symbolResolver: SymbolResolver? = null, protected open val generator: CodeGenerator<T>? = null) : LanguageServer, TextDocumentService, WorkspaceService, LanguageClientAware {
Expand Down Expand Up @@ -240,18 +237,16 @@ 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)

indexWriter.addDocument(document)
}
commitIndex()
Expand Down

0 comments on commit ed70462

Please sign in to comment.