Skip to content

Commit f538223

Browse files
committed
feat(rust): add RustCodeModifier class
This commit adds the RustCodeModifier class, which implements the CodeModifier interface. The class is responsible for modifying Rust code by inserting test code, methods, and classes into the source file. The class is applicable only to the Rust language.
1 parent 76d638d commit f538223

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cc.unitmesh.rust.provider
2+
3+
import cc.unitmesh.devti.context.builder.CodeModifier
4+
import com.intellij.lang.Language
5+
import com.intellij.openapi.project.Project
6+
import com.intellij.openapi.vfs.VirtualFile
7+
import org.rust.lang.RsLanguage
8+
9+
class RustCodeModifier : CodeModifier {
10+
override fun isApplicable(language: Language): Boolean = language is RsLanguage
11+
12+
override fun insertTestCode(sourceFile: VirtualFile, project: Project, code: String): Boolean {
13+
// in Rust, lang the test code is inserted into the source file
14+
15+
return true
16+
}
17+
18+
override fun insertMethod(sourceFile: VirtualFile, project: Project, code: String): Boolean {
19+
TODO("Not yet implemented")
20+
}
21+
22+
override fun insertClass(sourceFile: VirtualFile, project: Project, code: String): Boolean {
23+
TODO("Not yet implemented")
24+
}
25+
}

rust/src/main/kotlin/cc/unitmesh/rust/provider/RustVersionContextProvider.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ class RustVersionContextProvider : ChatContextProvider {
1717
val cargoProjectsService = project.service<CargoProjectsService>()
1818
val rustcInfo = cargoProjectsService.allProjects.firstOrNull()?.rustcInfo ?: return emptyList()
1919

20-
return listOf(
21-
ChatContextItem(
22-
RustVersionContextProvider::class,
23-
"Rust Version: ${rustcInfo.version}"
24-
)
25-
)
20+
val text = "Rust Version: ${rustcInfo.version}"
21+
return listOf(ChatContextItem(RustVersionContextProvider::class, text))
2622
}
2723
}

rust/src/main/resources/cc.unitmesh.rust.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
implementationClass="cc.unitmesh.rust.provider.RustLivingDocumentation"/>
2525

2626
<testContextProvider implementation="cc.unitmesh.rust.provider.RustTestContextProvider"/>
27+
<codeModifier language="Rust" implementationClass="cc.unitmesh.rust.provider.RustCodeModifier"/>
2728
</extensions>
2829
</idea-plugin>

src/main/kotlin/cc/unitmesh/devti/context/model/DtClass.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,8 @@ class DtClass(
109109

110110
return output.toString()
111111
}
112+
113+
/// Don't remove this, it's used by [cc.unitmesh.idea.DtModelExt] which is Kotlin compiler requirements.
114+
companion object
112115
}
113116

0 commit comments

Comments
 (0)