MCPcopy Create free account
hub / github.com/VSCodeConfigHelper/v4 / compiler

Function compiler

src-tauri/src/cli/prompt.rs:59–158  ·  view source on GitHub ↗
(setup: &'static CompilerSetup, arg: Option<String>, y: bool)

Source from the content-addressed store, hash-verified

57}
58
59pub fn compiler(setup: &'static CompilerSetup, arg: Option<String>, y: bool) -> Result<Compiler> {
60 if let Some(path) = arg {
61 match setup.verify {
62 Some(verify) => verify(&path).map_err(|str| anyhow!("验证编译器 {} 失败:{}", path, str)),
63 None => Err(anyhow!(
64 "类型 {} 的编译器不支持自定义路径。请更改编译器类型,或移除 -c 选项。",
65 setup.id
66 )),
67 }
68 } else {
69 loop {
70 let mut compilers = (setup.scan)();
71 break if y {
72 match compilers.len() {
73 0 => Err(anyhow!("找不到已安装的 {}。", setup.name)),
74 1 => Ok(compilers.swap_remove(0)),
75 _ => {
76 warn!(
77 "由于开启了 -y,在多个编译器路径中自动选择 {}",
78 compilers[0].path
79 );
80 Ok(compilers.swap_remove(0))
81 }
82 }
83 } else {
84 let mut builder = Question::select("compiler");
85
86 // The "rescan" choice's index
87 let mut rescan_idx = 0;
88
89 match compilers.len() {
90 0 => builder = builder.message("未检测到可用的编译器。您打算..."),
91 1 => {
92 return Ok(compilers.swap_remove(0));
93 }
94 _ => {
95 builder = builder
96 .message("检测到以下编译器:")
97 .choices(
98 compilers
99 .iter()
100 .map(|s| format!("{} ({})", s.version, s.path)),
101 )
102 .default_separator();
103 rescan_idx += compilers.len() + 1;
104 }
105 }
106
107 let install_idx = rescan_idx + 1;
108 let new_idx = rescan_idx + 2;
109
110 let mut actions = vec!["重新扫描"];
111 match setup.install {
112 Some(_) => actions.push("获取新的编译器..."),
113 None => actions.push("查看获取方法"),
114 }
115 match setup.verify {
116 Some(_) => actions.push("填写新的编译器路径..."),

Callers 1

cliFunction · 0.85

Calls 2

verifyFunction · 0.50
installFunction · 0.50

Tested by

no test coverage detected