|
1 | 1 | ---
|
2 | 2 | layout: default
|
3 | 3 | title: Dev New Language
|
4 |
| -nav_order: 20 |
| 4 | +nav_order: 1 |
5 | 5 | parent: Development
|
6 | 6 | ---
|
7 | 7 |
|
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. |
9 | 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) |
| 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. |
12 | 17 |
|
13 |
| -So, we need to configure plugin for the language |
| 18 | +## AutoDev Extension Point |
14 | 19 |
|
15 |
| -## Debug Config |
| 20 | +### CodeDataStructure Context Provider |
16 | 21 |
|
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. |
18 | 24 |
|
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. |
20 | 28 |
|
21 | 29 | ```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 | 30 |
|
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"/> |
46 | 39 |
|
47 |
| -```bash |
48 |
| -./gradlew :plugin:runIde -PbaseIDE=idea -Plang=rust |
49 | 40 | ```
|
50 | 41 |
|
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 | + |
86 | 50 | ```
|
| 51 | +<chatContextProvider implementation="cc.unitmesh.rust.provider.RustVersionContextProvider"/> |
| 52 | +<chatContextProvider implementation="cc.unitmesh.rust.provider.RustCompilerContextProvider"/> |
| 53 | +``` |
| 54 | + |
| 55 | +### Test Context Provider |
87 | 56 |
|
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. |
89 | 58 |
|
90 |
| -```kotlin |
91 |
| -val rustPlugins = listOf( |
92 |
| - prop("rustPlugin"), |
93 |
| - "org.toml.lang" |
94 |
| -) |
95 | 59 | ```
|
| 60 | +<testContextProvider language="Rust" implementation="cc.unitmesh.rust.provider.RustTestService"/> |
96 | 61 |
|
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 | +``` |
98 | 64 |
|
99 |
| -- gradle-222.properties |
100 |
| -- gradle-233.properties |
| 65 | +### Living Documentation |
101 | 66 |
|
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. |
103 | 68 |
|
104 |
| -```properties |
105 |
| -rustPlugin=org.rust.lang:0.4.185.5086-222 |
| 69 | +``` |
| 70 | +<livingDocumentationProvider language="Rust" implementation="cc.unitmesh.rust.provider.RustLivingDocumentationProvider"/> |
106 | 71 | ```
|
107 | 72 |
|
108 |
| -In `gradle-233.properties`, we can see the plugin version for Rust: |
| 73 | +### API TestDataBuilder |
109 | 74 |
|
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"/> |
112 | 80 | ```
|
113 | 81 |
|
| 82 | +### contextPrompter |
114 | 83 |
|
115 |
| -## Debug Config for Rust |
| 84 | +> contextPrompter will provide the context prompt rules for user, like display and request prompts. |
116 | 85 |
|
117 |
| -Tricks for Rust development. |
| 86 | +``` |
| 87 | +<contextPrompter |
| 88 | + language="kotlin" |
| 89 | + implementation="cc.unitmesh.kotlin.provider.KotlinContextPrompter"/> |
| 90 | +``` |
118 | 91 |
|
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 |
120 | 97 |
|
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