File tree 3 files changed +45
-1
lines changed
main/kotlin/chapi/ast/rustast
test/kotlin/chapi/ast/rustast
3 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ Languages Stages (Welcome to PR your usage languages)
18
18
| ---------------| ------| --------| ----| --------| -------| ----| ----| -------| -----| ------|
19
19
| http api decl | ✅ | 🆕 | 🆕 | ✅ | ✅ | 🆕 | 🆕 | | | |
20
20
| syntax parse | ✅ | ✅ | ✅ | ✅ | ✅ | 🆕 | 🆕 | ✅ | 🆕 | 🆕 |
21
- | function call | ✅ | 🆕 | 🆕 | 🆕 | ✅ | | | | | |
21
+ | function call | ✅ | 🆕 | 🆕 | 🆕 | ✅ | | | | | 🆕 |
22
22
| arch/package | ✅ | | | ✅ | ✅ | | | ✅ | | |
23
23
| real world | ✅ | | | 🆕 | ✅ | | | | | |
24
24
Original file line number Diff line number Diff line change 1
1
package chapi.ast.rustast
2
2
3
+ import chapi.ast.antlr.RustParser
4
+ import chapi.domain.core.CodeCall
5
+ import chapi.domain.core.CodeProperty
6
+
3
7
4
8
open class RustFullIdentListener (val fileName : String ) : RustAstBaseListener(fileName) {
9
+ override fun enterCallExpression (ctx : RustParser .CallExpressionContext ? ) {
10
+ val function = if (isEnteredIndividualFunction) {
11
+ currentIndividualFunction
12
+ } else {
13
+ currentFunction
14
+ }
15
+
16
+ val functionName = ctx?.expression()?.text
17
+ val split = functionName?.split(" ::" )
18
+ function.FunctionCalls + = CodeCall (
19
+ Package = split?.dropLast(1 )?.joinToString(" ::" ) ? : " " ,
20
+ NodeName = split?.dropLast(1 )?.joinToString(" ::" ) ? : " " ,
21
+ FunctionName = split?.last() ? : " " ,
22
+ Parameters = ctx?.callParams()?.expression()?.map {
23
+ CodeProperty (
24
+ TypeValue = it.text,
25
+ TypeType = it.text
26
+ )
27
+ } ? : listOf (),
28
+ )
29
+ }
5
30
}
Original file line number Diff line number Diff line change @@ -188,4 +188,23 @@ class RustFullIdentListenerTest {
188
188
assertEquals(" crate::Embedding" , codeDataStruct.Fields [2 ].TypeType )
189
189
assertEquals(" crate::Document" , codeDataStruct.Fields [3 ].TypeType )
190
190
}
191
+
192
+ @Test
193
+ fun should_analysis_first_function_call () {
194
+ val code = """
195
+ use crate::Point;
196
+
197
+ fn main() {
198
+ let p = Point::new(1, 2);
199
+ }
200
+ """ .trimIndent()
201
+
202
+ val codeContainer = RustAnalyser ().analysis(code, " test.rs" )
203
+ val codeDataStruct = codeContainer.DataStructures [0 ]
204
+ assertEquals(1 , codeDataStruct.Functions .size)
205
+ val functionCalls = codeDataStruct.Functions [0 ].FunctionCalls
206
+ assertEquals(1 , functionCalls.size)
207
+ assertEquals(" Point" , functionCalls[0 ].NodeName )
208
+ assertEquals(" new" , functionCalls[0 ].FunctionName )
209
+ }
191
210
}
You can’t perform that action at this time.
0 commit comments