Skip to content

Commit f6e068b

Browse files
committed
feat(docs): add guide for configuring new language plugin
This commit adds a guide for configuring a new language plugin in AutoDev. It includes steps for creating a new language plugin module, setting dependencies, and implementing the plugin module. It also provides information on AutoDev extension points such as CodeDataStructure Context Provider, Chat Context Provider, Test Context Provider, Living Documentation, API TestDataBuilder, contextPrompter, and Custom Prompt Provider. The guide aims to help developers easily develop new language plugins for AutoDev.
1 parent a64e365 commit f6e068b

File tree

2 files changed

+193
-92
lines changed

2 files changed

+193
-92
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
layout: default
3+
title: Debug New Language
4+
nav_order: 2
5+
parent: Development
6+
---
7+
8+
In JetBrains' IDE, some language support is not good enough, and some language support is not available at all.
9+
10+
- Good enough language will have IDE support, like golang with GoLand.
11+
- Not good enough language will have no IDE support, like Rust with CLion (before RustRover)
12+
13+
So, we need to configure plugin for the language
14+
15+
## Debug Config
16+
17+
for Debug, We already run configs under `.idea/runConfigurations`, so we can just copy and modify them.
18+
19+
Here are some examples [RustRust.xml] :
20+
21+
```xml
22+
<component name="ProjectRunConfigurationManager">
23+
<configuration default="false" name="Run Rust" type="GradleRunConfiguration" factoryName="Gradle">
24+
<ExternalSystemSettings>
25+
<option name="executionName" />
26+
<option name="externalProjectPath" value="$PROJECT_DIR$" />
27+
<option name="externalSystemIdString" value="GRADLE" />
28+
<option name="scriptParameters" value="-PbaseIDE=idea -Plang=rust" />
29+
<option name="taskDescriptions">
30+
<list />
31+
</option>
32+
<option name="taskNames">
33+
<list>
34+
<option value=":plugin:runIde" />
35+
</list>
36+
</option>
37+
<option name="vmOptions" value="" />
38+
</ExternalSystemSettings>
39+
<GradleScriptDebugEnabled>false</GradleScriptDebugEnabled>
40+
<method v="2" />
41+
</configuration>
42+
</component>
43+
```
44+
45+
We configure the `scriptParameters` to pass the `baseIDE` and `lang` to the gradle script.
46+
47+
```bash
48+
./gradlew :plugin:runIde -PbaseIDE=idea -Plang=rust
49+
```
50+
51+
## Configure in Gradle
52+
53+
We can configure the plugin in Gradle script, like build.gradle.kts :
54+
55+
```kotlin
56+
project(":plugin") {
57+
apply {
58+
plugin("org.jetbrains.changelog")
59+
}
60+
61+
version = prop("pluginVersion") + "-$platformVersion"
62+
63+
intellij {
64+
pluginName.set(basePluginArchiveName)
65+
val pluginList: MutableList<String> = mutableListOf("Git4Idea")
66+
when (lang) {
67+
"idea" -> {
68+
pluginList += javaPlugins
69+
}
70+
"python" -> {
71+
pluginList += pycharmPlugins
72+
}
73+
"go" -> {
74+
pluginList += listOf("org.jetbrains.plugins.go")
75+
}
76+
"rust" -> {
77+
pluginList += rustPlugins
78+
}
79+
}
80+
81+
plugins.set(pluginList)
82+
}
83+
84+
...
85+
}
86+
```
87+
88+
In `rustPlugins`, we can see the plugin list for Rust:
89+
90+
```kotlin
91+
val rustPlugins = listOf(
92+
prop("rustPlugin"),
93+
"org.toml.lang"
94+
)
95+
```
96+
97+
The `prop("rustPlugin")` is defined in `gradle.properties`, which will also load different version of plugin for different IDE version.
98+
99+
- gradle-222.properties
100+
- gradle-233.properties
101+
102+
In `gradle-222.properties`, we can see the plugin version for Rust:
103+
104+
```properties
105+
rustPlugin=org.rust.lang:0.4.185.5086-222
106+
```
107+
108+
In `gradle-233.properties`, we can see the plugin version for Rust:
109+
110+
```properties
111+
rustPlugin=com.jetbrains.rust:233.21799.284
112+
```
113+
114+
115+
## Debug Config for Rust
116+
117+
Tricks for Rust development.
118+
119+
Due to JetBrains' crafty move, there are two different versions of the Rust IDE plugin.
120+
121+
- **Under 233: Deprecated Rust**
122+
- check latest available version here https://plugins.jetbrains.com/plugin/8182--deprecated-rust
123+
- rustPlugin=org.rust.lang:0.4.185.5086-222
124+
- **Above 233: Official Rust
125+
- check latest available version here https://plugins.jetbrains.com/plugin/22407-rust/versions
126+
- rustPlugin=com.jetbrains.rust:233.21799.284

