ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / aura-kotlin / src / projectWizard.ts 215 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import * as vscode from 'vscode' ;
import { tr } from './l10n' ;
import { findGradleCommand, execTool } from './gradle' ;
import { GRADLE_VERSION } from './toolchain' ;
export function registerProjectWizard ( context: vscode. ExtensionContext) : void {
context. subscriptions. push (
vscode. commands. registerCommand ( folder vscode Uri folder
vscode commands target vscode Uri target
folder vscode Uri
target folder vscode window canSelectFolders canSelectMany openLabel
target
namePick vscode window prompt value
namePick
kind vscode window
label id
label id
label id
label id
placeHolder
kind
root vscode Uri target namePick
pkg namePick
kind id
src vscode Uri root
vscode workspace fs src
vscode workspace fs vscode Uri src Buffer
vscode workspace fs vscode Uri root Buffer
kind id
javaDir vscode Uri root pkg
vscode workspace fs javaDir
vscode workspace fs vscode Uri root Buffer
vscode workspace fs vscode Uri root Buffer
vscode workspace fs vscode Uri javaDir Buffer
kind id kind id
compose kind id
mainDir vscode Uri root pkg
resDir vscode Uri root
vscode workspace fs mainDir
vscode workspace fs resDir
activity namePick c c
vscode workspace fs vscode Uri root Buffer
vscode workspace fs vscode Uri root Buffer
compose
vscode workspace fs vscode Uri root Buffer
vscode workspace fs vscode Uri root Buffer
compose
vscode workspace fs vscode Uri root Buffer
vscode workspace fs vscode Uri mainDir Buffer
compose
vscode workspace fs vscode Uri resDir Buffer
kind id root
open vscode window namePick
open vscode commands root
root vscode Uri
gradle root fsPath
gradle
gradle command gradle args cwd root fsPath timeout
kotlinDir vscode Uri resDir vscode Uri pkg
root vscode Uri AndroidDirs
uri vscode Uri Buffer vscode workspace fs uri
moduleDir
mainDir moduleDir vscode Uri root moduleDir vscode Uri root
vscode workspace fs mainDir
moduleRoot moduleDir vscode Uri root moduleDir root
gradle vscode Uri moduleRoot vscode Uri moduleRoot
manifest vscode Uri mainDir
pkg gradle
manifest
kotlinDir vscode Uri mainDir pkg
resDir vscode Uri mainDir
pkg
className suffix
base className
base
uri vscode Uri content
vscode workspace fs uri
vscode window uri fsPath
vscode workspace fs uri Buffer content
doc vscode workspace uri
vscode window doc
target vscode Uri
root vscode workspace workspaceFolders uri
root
vscode window
android root
kinds
label id
label id
android
label id
label id
label id
label id
kind vscode window kinds placeHolder
kind
kotlinBase target android kotlinDir vscode Uri root
kind id android
valuesDir vscode Uri android resDir
vscode workspace fs valuesDir
vscode Uri valuesDir
isLayout kind id
name vscode window
prompt isLayout
value isLayout
value isLayout value
name
clean name
kind id
pkg android
vscode Uri kotlinBase
pkg android
vscode Uri kotlinBase
android
layout clean kind id
layoutDir vscode Uri android resDir
vscode workspace fs layoutDir
vscode Uri layoutDir
body kind id
vscode Uri kotlinBase body
vscode window clean layout
android
layoutDir vscode Uri android resDir
vscode workspace fs layoutDir
vscode Uri layoutDir
'auraKotlin.newProject'
,
(
?
:
.
)
=>
newProject
(
)
)
,
.
.
registerCommand
(
'auraKotlin.newFile'
,
(
?
:
.
)
=>
newFile
(
)
)
,
)
;
}
async
function
newProject
(
?
:
.
)
:
Promise
<
void
>
{
const
=
??
(
await
.
.
showOpenDialog
(
{
:
true
,
:
false
,
:
tr
(
'Create project here'
)
}
)
)
?.
[
0
]
;
if
(
!
)
{
return
;
}
const
=
await
.
.
showInputBox
(
{
:
tr
(
'Project name'
)
,
:
'MyApp'
}
)
;
if
(
!
)
{
return
;
}
const
=
await
.
.
showQuickPick
(
[
{
:
'$(rocket) Kotlin CLI (kotlinc + JVM)'
,
:
'cli'
}
,
{
:
'$(coffee) Java (Gradle)'
,
:
'java'
}
,
{
:
'$(device-mobile) Android (Views, AppCompat)'
,
:
'android'
}
,
{
:
'$(device-mobile) Android (Jetpack Compose)'
,
:
'compose'
}
,
]
,
{
:
tr
(
'Project type'
)
}
)
;
if
(
!
)
{
return
;
}
const
=
.
.
joinPath
(
,
)
;
const
=
.
toLowerCase
(
)
.
replace
(
/ [ ^ a- z 0- 9 ] / g
,
''
)
||
'app'
;
if
(
.
===
'cli'
)
{
const
=
.
.
joinPath
(
,
'src'
)
;
await
.
.
.
createDirectory
(
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'Main.kt'
)
,
.
from
(
` fun main() {\n\tprintln("Hello, ${ namePick} !")\n}\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'README.md'
)
,
.
from
(
` # ${ namePick} \n\nBuild: kotlinc src/Main.kt -include-runtime -d app.jar && java -jar app.jar\n `
,
'utf8'
)
)
;
}
else
if
(
.
===
'java'
)
{
const
=
.
.
joinPath
(
,
'src'
,
'main'
,
'java'
,
'com'
,
'example'
,
)
;
await
.
.
.
createDirectory
(
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'settings.gradle.kts'
)
,
.
from
(
` rootProject.name = " ${ namePick} "\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'build.gradle.kts'
)
,
.
from
(
` plugins {\n\tjava\n\tapplication\n}\n\nrepositories {\n\tmavenCentral()\n}\n\napplication {\n\tmainClass.set("com.example. ${ pkg} .Main")\n}\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'Main.java'
)
,
.
from
(
` package com.example. ${ pkg} ;\n\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println("Hello, ${ namePick} !");\n\t}\n}\n `
,
'utf8'
)
)
;
}
else
if
(
.
===
'android'
||
.
===
'compose'
)
{
const
=
.
===
'compose'
;
const
=
.
.
joinPath
(
,
'app'
,
'src'
,
'main'
,
'kotlin'
,
'com'
,
'example'
,
)
;
const
=
.
.
joinPath
(
,
'app'
,
'src'
,
'main'
,
'res'
,
'values'
)
;
await
.
.
.
createDirectory
(
)
;
await
.
.
.
createDirectory
(
)
;
const
=
.
replace
(
/ [ ^ A- Z a- z 0- 9 ] / g
,
''
)
.
replace
(
/ ^ . /
,
=>
.
toUpperCase
(
)
)
||
'Main'
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'settings.gradle.kts'
)
,
.
from
(
` pluginManagement {\n\trepositories {\n\t\tgoogle()\n\t\tmavenCentral()\n\t\tgradlePluginPortal()\n\t}\n}\n\ndependencyResolutionManagement {\n\trepositories {\n\t\tgoogle()\n\t\tmavenCentral()\n\t}\n}\n\nrootProject.name = " ${ namePick} "\ninclude(":app")\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'build.gradle.kts'
)
,
.
from
(
?
` plugins {\n\tid("com.android.application") version "8.7.2" apply false\n\tid("org.jetbrains.kotlin.android") version "2.1.0" apply false\n\tid("org.jetbrains.kotlin.plugin.compose") version "2.1.0" apply false\n}\n `
:
` plugins {\n\tid("com.android.application") version "8.7.2" apply false\n\tid("org.jetbrains.kotlin.android") version "2.1.0" apply false\n}\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'gradle.properties'
)
,
.
from
(
` org.gradle.jvmargs=-Xmx2g\nandroid.useAndroidX=true\nkotlin.code.style=official\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'app'
,
'build.gradle.kts'
)
,
.
from
(
?
` plugins {\n\tid("com.android.application")\n\tid("org.jetbrains.kotlin.android")\n\tid("org.jetbrains.kotlin.plugin.compose")\n}\n\nandroid {\n\tnamespace = "com.example. ${ pkg} "\n\tcompileSdk = 35\n\tdefaultConfig {\n\t\tapplicationId = "com.example. ${ pkg} "\n\t\tminSdk = 24\n\t\ttargetSdk = 35\n\t}\n\tbuildFeatures {\n\t\tcompose = true\n\t}\n}\n\ndependencies {\n\timplementation(platform("androidx.compose:compose-bom:2024.12.01"))\n\timplementation("androidx.activity:activity-compose:1.9.3")\n\timplementation("androidx.compose.ui:ui")\n\timplementation("androidx.compose.ui:ui-tooling-preview")\n\timplementation("androidx.compose.material3:material3")\n\tdebugImplementation("androidx.compose.ui:ui-tooling")\n}\n `
:
` plugins {\n\tid("com.android.application")\n\tid("org.jetbrains.kotlin.android")\n}\n\nandroid {\n\tnamespace = "com.example. ${ pkg} "\n\tcompileSdk = 35\n\tdefaultConfig {\n\t\tapplicationId = "com.example. ${ pkg} "\n\t\tminSdk = 24\n\t\ttargetSdk = 35\n\t}\n}\n\ndependencies {\n\timplementation("androidx.core:core-ktx:1.15.0")\n\timplementation("androidx.appcompat:appcompat:1.7.0")\n}\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'app'
,
'src'
,
'main'
,
'AndroidManifest.xml'
)
,
.
from
(
` <?xml version="1.0" encoding="utf-8"?>\n<manifest xmlns:android="http://schemas.android.com/apk/res/android">\n\t<application android:label=" ${ namePick} " android:theme=" ${ compose ? '@android:style/Theme.Material.NoActionBar' : '@style/Theme.AppCompat' } ">\n\t\t<activity android:name=". ${ activity} Activity" android:exported="true">\n\t\t\t<intent-filter>\n\t\t\t\t<action android:name="android.intent.action.MAIN" />\n\t\t\t\t<category android:name="android.intent.category.LAUNCHER" />\n\t\t\t</intent-filter>\n\t\t</activity>\n\t</application>\n</manifest>\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
` ${ activity} Activity.kt `
)
,
.
from
(
?
` package com.example. ${ pkg} \n\nimport android.os.Bundle\nimport androidx.activity.ComponentActivity\nimport androidx.activity.compose.setContent\nimport androidx.compose.foundation.layout.fillMaxSize\nimport androidx.compose.material3.MaterialTheme\nimport androidx.compose.material3.Surface\nimport androidx.compose.material3.Text\nimport androidx.compose.runtime.Composable\nimport androidx.compose.ui.Modifier\n\nclass ${ activity} Activity : ComponentActivity() {\n\toverride fun onCreate(savedInstanceState: Bundle?) {\n\t\tsuper.onCreate(savedInstanceState)\n\t\tsetContent {\n\t\t\tMaterialTheme {\n\t\t\t\tSurface(modifier = Modifier.fillMaxSize()) { Greeting(" ${ namePick} ") }\n\t\t\t}\n\t\t}\n\t}\n}\n\n@Composable\nfun Greeting(name: String) {\n\tText(text = "Hello, $name!")\n}\n `
:
` package com.example. ${ pkg} \n\nimport android.os.Bundle\nimport androidx.appcompat.app.AppCompatActivity\n\nclass ${ activity} Activity : AppCompatActivity() {\n\toverride fun onCreate(savedInstanceState: Bundle?) {\n\t\tsuper.onCreate(savedInstanceState)\n\t}\n}\n `
,
'utf8'
)
)
;
await
.
.
.
writeFile
(
.
.
joinPath
(
,
'strings.xml'
)
,
.
from
(
` <?xml version="1.0" encoding="utf-8"?>\n<resources>\n\t<string name="app_name"> ${ namePick} </string>\n</resources>\n `
,
'utf8'
)
)
;
}
if
(
.
!==
'cli'
)
{
await
generateGradleWrapper
(
)
;
}
const
=
await
.
.
showInformationMessage
(
tr
(
'Project \'{0}\' created.'
,
)
,
tr
(
'Open folder'
)
)
;
if
(
)
{
await
.
.
executeCommand
(
'vscode.openFolder'
,
)
;
}
}
async
function
generateGradleWrapper
(
:
.
)
:
Promise
<
void
>
{
try
{
const
=
await
findGradleCommand
(
.
)
;
if
(
!
)
{
return
;
}
await
execTool
(
.
,
[
...
.
,
'wrapper'
,
'--gradle-version'
,
GRADLE_VERSION
,
'--distribution-type'
,
'bin'
,
'-q'
]
,
{
:
.
,
:
10
*
60_000
}
)
;
}
catch
{
}
}
interface
AndroidDirs
{
:
.
;
:
.
;
:
string
;
}
async
function
detectAndroidModule
(
:
.
)
:
Promise
<
|
undefined
>
{
const
read
=
async
(
:
.
)
=>
{
try
{
return
.
from
(
await
.
.
.
readFile
(
)
)
.
toString
(
'utf8'
)
;
}
catch
{
return
undefined
;
}
}
;
for
(
const
of
[
'app'
,
''
]
)
{
const
=
?
.
.
joinPath
(
,
,
'src'
,
'main'
)
:
.
.
joinPath
(
,
'src'
,
'main'
)
;
try
{
await
.
.
.
stat
(
)
;
}
catch
{
continue
;
}
const
=
?
.
.
joinPath
(
,
)
:
;
const
=
await
read
(
.
.
joinPath
(
,
'build.gradle.kts'
)
)
??
await
read
(
.
.
joinPath
(
,
'build.gradle'
)
)
??
''
;
const
=
await
read
(
.
.
joinPath
(
,
'AndroidManifest.xml'
)
)
??
''
;
const
=
/ namespace\s * =? \s * "( [ \w .] + ) " /
.
exec
(
)
?.
[
1
]
??
/ package\s * =\s * "( [ \w .] + ) " /
.
exec
(
)
?.
[
1
]
??
'com.example.app'
;
return
{
:
.
.
joinPath
(
,
'kotlin'
,
...
.
split
(
'.'
)
)
,
:
.
.
joinPath
(
,
'res'
)
,
,
}
;
}
return
undefined
;
}
function
layoutName
(
:
string
,
:
'activity'
|
'fragment'
)
:
string
{
const
=
.
replace
(
new
RegExp
(
` ${ suffix} $ `
,
'i'
)
,
''
)
||
'main'
;
return
` ${ suffix} _ `
+
.
replace
(
/ ( [ a- z 0- 9 ] ) ( [ A- Z ] ) / g
,
'$1_$2'
)
.
toLowerCase
(
)
;
}
async
function
writeNew
(
:
.
,
:
string
)
:
Promise
<
boolean
>
{
try
{
await
.
.
.
stat
(
)
;
void
.
.
showErrorMessage
(
tr
(
'File {0} already exists.'
,
.
.
split
(
/ [ \\ /] /
)
.
pop
(
)
??
''
)
)
;
return
false
;
}
catch
{
}
await
.
.
.
writeFile
(
,
.
from
(
,
'utf8'
)
)
;
const
=
await
.
.
openTextDocument
(
)
;
await
.
.
showTextDocument
(
)
;
return
true
;
}
async
function
newFile
(
?
:
.
)
:
Promise
<
void
>
{
const
=
.
.
?.
[
0
]
?.
;
if
(
!
)
{
void
.
.
showWarningMessage
(
tr
(
'Open a workspace first.'
)
)
;
return
;
}
const
=
await
detectAndroidModule
(
)
;
const
=
[
{
:
'$(symbol-class) Kotlin class'
,
:
'kt-class'
}
,
{
:
'$(play) Kotlin file with main()'
,
:
'kt-main'
}
,
...
(
?
[
{
:
'$(device-mobile) Android Activity (+ layout)'
,
:
'activity'
}
,
{
:
'$(symbol-snippet) Android Fragment (+ layout)'
,
:
'fragment'
}
,
{
:
'$(layout) Layout XML'
,
:
'layout'
}
,
{
:
'$(symbol-string) values/strings.xml'
,
:
'values'
}
,
]
:
[
]
)
,
]
;
const
=
await
.
.
showQuickPick
(
,
{
:
tr
(
'File template'
)
}
)
;
if
(
!
)
{
return
;
}
const
=
??
?.
??
.
.
joinPath
(
,
'src'
)
;
if
(
.
===
'values'
&&
)
{
const
=
.
.
joinPath
(
.
,
'values'
)
;
await
.
.
.
createDirectory
(
)
;
await
writeNew
(
.
.
joinPath
(
,
'strings.xml'
)
,
` <?xml version="1.0" encoding="utf-8"?>\n<resources>\n\t<string name="app_name">App</string>\n</resources>\n `
)
;
return
;
}
const
=
.
===
'layout'
;
const
=
await
.
.
showInputBox
(
{
:
?
tr
(
'Layout name (e.g. activity_main)'
)
:
tr
(
'Class / file name'
)
,
:
?
'activity_main'
:
'MyClass'
,
validateInput
:
=>
(
?
/ ^ [ a- z ] [ a- z 0- 9 _] * $ /
:
/ ^ [ A- Z a- z _] \w * $ /
)
.
test
(
.
trim
(
)
)
?
undefined
:
tr
(
'Invalid name'
)
,
}
)
;
if
(
!
)
{
return
;
}
const
=
.
trim
(
)
;
switch
(
.
)
{
case
'kt-class'
:
{
const
=
?
` package ${ android. pkg} \n\n `
:
''
;
await
writeNew
(
.
.
joinPath
(
,
` ${ clean} .kt `
)
,
` ${ pkg} class ${ clean} {\n\t\n}\n `
)
;
break
;
}
case
'kt-main'
:
{
const
=
?
` package ${ android. pkg} \n\n `
:
''
;
await
writeNew
(
.
.
joinPath
(
,
` ${ clean} .kt `
)
,
` ${ pkg} fun main() {\n\tprintln("Hello from ${ clean} ")\n}\n `
)
;
break
;
}
case
'activity'
:
case
'fragment'
:
{
if
(
!
)
{
return
;
}
const
=
layoutName
(
,
.
)
;
const
=
.
.
joinPath
(
.
,
'layout'
)
;
await
.
.
.
createDirectory
(
)
;
await
writeNew
(
.
.
joinPath
(
,
` ${ layout} .xml `
)
,
` <?xml version="1.0" encoding="utf-8"?>\n<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\n\tandroid:layout_width="match_parent"\n\tandroid:layout_height="match_parent"\n\tandroid:orientation="vertical">\n\n</LinearLayout>\n `
)
;
const
=
.
===
'activity'
?
` package ${ android. pkg} \n\nimport android.os.Bundle\nimport androidx.appcompat.app.AppCompatActivity\n\nclass ${ clean} : AppCompatActivity() {\n\toverride fun onCreate(savedInstanceState: Bundle?) {\n\t\tsuper.onCreate(savedInstanceState)\n\t\tsetContentView(R.layout. ${ layout} )\n\t}\n}\n `
:
` package ${ android. pkg} \n\nimport android.os.Bundle\nimport android.view.View\nimport androidx.fragment.app.Fragment\n\nclass ${ clean} : Fragment(R.layout. ${ layout} ) {\n\toverride fun onViewCreated(view: View, savedInstanceState: Bundle?) {\n\t\tsuper.onViewCreated(view, savedInstanceState)\n\t}\n}\n `
;
await
writeNew
(
.
.
joinPath
(
,
` ${ clean} .kt `
)
,
)
;
void
.
.
showInformationMessage
(
tr
(
'Created {0}.kt and res/layout/{1}.xml'
,
,
)
)
;
break
;
}
case
'layout'
:
{
if
(
!
)
{
return
;
}
const
=
.
.
joinPath
(
.
,
'layout'
)
;
await
.
.
.
createDirectory
(
)
;
await
writeNew
(
.
.
joinPath
(
,
` ${ clean} .xml `
)
,
` <?xml version="1.0" encoding="utf-8"?>\n<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\n\tandroid:layout_width="match_parent"\n\tandroid:layout_height="match_parent"\n\tandroid:orientation="vertical">\n\n</LinearLayout>\n `
)
;
break
;
}
}
}