File tree Expand file tree Collapse file tree 5 files changed +54
-10
lines changed
222/main/kotin/cc/unitmesh/rust/context
main/kotlin/cc/unitmesh/rust/context
test/kotlin/cc/unitmesh/rust/context Expand file tree Collapse file tree 5 files changed +54
-10
lines changed Original file line number Diff line number Diff line change 1
1
# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
2
2
propertiesPluginEnvironmentNameProperty =platformVersion
3
3
# Supported platforms: 222, 233
4
- platformVersion =233
4
+ platformVersion =222
5
5
6
6
pluginGroup = com.phodal.autodev
7
7
pluginName = AutoDev
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ package cc.unitmesh.rust.context
2
+
3
+ import cc.unitmesh.devti.context.ClassContext
4
+ import cc.unitmesh.devti.context.builder.ClassContextBuilder
5
+ import com.intellij.psi.PsiElement
6
+ import com.intellij.psi.util.PsiTreeUtil
7
+ import org.rust.lang.core.psi.RsEnumItem
8
+ import org.rust.lang.core.psi.RsFunction
9
+ import org.rust.lang.core.psi.RsImplItem
10
+ import org.rust.lang.core.psi.RsStructItem
11
+ import org.rust.lang.core.psi.ext.RsStructOrEnumItemElement
12
+ import org.rust.lang.core.psi.ext.expandedFields
13
+
14
+ class RustClassContextBuilder : ClassContextBuilder {
15
+ override fun getClassContext (psiElement : PsiElement , gatherUsages : Boolean ): ClassContext ? {
16
+ if (psiElement !is RsStructOrEnumItemElement ) return null
17
+
18
+ when (psiElement) {
19
+ is RsStructItem -> {
20
+ val fields: List <PsiElement > = psiElement.expandedFields
21
+
22
+ val impls = PsiTreeUtil .getChildrenOfTypeAsList(psiElement.containingFile, RsImplItem ::class .java)
23
+ val functions = impls.filter { it.name == psiElement.name }
24
+ .flatMap { PsiTreeUtil .getChildrenOfTypeAsList(it, RsFunction ::class .java) }
25
+
26
+ return ClassContext (
27
+ psiElement,
28
+ psiElement.text,
29
+ psiElement.name,
30
+ functions,
31
+ fields,
32
+ emptyList(),
33
+ emptyList(),
34
+ psiElement.name
35
+ )
36
+ }
37
+
38
+ is RsEnumItem -> {
39
+ // TODO: Implement
40
+ }
41
+ }
42
+
43
+ return null
44
+ }
45
+ }
Original file line number Diff line number Diff line change 1
- package cc.unitmesh.rust.context ;
1
+ package cc.unitmesh.rust.context
2
2
3
3
import com.intellij.openapi.application.ApplicationManager
4
4
import com.intellij.openapi.extensions.ExtensionPoint
@@ -8,7 +8,7 @@ import org.rust.lang.core.psi.RsStructItem
8
8
9
9
class RustClassContextBuilderTest : BasePlatformTestCase () {
10
10
11
- fun shouldFormatStruct () {
11
+ fun testShouldFormatStruct () {
12
12
// given
13
13
val code = myFixture.configureByText(
14
14
" test.rs" , """
Original file line number Diff line number Diff line change 1
- package cc.unitmesh.rust.context ;
1
+ package cc.unitmesh.rust.context
2
2
3
3
import com.intellij.psi.util.PsiTreeUtil
4
4
import com.intellij.testFramework.fixtures.BasePlatformTestCase
@@ -8,7 +8,7 @@ import org.rust.lang.core.psi.RsMembers
8
8
9
9
class RustMethodContextBuilderTest : BasePlatformTestCase () {
10
10
11
- fun shouldFormatMethodStruct () {
11
+ fun testShouldFormatMethodStruct () {
12
12
// given
13
13
val psiFile = myFixture.configureByText(
14
14
" test.rs" , """
@@ -40,11 +40,10 @@ class RustMethodContextBuilderTest : BasePlatformTestCase() {
40
40
assertEquals(" new" , result.name)
41
41
assertEquals(
42
42
result.format(), """
43
- 'package: Entry
44
- class Entry {
45
-
46
-
47
- }
43
+ path: /src/test.rs
44
+ language: Rust
45
+ fun name: new
46
+ fun signature: function
48
47
""" .trimIndent()
49
48
)
50
49
}
You can’t perform that action at this time.
0 commit comments