docs/development/dev-new-language.md

Lines changed: 67 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,101 @@
11
---
22
layout: default
33
title: Dev New Language
4-
nav_order: 20
4+
nav_order: 1
55
parent: Development
66
---
77

8-
In JetBrains' IDE, some language support is not good enough, and some language support is not available at all.
8+
If you want to develop a new language for AutoDev, you can follow this guide.
99

10-
- Good enough language will have IDE support, like golang with GoLand.
11-
- Not good enough language will have no IDE support, like Rust with CLion (before RustRover)
10+
1. lookup the plugin in [JetBrains' Plugin Repository](https://plugins.jetbrains.com/)
11+
2. create new language plugin module in AutoDev.
12+
- set dependencies in `build.gradle.kts`.
13+
- set dependencies in `settings.gradle.kts`.
14+
- create plugin module file under `newlang/src/main/resources/cc.unitmesh.<newlang>.xml`
15+
- declare plugin module in `plugin/src/main/plugin.xml`
16+
3. implement the plugin module.
1217

13-
So, we need to configure plugin for the language
18+
## AutoDev Extension Point
1419

15-
## Debug Config
20+
### CodeDataStructure Context Provider
1621

17-
for Debug, We already run configs under `.idea/runConfigurations`, so we can just copy and modify them.
22+
> CodeDataStructure will provide the data structure for code, like file, class, method, variable, etc. Which will be
23+
> used in Test Generation, Code Complete, Code Refactor, etc.
1824
19-
Here are some examples [RustRust.xml] :
25+
At beginning, we use [Chapi](https://github.com/phodal/chapi) to parse code data structure, but it's too slow.
26+
And, we found that JetBrains' IDE already have a good data structure, so we use it. We follow JetBrains' code data
27+
structure and design.
2028

2129
```xml
22-
<component name="ProjectRunConfigurationManager">
23-
<configuration default="false" name="Run Rust" type="GradleRunConfiguration" factoryName="Gradle">
24-
<ExternalSystemSettings>
25-
<option name="executionName" />
26-
<option name="externalProjectPath" value="$PROJECT_DIR$" />
27-
<option name="externalSystemIdString" value="GRADLE" />
28-
<option name="scriptParameters" value="-PbaseIDE=idea -Plang=rust" />
29-
<option name="taskDescriptions">
30-
<list />
31-
</option>
32-
<option name="taskNames">
33-
<list>
34-
<option value=":plugin:runIde" />
35-
</list>
36-
</option>
37-
<option name="vmOptions" value="" />
38-
</ExternalSystemSettings>
39-
<GradleScriptDebugEnabled>false</GradleScriptDebugEnabled>
40-
<method v="2" />
41-
</configuration>
42-
</component>
43-
```
4430

45-
We configure the `scriptParameters` to pass the `baseIDE` and `lang` to the gradle script.
31+
<fileContextBuilder language="Rust"
32+
implementationClass="cc.unitmesh.rust.context.RustFileContextBuilder"/>
33+
<classContextBuilder language="Rust"
34+
implementationClass="cc.unitmesh.rust.context.RustClassContextBuilder"/>
35+
<methodContextBuilder language="Rust"
36+
implementationClass="cc.unitmesh.rust.context.RustMethodContextBuilder"/>
37+
<variableContextBuilder language="Rust"
38+
implementationClass="cc.unitmesh.rust.context.RustVariableContextBuilder"/>
4639

47-
```bash
48-
./gradlew :plugin:runIde -PbaseIDE=idea -Plang=rust
4940
```
5041

51-
## Configure in Gradle
52-
53-
We can configure the plugin in Gradle script, like build.gradle.kts :
54-
55-
```kotlin
56-
project(":plugin") {
57-
apply {
58-
plugin("org.jetbrains.changelog")
59-
}
60-
61-
version = prop("pluginVersion") + "-$platformVersion"
62-
63-
intellij {
64-
pluginName.set(basePluginArchiveName)
65-
val pluginList: MutableList<String> = mutableListOf("Git4Idea")
66-
when (lang) {
67-
"idea" -> {
68-
pluginList += javaPlugins
69-
}
70-
"python" -> {
71-
pluginList += pycharmPlugins
72-
}
73-
"go" -> {
74-
pluginList += listOf("org.jetbrains.plugins.go")
75-
}
76-
"rust" -> {
77-
pluginList += rustPlugins
78-
}
79-
}
80-
81-
plugins.set(pluginList)
82-
}
83-
84-
...
85-
}
42+
### Chat Context Provider
43+
44+
> Chat Context Provider will provide the data structure for chat, like Language version, Compiler version, Framework
45+
> information, etc.
46+
47+
Similar to CodeDataStructure Context Provider, we use JetBrains' design for Chat Context Provider. You can implement
48+
multiple Chat Context Providers for same languages.
49+
8650
```
51+
<chatContextProvider implementation="cc.unitmesh.rust.provider.RustVersionContextProvider"/>
52+
<chatContextProvider implementation="cc.unitmesh.rust.provider.RustCompilerContextProvider"/>
53+
```
54+
55+
### Test Context Provider
8756

88-
In `rustPlugins`, we can see the plugin list for Rust:
57+
> Test Context will collect that context for test generation, and with CodeModifier to generate test code.
8958
90-
```kotlin
91-
val rustPlugins = listOf(
92-
prop("rustPlugin"),
93-
"org.toml.lang"
94-
)
9559
```
60+
<testContextProvider language="Rust" implementation="cc.unitmesh.rust.provider.RustTestService"/>
9661
97-
The `prop("rustPlugin")` is defined in `gradle.properties`, which will also load different version of plugin for different IDE version.
62+
<codeModifier language="Rust" implementationClass="cc.unitmesh.rust.provider.RustCodeModifier"/>
63+
```
9864

99-
- gradle-222.properties
100-
- gradle-233.properties
65+
### Living Documentation
10166

102-
In `gradle-222.properties`, we can see the plugin version for Rust:
67+
> Living Documentation will provide the living documentation for user, and also can generate the comments.
10368
104-
```properties
105-
rustPlugin=org.rust.lang:0.4.185.5086-222
69+
```
70+
<livingDocumentationProvider language="Rust" implementation="cc.unitmesh.rust.provider.RustLivingDocumentationProvider"/>
10671
```
10772

108-
In `gradle-233.properties`, we can see the plugin version for Rust:
73+
### API TestDataBuilder
10974

110-
```properties
111-
rustPlugin=com.jetbrains.rust:233.21799.284
75+
> API TestDataBuilder will provide the API test data for user, like API test data, API test code, etc.
76+
77+
```
78+
<testDataBuilder language="kotlin"
79+
implementationClass="cc.unitmesh.kotlin.provider.KotlinTestDataBuilder"/>
11280
```
11381

82+
### contextPrompter
11483

115-
## Debug Config for Rust
84+
> contextPrompter will provide the context prompt rules for user, like display and request prompts.
11685
117-
Tricks for Rust development.
86+
```
87+
<contextPrompter
88+
language="kotlin"
89+
implementation="cc.unitmesh.kotlin.provider.KotlinContextPrompter"/>
90+
```
11891

119-
Due to JetBrains' crafty move, there are two different versions of the Rust IDE plugin.
92+
### Custom Prompt Provider
93+
94+
> customPromptProvider will provide the custom prompt functions for user.
95+
96+
```xml
12097

121-
- **Under 233: Deprecated Rust**
122-
- check latest available version here https://plugins.jetbrains.com/plugin/8182--deprecated-rust
123-
- rustPlugin=org.rust.lang:0.4.185.5086-222
124-
- **Above 233: Official Rust
125-
- check latest available version here https://plugins.jetbrains.com/plugin/22407-rust/versions
126-
- rustPlugin=com.jetbrains.rust:233.21799.284
98+
<customPromptProvider
99+
language="kotlin"
100+
implementationClass="cc.unitmesh.kotlin.provider.KotlinCustomPromptProvider"/>
101+
```

0 commit comments

Comments
 (0)