Skip to content

Commit

Permalink
feat(rust): add lookup type support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 31, 2023
1 parent 5641a8f commit 37b6c42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
)
}
Expand Down Expand Up @@ -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<RustParser.OuterAttributeContext>): MutableList<CodeAnnotation> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 37b6c42

Please # to comment.