From 37b6c425d22383900031d202b781dfd76acfe8fe Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 1 Jan 2024 00:02:39 +0800 Subject: [PATCH] feat(rust): add lookup type support --- .../kotlin/chapi/ast/rustast/RustAstBaseListener.kt | 10 ++++++++-- .../chapi/ast/rustast/RustFullIdentListenerTest.kt | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt b/chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt index a66bd361..4d94cbda 100644 --- a/chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt +++ b/chapi-ast-rust/src/main/kotlin/chapi/ast/rustast/RustAstBaseListener.kt @@ -82,7 +82,8 @@ open class RustAstBaseListener(private val fileName: String) : RustParserBaseLis CodeImport( Source = path.joinToString("::"), UsageName = path, - Scope = "" + Scope = if (path.first() == "crate") "crate" else "cargo", + AsName = path.last() ) ) } @@ -154,7 +155,12 @@ open class RustAstBaseListener(private val fileName: String) : RustParserBaseLis } private fun lookupType(type_: Type_Context?): String { - return type_?.text ?: "" + val typeText = type_?.text + imports.filter { it.AsName == typeText }.forEach { + return it.Source + } + + return typeText ?: "" } private fun buildAttribute(outerAttribute: List): MutableList { diff --git a/chapi-ast-rust/src/test/kotlin/chapi/ast/rustast/RustFullIdentListenerTest.kt b/chapi-ast-rust/src/test/kotlin/chapi/ast/rustast/RustFullIdentListenerTest.kt index 4f5f3db7..ca6eace6 100644 --- a/chapi-ast-rust/src/test/kotlin/chapi/ast/rustast/RustFullIdentListenerTest.kt +++ b/chapi-ast-rust/src/test/kotlin/chapi/ast/rustast/RustFullIdentListenerTest.kt @@ -185,6 +185,7 @@ class RustFullIdentListenerTest { assertEquals(4, codeDataStruct.Fields.size) assertEquals("score", codeDataStruct.Fields[0].TypeValue) assertEquals("f32", codeDataStruct.Fields[0].TypeType) -// assertEquals("crate::Embedding", codeDataStruct.Fields[2].TypeType) + assertEquals("crate::Embedding", codeDataStruct.Fields[2].TypeType) + assertEquals("crate::Document", codeDataStruct.Fields[3].TypeType) } }