ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / cli / src / desktop / version_manager.rs 531 строк · изменён 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
use std:: {
ffi:: OsString ,
fmt, io,
path:: { Path , PathBuf } ,
} ;
use regex:: Regex ;
use serde:: { Deserialize , Serialize } ;
use std:: sync:: LazyLock ;
use crate :: {
constants:: { PRODUCT_DOWNLOAD_URL , QUALITY ,
log
new_std_command
commit
path
f
f
commit
f
path f
s
s
s
s
s
s
versions
current
state
log
log lp _platform
log
state lp
path
mpsc
path m
result path
o status
result
path
tx rx
entry
my_path path entry
my_tx tx
my_path
my_tx my_path
tx
rx
version
path
stored state
stored current stored version path
state stored
state
version
path
i state versions v version
state versions i path
i
state
versions
version path
state versions
stored state
stored
versions
stored current
v
version
state state
_ install_path state versions v version
p install_path
p
p
candidates version
log
p p
e
log e
_
found candidates
p p
state version found
e state state
log e
found
version
version
uri
uri
uri
version
log
probable
probable
probable
probable
probable
log
stdout
stdout
state
output
line stdout
line line
state
line line
state
suffix line
output
suffix
state
output a
output
_log
output
app_ids
ids ids
output
scopes
scope key scopes
cur_ver scope key
k k
_
key cur_ver
app_ids key id
sk cur_ver key
location sk _
output
location
output
log
path
p p
e
log e
current_exe
output
dir path
target dir
target
m m current_exe
_
_
output target
output
target_os
target_os
create_dir_all
path
bin
binary_file_path path bin
parent_dir_path binary_file_path
parent_dir_path
binary_file binary_file_path
binary_file
dir
dir
dir
dir
result
result
dir
lp dir
vm1 lp
vm1
vm1
dir
vm1
dir
vm1
vm2 lp
vm2
dir
dir
dir
dir
binary_file_path
path dir
path
path
binary_file_path
fs
path dir
f path
f
path
path
binary_file_path
binary_file_path
QUALITYLESS_PRODUCT_NAME
}
,
,
state::
{
LauncherPaths
,
PersistedState
}
,
update_service::
Platform
,
util::
{
command::
,
errors::
{
AnyError
,
InvalidRequestedVersion
}
,
}
,
}
;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(tag = "t" , content = "c" )]
pub
enum
RequestedVersion
{
Default
,
Commit
(
String
)
,
Path
(
String
)
,
}
static
COMMIT_RE
:
LazyLock
<
Regex
>
=
LazyLock
::
new
(
| |
Regex
::
new
(
r"(?i)^[0-9a-f]{40}$"
)
.
unwrap
(
)
)
;
impl
RequestedVersion
{
pub
fn
get_command
(
&
self
)
->
String
{
match
self
{
RequestedVersion
::
Default
=>
{
format!
(
"code version use {QUALITY}"
)
}
RequestedVersion
::
Commit
(
)
=>
{
format!
(
"code version use {QUALITY}/{commit}"
)
}
RequestedVersion
::
Path
(
)
=>
{
format!
(
"code version use {path}"
)
}
}
}
}
impl
std:: fmt::
Display
for
RequestedVersion
{
fn
fmt
(
&
self
,
:
&
mut
fmt::
Formatter
)
->
fmt::
Result
{
match
self
{
RequestedVersion
::
Default
=>
{
write!
(
,
"{QUALITY}"
)
}
RequestedVersion
::
Commit
(
)
=>
{
write!
(
,
"{QUALITY}/{commit}"
)
}
RequestedVersion
::
Path
(
)
=>
write!
(
,
"{path}"
)
,
}
}
}
impl
TryFrom
<
&
str
>
for
RequestedVersion
{
type
Error
=
InvalidRequestedVersion
;
fn
try_from
(
:
&
str
)
->
Result
<
Self
,
Self
::
Error
>
{
if
==
QUALITY
{
return
Ok
(
RequestedVersion
::
Default
)
;
}
if
Path
::
is_absolute
(
&
PathBuf
::
from
(
)
)
{
return
Ok
(
RequestedVersion
::
Path
(
.
to_string
(
)
)
)
;
}
if
COMMIT_RE
.
is_match
(
)
{
return
Ok
(
RequestedVersion
::
Commit
(
.
to_string
(
)
)
)
;
}
Err
(
InvalidRequestedVersion
(
)
)
}
}
#[derive(Serialize, Deserialize, Clone, Default)]
struct
Stored
{
:
Vec
<
(
RequestedVersion
,
OsString
)
>
,
:
usize
,
}
pub
struct
CodeVersionManager
{
:
PersistedState
<
Stored
>
,
:
log::
Logger
,
}
impl
CodeVersionManager
{
pub
fn
new
(
:
log::
Logger
,
:
&
LauncherPaths
,
:
Platform
)
->
Self
{
CodeVersionManager
{
,
:
PersistedState
::
new
(
.
root
(
)
.
join
(
"versions.json"
)
)
,
}
}
pub
async
fn
get_entrypoint_for_install_dir
(
:
&
Path
)
->
Option
<
PathBuf
>
{
use
tokio:: sync::
;
if
let
Ok
(
true
)
=
.
metadata
(
)
.
map
(
| m|
.
is_file
(
)
)
{
let
=
new_std_command
(
)
.
args
(
[
"--version"
]
)
.
output
(
)
.
map
(
| o|
.
.
success
(
)
)
;
if
let
Ok
(
true
)
=
{
return
Some
(
.
to_owned
(
)
)
;
}
}
let
(
,
mut
)
=
mpsc::
channel
(
1
)
;
for
in
DESKTOP_CLI_RELATIVE_PATH
.
split
(
','
)
{
let
=
.
join
(
)
;
let
=
.
clone
(
)
;
tokio::
spawn
(
async
move
{
if
tokio:: fs::
metadata
(
&
)
.
await
.
is_ok
(
)
{
.
send
(
)
.
await
.
ok
(
)
;
}
}
)
;
}
drop
(
)
;
.
recv
(
)
.
await
}
pub
async
fn
set_preferred_version
(
&
self
,
:
RequestedVersion
,
:
PathBuf
,
)
->
Result
<
(
)
,
AnyError
>
{
let
mut
=
self
.
.
load
(
)
;
.
=
self
.
store_version_path
(
&
mut
,
,
)
;
self
.
.
save
(
)
?
;
Ok
(
(
)
)
}
fn
store_version_path
(
&
self
,
:
&
mut
Stored
,
:
RequestedVersion
,
:
PathBuf
,
)
->
usize
{
if
let
Some
(
)
=
.
.
iter
(
)
.
position
(
| ( v, _) |
==
&
)
{
.
[
]
.
1
=
.
into_os_string
(
)
;
}
else
{
.
.
push
(
(
.
clone
(
)
,
.
into_os_string
(
)
)
)
;
.
.
len
(
)
-
1
}
}
pub
fn
get_preferred_version
(
&
self
)
->
RequestedVersion
{
let
=
self
.
.
load
(
)
;
.
.
get
(
.
)
.
map
(
| ( v, _) |
.
clone
(
)
)
.
unwrap_or
(
RequestedVersion
::
Default
)
}
pub
async
fn
try_get_entrypoint
(
&
self
,
:
&
RequestedVersion
)
->
Option
<
PathBuf
>
{
let
mut
=
self
.
.
load
(
)
;
if
let
Some
(
(
,
)
)
=
.
.
iter
(
)
.
find
(
| ( v, _) |
==
)
{
let
=
PathBuf
::
from
(
)
;
if
.
exists
(
)
{
return
Some
(
)
;
}
}
let
=
match
&
{
RequestedVersion
::
Default
=>
match
detect_installed_program
(
&
self
.
)
{
Ok
(
)
=>
,
Err
(
)
=>
{
warning!
(
self
.
,
"error looking up installed applications: {}"
,
)
;
return
None
;
}
}
,
=>
return
None
,
}
;
let
=
match
.
into_iter
(
)
.
next
(
)
{
Some
(
)
=>
,
None
=>
return
None
,
}
;
self
.
store_version_path
(
&
mut
,
.
clone
(
)
,
.
clone
(
)
)
;
if
let
Err
(
)
=
self
.
.
save
(
)
{
debug!
(
self
.
,
"error caching version path: {}"
,
)
;
}
Some
(
)
}
}
pub
fn
prompt_to_install
(
:
&
RequestedVersion
)
{
println!
(
"No installation of {QUALITYLESS_PRODUCT_NAME} {version} was found."
)
;
if
let
RequestedVersion
::
Default
=
{
if
let
Some
(
)
=
PRODUCT_DOWNLOAD_URL
{
#[cfg(target_os = "linux" )]
println!
(
"Install it from your system's package manager or {uri}, restart your shell, and try again."
)
;
#[cfg(target_os = "macos" )]
println!
(
"Download and unzip it from {} and try again."
,
)
;
#[cfg(target_os = "windows" )]
println!
(
"Install it from {} and try again."
,
)
;
}
}
println!
(
)
;
println!
(
"If you already installed {} and we didn't detect it, run `{} --install-dir /path/to/installation`"
,
QUALITYLESS_PRODUCT_NAME
,
.
get_command
(
)
)
;
}
#[cfg(target_os = "macos" )]
fn
detect_installed_program
(
:
&
log::
Logger
)
->
io::
Result
<
Vec
<
PathBuf
>>
{
use
crate
:: constants::
PRODUCT_NAME_LONG
;
let
mut
=
PathBuf
::
from
(
"/Applications"
)
;
.
push
(
format!
(
"{}.app"
,
PRODUCT_NAME_LONG
)
)
;
if
.
exists
(
)
{
.
extend
(
[
"Contents/Resources"
,
"app"
,
"bin"
,
"code"
]
)
;
return
Ok
(
vec!
[
]
)
;
}
info!
(
,
"Searching for installations on your machine, this is done once and will take about 10 seconds..."
)
;
let
=
new_std_command
(
"system_profiler"
)
.
args
(
[
"SPApplicationsDataType"
,
"-detailLevel"
,
"mini"
]
)
.
output
(
)
?
.
;
enum
State
{
LookingForName
,
LookingForLocation
,
}
let
mut
=
State
::
LookingForName
;
let
mut
:
Vec
<
PathBuf
>
=
vec!
[
]
;
const
LOCATION_PREFIX
:
&
str
=
"Location:"
;
for
mut
in
String
::
from_utf8_lossy
(
&
)
.
lines
(
)
{
=
.
trim
(
)
;
match
{
State
::
LookingForName
=>
{
if
.
starts_with
(
PRODUCT_NAME_LONG
)
&&
.
ends_with
(
':'
)
{
=
State
::
LookingForLocation
;
}
}
State
::
LookingForLocation
=>
{
if
let
Some
(
)
=
.
strip_prefix
(
LOCATION_PREFIX
)
{
.
push
(
[
.
trim
(
)
,
"Contents/Resources"
,
"app"
,
"bin"
,
"code"
]
.
iter
(
)
.
collect
(
)
,
)
;
=
State
::
LookingForName
;
}
}
}
}
.
sort_by_key
(
| a|
.
as_os_str
(
)
.
len
(
)
)
;
Ok
(
)
}
#[cfg(windows)]
fn
detect_installed_program
(
:
&
log::
Logger
)
->
io::
Result
<
Vec
<
PathBuf
>>
{
use
crate
:: constants::
{
APPLICATION_NAME
,
WIN32_APP_IDS
}
;
use
winreg:: enums::
{
HKEY_CURRENT_USER
,
HKEY_LOCAL_MACHINE
}
;
use
winreg::
RegKey
;
let
mut
:
Vec
<
PathBuf
>
=
vec!
[
]
;
let
=
match
WIN32_APP_IDS
.
as_ref
(
)
{
Some
(
)
=>
,
None
=>
return
Ok
(
)
,
}
;
let
=
[
(
HKEY_LOCAL_MACHINE
,
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
,
)
,
(
HKEY_LOCAL_MACHINE
,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
,
)
,
(
HKEY_CURRENT_USER
,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
,
)
,
]
;
for
(
,
)
in
{
let
=
match
RegKey
::
predef
(
)
.
open_subkey
(
)
{
Ok
(
)
=>
,
Err
(
)
=>
continue
,
}
;
for
in
.
enum_keys
(
)
.
flatten
(
)
{
if
.
iter
(
)
.
any
(
| id|
.
contains
(
)
)
{
let
=
.
open_subkey
(
&
)
?
;
if
let
Ok
(
)
=
.
get_value
::
<
String
,
>
(
"InstallLocation"
)
{
.
push
(
[
.
as_str
(
)
,
"bin"
,
&
format!
(
"{}.cmd"
,
APPLICATION_NAME
)
,
]
.
iter
(
)
.
collect
(
)
,
)
}
}
}
}
Ok
(
)
}
#[cfg(target_os = "linux" )]
fn
detect_installed_program
(
:
&
log::
Logger
)
->
io::
Result
<
Vec
<
PathBuf
>>
{
use
crate
:: constants::
APPLICATION_NAME
;
let
=
match
std:: env::
var
(
"PATH"
)
{
Ok
(
)
=>
,
Err
(
)
=>
{
info!
(
,
"PATH is empty ({}), skipping detection"
,
)
;
return
Ok
(
vec!
[
]
)
;
}
}
;
let
=
std:: env::
current_exe
(
)
.
expect
(
"expected to read current exe"
)
;
let
mut
=
vec!
[
]
;
for
in
.
split
(
':'
)
{
let
:
PathBuf
=
[
,
APPLICATION_NAME
]
.
iter
(
)
.
collect
(
)
;
match
std:: fs::
canonicalize
(
&
)
{
Ok
(
)
if
==
=>
continue
,
Ok
(
)
=>
{
}
Err
(
)
=>
continue
,
}
;
.
push
(
)
;
}
Ok
(
)
}
const
DESKTOP_CLI_RELATIVE_PATH
:
&
str
=
if
cfg!
(
=
"macos"
)
{
"Contents/Resources/app/bin/code"
}
else
if
cfg!
(
=
"windows"
)
{
"bin/code.cmd,bin/code-insiders.cmd,bin/code-exploration.cmd"
}
else
{
"bin/code,bin/code-insiders,bin/code-exploration"
}
;
#[cfg(test)]
mod
tests
{
use
std::
{
fs::
{
,
File
}
,
io::
Write
,
}
;
use
super
::
*
;
fn
make_fake_vscode_install
(
:
&
Path
)
{
let
=
DESKTOP_CLI_RELATIVE_PATH
.
split
(
','
)
.
next
(
)
.
expect
(
"expected exe path"
)
;
let
=
.
join
(
)
;
let
=
.
parent
(
)
.
expect
(
"expected parent path"
)
;
create_dir_all
(
)
.
expect
(
"expected to create parent dir"
)
;
let
mut
=
File
::
create
(
)
.
expect
(
"expected to make file"
)
;
.
write_all
(
b""
)
.
expect
(
"expected to write binary"
)
;
}
fn
make_multiple_vscode_install
(
)
->
tempfile::
TempDir
{
let
=
tempfile::
tempdir
(
)
.
expect
(
"expected to make temp dir"
)
;
make_fake_vscode_install
(
&
.
path
(
)
.
join
(
"desktop/stable"
)
)
;
make_fake_vscode_install
(
&
.
path
(
)
.
join
(
"desktop/1.68.2"
)
)
;
}
#[test]
fn
test_detect_installed_program
(
)
{
let
=
detect_installed_program
(
&
log::
Logger
::
test
(
)
)
;
println!
(
"result: {result:?}"
)
;
assert!
(
.
is_ok
(
)
)
;
}
#[tokio::test]
async
fn
test_set_preferred_version
(
)
{
let
=
make_multiple_vscode_install
(
)
;
let
=
LauncherPaths
::
new_without_replacements
(
.
path
(
)
.
to_owned
(
)
)
;
let
=
CodeVersionManager
::
new
(
log::
Logger
::
test
(
)
,
&
,
Platform
::
LinuxARM64
)
;
assert_eq!
(
.
get_preferred_version
(
)
,
RequestedVersion
::
Default
)
;
.
set_preferred_version
(
RequestedVersion
::
Commit
(
"foobar"
.
to_string
(
)
)
,
.
path
(
)
.
join
(
"desktop/stable"
)
,
)
.
await
.
expect
(
"expected to store"
)
;
.
set_preferred_version
(
RequestedVersion
::
Commit
(
"foobar2"
.
to_string
(
)
)
,
.
path
(
)
.
join
(
"desktop/stable"
)
,
)
.
await
.
expect
(
"expected to store"
)
;
assert_eq!
(
.
get_preferred_version
(
)
,
RequestedVersion
::
Commit
(
"foobar2"
.
to_string
(
)
)
,
)
;
let
=
CodeVersionManager
::
new
(
log::
Logger
::
test
(
)
,
&
,
Platform
::
LinuxARM64
)
;
assert_eq!
(
.
get_preferred_version
(
)
,
RequestedVersion
::
Commit
(
"foobar2"
.
to_string
(
)
)
,
)
;
}
#[tokio::test]
async
fn
test_gets_entrypoint
(
)
{
let
=
make_multiple_vscode_install
(
)
;
assert!
(
CodeVersionManager
::
get_entrypoint_for_install_dir
(
&
.
path
(
)
.
join
(
"desktop"
)
.
join
(
"stable"
)
)
.
await
.
is_some
(
)
)
;
assert!
(
CodeVersionManager
::
get_entrypoint_for_install_dir
(
&
.
path
(
)
.
join
(
"invalid"
)
)
.
await
.
is_none
(
)
)
;
}
#[tokio::test]
async
fn
test_gets_entrypoint_as_binary
(
)
{
let
=
tempfile::
tempdir
(
)
.
expect
(
"expected to make temp dir"
)
;
#[cfg(windows)]
let
=
{
let
=
.
path
(
)
.
join
(
"code.cmd"
)
;
File
::
create
(
&
)
.
expect
(
"expected to create file"
)
;
}
;
#[cfg(unix)]
let
=
{
use
std::
;
use
std:: os:: unix:: fs::
PermissionsExt
;
let
=
.
path
(
)
.
join
(
"code"
)
;
{
let
mut
=
File
::
create
(
&
)
.
expect
(
"expected to create file"
)
;
.
write_all
(
b"#!/bin/sh"
)
.
expect
(
"expected to write to file"
)
;
}
fs::
set_permissions
(
&
,
fs::
Permissions
::
from_mode
(
0o777
)
)
.
expect
(
"expected to set permissions"
)
;
}
;
assert_eq!
(
CodeVersionManager
::
get_entrypoint_for_install_dir
(
&
)
.
await
,
Some
(
)
)
;
}
}