ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / aura-kotlin / test / jdtls-experiment.mjs 217 строк · изменён 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
215
216
import { spawn } from 'node:child_process' ;
import * as fs from 'node:fs' ;
import * as path from 'node:path' ;
import * as os from 'node:os' ;
const TMP = os. tmpdir ( ) . replace ( / \\ / g , '/' )
process
launcher fs name name
launcher
fs
fs
fs
libEntries fs
fs
child
buffer
pending
nextId
diagnostics
serverLogs
body payload
child
child body
id nextId
pending id resolve reject
id method params
pending id pending id timeoutMs
method params
child serverLogs
child
buffer buffer chunk
end buffer
end
header buffer end
match header
match buffer buffer end
length match
buffer end length
text buffer end end length
buffer buffer end length
message
message text
message
message
diagnostics message message
message message
result message
message
message result
message pending message
entry pending message
pending message
message entry message entry message
javaActivity
probe
launcher
t0
init
process
text fs file
file text
text
javaActivity
probe
deadline
deadline diagnostics javaActivity
resolve
diags diagnostics javaActivity
diagnostic diags
unresolved diags d
unresolved
completion
probe
error
items completion completion completion items
items item
withImport items item
unresolved
actions
javaActivity
unresolved
unresolved
error
list actions actions
action list
hasEdit action action
organize
javaActivity
error
line serverLogs line
child process
;
const
JDTLS
=
` ${ TMP } /jdtls `
;
const
EXP
=
` ${ TMP } /aura-java-exp `
;
const
LIBS
=
` ${ EXP } /libs `
;
const
PROJ
=
` ${ EXP } /proj `
;
const
DATA
=
` ${ EXP } /data `
;
const
PROJECT
=
` ${ TMP } /aura-e2e/AuraTestApp `
;
const
JAVA
=
.
env
.
JDTLS_JAVA
??
'C:/Users/Wiks/.jdks/openjdk-25.0.2/bin/java.exe'
;
const
ANDROID_JAR
=
'C:/android-sdk/platforms/android-35/android.jar'
;
const
SRC_DIR
=
` ${ PROJECT } /app/src/main/java `
;
const
=
.
readdirSync
(
` ${ JDTLS } /plugins `
)
.
find
(
name
=>
/ ^ org\. eclipse\. equinox\. launcher_/
.
test
(
)
&&
.
endsWith
(
'.jar'
)
)
;
if
(
!
)
{
throw
new
Error
(
'launcher jar not found'
)
;
}
.
mkdirSync
(
PROJ
,
{
recursive
:
true
}
)
;
.
mkdirSync
(
DATA
,
{
recursive
:
true
}
)
;
.
writeFileSync
(
` ${ PROJ } /.project `
,
` <?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AuraTestApp</name>
<comment></comment>
<projects></projects>
<buildSpec>
<buildCommand><name>org.eclipse.jdt.core.javabuilder</name><arguments></arguments></buildCommand>
</buildSpec>
<natures><nature>org.eclipse.jdt.core.javanature</nature></natures>
<linkedResources>
<link><name>src-main</name><type>2</type><location> ${ SRC_DIR } </location></link>
</linkedResources>
</projectDescription>
`
)
;
const
=
[
ANDROID_JAR
,
...
.
readdirSync
(
LIBS
)
.
map
(
name
=>
` ${ LIBS } / ${ name} `
)
]
.
map
(
file
=>
` \t<classpathentry kind="lib" path=" ${ file} "/> `
)
.
join
(
'\n'
)
;
.
writeFileSync
(
` ${ PROJ } /.classpath `
,
` <?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src-main"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
${ libEntries}
<classpathentry kind="output" path="bin"/>
</classpath>
`
)
;
const
=
spawn
(
JAVA
,
[
'-Declipse.application=org.eclipse.jdt.ls.core.id1'
,
'-Dosgi.bundles.defaultStartLevel=4'
,
'-Declipse.product=org.eclipse.jdt.ls.core.product'
,
'-Dlog.level=ERROR'
,
'-Xmx1G'
,
'--add-modules=ALL-SYSTEM'
,
'--add-opens'
,
'java.base/java.util=ALL-UNNAMED'
,
'--add-opens'
,
'java.base/java.lang=ALL-UNNAMED'
,
'-jar'
,
` ${ JDTLS } /plugins/ ${ launcher} `
,
'-configuration'
,
` ${ JDTLS } /config_win `
,
'-data'
,
DATA
,
]
,
{
stdio
:
[
'pipe'
,
'pipe'
,
'pipe'
]
}
)
;
let
=
Buffer
.
alloc
(
0
)
;
const
=
new
Map
(
)
;
let
=
1
;
const
=
new
Map
(
)
;
const
=
[
]
;
const
send
=
payload
=>
{
const
=
Buffer
.
from
(
JSON
.
stringify
(
)
,
'utf8'
)
;
.
stdin
.
write
(
` Content-Length: ${ body. length } \r\n\r\n `
)
;
.
stdin
.
write
(
)
;
}
;
const
request
=
(
method, params, timeoutMs = 240_000
)
=>
new
Promise
(
(
resolve, reject
)
=>
{
const
=
++
;
.
set
(
,
{
,
}
)
;
send
(
{
jsonrpc
:
'2.0'
,
,
,
}
)
;
setTimeout
(
(
)
=>
{
if
(
.
has
(
)
)
{
.
delete
(
)
;
reject
(
new
Error
(
` ${ method} : timeout `
)
)
;
}
}
,
)
;
}
)
;
const
notify
=
(
method, params
)
=>
send
(
{
jsonrpc
:
'2.0'
,
,
}
)
;
.
stderr
.
on
(
'data'
,
chunk
=>
.
push
(
` [err] ${ chunk. toString ( ) . trim ( ) } `
)
)
;
.
stdout
.
on
(
'data'
,
chunk
=>
{
=
Buffer
.
concat
(
[
,
]
)
;
for
(
;
;
)
{
const
=
.
indexOf
(
'\r\n\r\n'
)
;
if
(
<
0
)
{
return
;
}
const
=
.
slice
(
0
,
)
.
toString
(
'utf8'
)
;
const
=
/ Content-Length:\s * ( \d + ) / i
.
exec
(
)
;
if
(
!
)
{
=
.
slice
(
+
4
)
;
continue
;
}
const
=
Number
(
[
1
]
)
;
if
(
.
length
<
+
4
+
)
{
return
;
}
const
=
.
slice
(
+
4
,
+
4
+
)
.
toString
(
'utf8'
)
;
=
.
slice
(
+
4
+
)
;
let
;
try
{
=
JSON
.
parse
(
)
;
}
catch
{
continue
;
}
handle
(
)
;
}
}
)
;
const
handle
=
message
=>
{
if
(
.
method
===
'textDocument/publishDiagnostics'
)
{
.
set
(
.
params
.
uri
,
.
params
.
diagnostics
)
;
return
;
}
if
(
.
id
!==
undefined
&&
.
method
)
{
const
=
.
method
===
'workspace/configuration'
?
.
params
.
items
.
map
(
(
)
=>
(
{
}
)
)
:
null
;
send
(
{
jsonrpc
:
'2.0'
,
id
:
.
id
,
}
)
;
return
;
}
if
(
.
id
!==
undefined
&&
.
has
(
Number
(
.
id
)
)
)
{
const
=
.
get
(
Number
(
.
id
)
)
;
.
delete
(
Number
(
.
id
)
)
;
if
(
.
error
)
{
.
reject
(
new
Error
(
.
error
.
message
)
)
;
}
else
{
.
resolve
(
.
result
)
;
}
}
}
;
const
fileUri
=
file
=>
` file:/// ${ file. replace ( / ^ \/ + / , '' ) } `
;
const
=
` ${ PROJECT } /app/src/main/java/com/aura/testapp/JavaActivity.java `
;
const
=
` ${ PROJECT } /app/src/main/java/com/aura/testapp/CompletionProbe.java `
;
console
.
log
(
'jdtls:'
,
)
;
const
=
Date
.
now
(
)
;
const
=
await
request
(
'initialize'
,
{
processId
:
.
pid
,
rootUri
:
fileUri
(
PROJ
)
,
workspaceFolders
:
[
{
uri
:
fileUri
(
PROJ
)
,
name
:
'AuraTestApp'
}
]
,
capabilities
:
{
workspace
:
{
applyEdit
:
true
,
configuration
:
true
,
workspaceFolders
:
true
}
,
textDocument
:
{
synchronization
:
{
didSave
:
true
}
,
completion
:
{
completionItem
:
{
snippetSupport
:
true
,
resolveSupport
:
{
properties
:
[
'additionalTextEdits'
,
'documentation'
,
'detail'
]
}
}
}
,
codeAction
:
{
codeActionLiteralSupport
:
{
codeActionKind
:
{
valueSet
:
[
'quickfix'
,
'source.organizeImports'
]
}
}
}
,
publishDiagnostics
:
{
relatedInformation
:
true
}
,
hover
:
{
contentFormat
:
[
'markdown'
,
'plaintext'
]
}
,
}
,
}
,
initializationOptions
:
{
settings
:
{
java
:
{
import
:
{
gradle
:
{
enabled
:
false
}
}
,
configuration
:
{
updateBuildConfiguration
:
'automatic'
}
}
}
,
}
,
}
)
;
console
.
log
(
` initialize: ${ ( ( Date . now ( ) - t0) / 1000 ) . toFixed ( 1 ) } s, jdtls версия: ${ init?. serverInfo?. version ?? '?' } `
)
;
notify
(
'initialized'
,
{
}
)
;
const
open
=
file
=>
{
const
=
.
readFileSync
(
,
'utf8'
)
;
notify
(
'textDocument/didOpen'
,
{
textDocument
:
{
uri
:
fileUri
(
)
,
languageId
:
'java'
,
version
:
1
,
}
}
)
;
return
;
}
;
open
(
)
;
open
(
)
;
const
=
Date
.
now
(
)
+
180_000
;
while
(
Date
.
now
(
)
<
&&
!
.
has
(
fileUri
(
)
)
)
{
await
new
Promise
(
resolve
=>
setTimeout
(
,
1000
)
)
;
}
console
.
log
(
` диагностика получена за ${ ( ( Date . now ( ) - t0) / 1000 ) . toFixed ( 1 ) } s `
)
;
const
=
.
get
(
fileUri
(
)
)
??
[
]
;
console
.
log
(
` \n== Диагностика JavaActivity.java ( ${ diags. length } ): `
)
;
for
(
const
of
)
{
console
.
log
(
` [ ${ diagnostic. severity } ] ${ diagnostic. line ?? diagnostic. range . start . line + 1 } : ${ diagnostic. message . split ( '\n' ) [ 0 ] . slice ( 0 , 140 ) } `
)
;
}
const
=
.
find
(
d
=>
/ ContextCompat /
.
test
(
.
message
)
)
;
console
.
log
(
?
'ContextCompat НЕ резолвится (ожидаемо — проверяем quick fix)'
:
'ContextCompat резолвится (автоимпорт не нужен)'
)
;
const
=
await
request
(
'textDocument/completion'
,
{
textDocument
:
{
uri
:
fileUri
(
)
}
,
position
:
{
line
:
7
,
character
:
7
}
,
context
:
{
triggerKind
:
2
,
triggerCharacter
:
'.'
}
,
}
)
.
catch
(
error
=>
(
{
error
:
.
message
}
)
)
;
const
=
Array
.
isArray
(
)
?
:
?.
??
[
]
;
console
.
log
(
` \n== Автодополнение после «view.» ( ${ items. length } элементов): `
)
;
console
.
log
(
' '
+
.
slice
(
0
,
12
)
.
map
(
item
=>
.
label
)
.
join
(
', '
)
)
;
const
=
.
filter
(
item
=>
(
.
additionalTextEdits
??
[
]
)
.
length
>
0
)
;
console
.
log
(
` элементов с дополнительными правками (автоимпорт при принятии): ${ withImport. length } `
)
;
if
(
)
{
const
=
await
request
(
'textDocument/codeAction'
,
{
textDocument
:
{
uri
:
fileUri
(
)
}
,
range
:
.
range
,
context
:
{
diagnostics
:
[
]
}
,
}
)
.
catch
(
error
=>
(
{
error
:
.
message
}
)
)
;
const
=
Array
.
isArray
(
)
?
:
[
]
;
console
.
log
(
` \n== Code actions на ошибке ContextCompat ( ${ list. length } ): `
)
;
for
(
const
of
.
slice
(
0
,
6
)
)
{
const
=
!
!
.
edit
||
!
!
.
command
;
console
.
log
(
` ${ action. kind ?? '?' } : ${ action. title } ${ hasEdit ? ' (с правкой)' : '' } `
)
;
}
}
const
=
await
request
(
'textDocument/codeAction'
,
{
textDocument
:
{
uri
:
fileUri
(
)
}
,
range
:
{
start
:
{
line
:
0
,
character
:
0
}
,
end
:
{
line
:
0
,
character
:
0
}
}
,
context
:
{
only
:
[
'source.organizeImports'
]
,
diagnostics
:
[
]
}
,
}
)
.
catch
(
error
=>
(
{
error
:
.
message
}
)
)
;
console
.
log
(
` \n== source.organizeImports: ${ Array . isArray ( organize) ? organize. map ( a => a. title ) . join ( ', ' ) || 'нет' : JSON . stringify ( organize) } `
)
;
console
.
log
(
` \nсерверных ошибок в stderr: ${ serverLogs. length } `
)
;
for
(
const
of
.
slice
(
0
,
5
)
)
{
console
.
log
(
' '
+
.
slice
(
0
,
160
)
)
;
}
try
{
await
request
(
'shutdown'
,
null
,
20_000
)
;
notify
(
'exit'
)
;
}
catch
{
}
setTimeout
(
(
)
=>
{
.
kill
(
)
;
.
exit
(
0
)
;
}
,
1500
)
;