Skip to content

Commit df8c88f

Browse files
committed
get xmake version from cmd
1 parent 49fec49 commit df8c88f

File tree

9 files changed

+385
-155
lines changed

9 files changed

+385
-155
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/xmake_ls/src/context/workspace_manager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use tokio_util::sync::CancellationToken;
1313
use wax::Pattern;
1414
use xmake_code_analysis::uri_to_file_path;
1515
use xmake_code_analysis::{Emmyrc, XmakeAnalysis, load_configs};
16+
use xmake_wrapper::XmakeVersion;
1617

1718
pub struct WorkspaceManager {
1819
analysis: Arc<RwLock<XmakeAnalysis>>,
@@ -28,6 +29,7 @@ pub struct WorkspaceManager {
2829
pub match_file_pattern: WorkspaceFileMatcher,
2930
// 原子变量
3031
pub workspace_initialized: Arc<AtomicBool>,
32+
pub xmake_version: XmakeVersion,
3133
}
3234

3335
impl WorkspaceManager {
@@ -49,6 +51,7 @@ impl WorkspaceManager {
4951
current_open_files: HashSet::new(),
5052
match_file_pattern: WorkspaceFileMatcher::default(),
5153
workspace_initialized: Arc::new(AtomicBool::new(false)),
54+
xmake_version: XmakeVersion::default(),
5255
}
5356
}
5457

crates/xmake_ls/src/handlers/initialized/xmake_initialize.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,30 @@ pub async fn init_xmake(context: &ServerContextSnapshot) {
2222
return;
2323
}
2424

25-
// donot need load xmake lib files for now
25+
let xmake_version = match context.xmake().get_xmake_version().await {
26+
Ok(version) => {
27+
log::info!("xmake version: {}", version);
28+
version
29+
}
30+
Err(err) => {
31+
log::warn!("failed to get xmake version: {}", err);
32+
let message = ShowMessageParams {
33+
typ: lsp_types::MessageType::ERROR,
34+
message: format!(
35+
"Failed to get xmake version: {}. Please ensure xmake is properly installed.",
36+
err
37+
),
38+
};
39+
context.client().show_message(message);
40+
return;
41+
}
42+
};
43+
44+
// set version to workspace
45+
{
46+
let mut workspace = context.workspace_manager().write().await;
47+
workspace.xmake_version = xmake_version;
48+
}
2649

2750
let Some(xmake_path) = context.xmake().get_xmake_path().await else {
2851
log::warn!("xmake directory not found");

crates/xmake_wrapper/src/builder.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
use crate::{XmakeCommand, XmakeCommandType, XmakeError, XmakeOutput, XmakeWrapper};
22

3-
/// xmake命令构建器
3+
/// xmake command builder
44
#[derive(Debug, Clone)]
55
pub struct XmakeCommandBuilder {
66
wrapper: XmakeWrapper,
77
pub(crate) command: XmakeCommand,
88
}
99

1010
impl XmakeCommandBuilder {
11-
/// 创建新的命令构建器
11+
/// Create a new command builder
1212
pub fn new(wrapper: XmakeWrapper) -> Self {
1313
Self {
1414
wrapper,
15-
command: XmakeCommand::new(XmakeCommandType::Build), // 默认命令
15+
command: XmakeCommand::new(XmakeCommandType::Build), // default command
1616
}
1717
}
1818

19-
/// 设置命令类型
19+
/// Set command type
2020
pub fn command_type(mut self, cmd_type: XmakeCommandType) -> Self {
2121
self.command.command_type = cmd_type;
2222
self
2323
}
2424

25-
/// 添加参数
25+
/// Add an argument
2626
pub fn arg<S: Into<String>>(mut self, arg: S) -> Self {
2727
self.command = self.command.arg(arg);
2828
self
2929
}
3030

31-
/// 添加多个参数
31+
/// Add multiple arguments
3232
pub fn args<I, S>(mut self, args: I) -> Self
3333
where
3434
I: IntoIterator<Item = S>,
@@ -38,7 +38,7 @@ impl XmakeCommandBuilder {
3838
self
3939
}
4040

41-
/// 添加环境变量
41+
/// Add an environment variable
4242
pub fn env<K, V>(mut self, key: K, value: V) -> Self
4343
where
4444
K: Into<String>,
@@ -48,73 +48,73 @@ impl XmakeCommandBuilder {
4848
self
4949
}
5050

51-
/// 设置是否继承父进程环境变量
51+
/// Set whether to inherit parent environment variables
5252
pub fn inherit_env(mut self, inherit: bool) -> Self {
5353
self.command = self.command.inherit_env(inherit);
5454
self
5555
}
5656

57-
/// 执行命令
57+
/// Execute the command
5858
pub async fn execute(self) -> Result<XmakeOutput, XmakeError> {
5959
self.wrapper.execute(&self.command).await
6060
}
6161

62-
/// 构建项目
62+
/// Build project
6363
pub fn build() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
6464
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Build)
6565
}
6666

67-
/// 清理项目
67+
/// Clean project
6868
pub fn clean() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
6969
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Clean)
7070
}
7171

72-
/// 配置项目
72+
/// Configure project
7373
pub fn config() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
7474
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Config)
7575
}
7676

77-
/// 安装项目
77+
/// Install project
7878
pub fn install() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
7979
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Install)
8080
}
8181

82-
/// 创建新项目
82+
/// Create new project
8383
pub fn create() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
8484
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Create)
8585
}
8686

87-
/// 运行项目
87+
/// Run project
8888
pub fn run() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
8989
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Run)
9090
}
9191

92-
/// 显示版本信息
92+
/// Show version info
9393
pub fn version() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
9494
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Version)
9595
}
9696

97-
/// 显示帮助信息
97+
/// Show help info
9898
pub fn help() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
9999
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Help)
100100
}
101101

102-
/// 显示项目信息
102+
/// Show project info
103103
pub fn show() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
104104
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Show)
105105
}
106106

107-
/// 包管理命令
107+
/// Package management command
108108
pub fn package() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
109109
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Package)
110110
}
111111

112-
/// 测试项目
112+
/// Test project
113113
pub fn test() -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
114114
|wrapper| XmakeCommandBuilder::new(wrapper).command_type(XmakeCommandType::Test)
115115
}
116116

117-
/// 自定义命令
117+
/// Custom command
118118
pub fn custom<S: Into<String>>(cmd: S) -> impl Fn(XmakeWrapper) -> XmakeCommandBuilder {
119119
let cmd = cmd.into();
120120
move |wrapper| {
@@ -123,64 +123,64 @@ impl XmakeCommandBuilder {
123123
}
124124
}
125125

126-
/// 便捷的命令构建函数
126+
/// Convenience command builder helpers
127127
impl XmakeWrapper {
128-
/// 构建项目
128+
/// Build project
129129
pub fn build(&self) -> XmakeCommandBuilder {
130130
XmakeCommandBuilder::build()(self.clone())
131131
}
132132

133-
/// 清理项目
133+
/// Clean project
134134
pub fn clean(&self) -> XmakeCommandBuilder {
135135
XmakeCommandBuilder::clean()(self.clone())
136136
}
137137

138-
/// 配置项目
138+
/// Configure project
139139
pub fn config(&self) -> XmakeCommandBuilder {
140140
XmakeCommandBuilder::config()(self.clone())
141141
}
142142

143-
/// 安装项目
143+
/// Install project
144144
pub fn install(&self) -> XmakeCommandBuilder {
145145
XmakeCommandBuilder::install()(self.clone())
146146
}
147147

148-
/// 创建新项目
148+
/// Create new project
149149
pub fn create(&self) -> XmakeCommandBuilder {
150150
XmakeCommandBuilder::create()(self.clone())
151151
}
152152

153-
/// 运行项目
153+
/// Run project
154154
pub fn run(&self) -> XmakeCommandBuilder {
155155
XmakeCommandBuilder::run()(self.clone())
156156
}
157157

158-
/// 显示版本信息
158+
/// Show version info
159159
pub fn version(&self) -> XmakeCommandBuilder {
160160
XmakeCommandBuilder::version()(self.clone())
161161
}
162162

163-
/// 显示帮助信息
163+
/// Show help info
164164
pub fn help(&self) -> XmakeCommandBuilder {
165165
XmakeCommandBuilder::help()(self.clone())
166166
}
167167

168-
/// 显示项目信息
168+
/// Show project info
169169
pub fn show(&self) -> XmakeCommandBuilder {
170170
XmakeCommandBuilder::show()(self.clone())
171171
}
172172

173-
/// 包管理命令
173+
/// Package management command
174174
pub fn package(&self) -> XmakeCommandBuilder {
175175
XmakeCommandBuilder::package()(self.clone())
176176
}
177177

178-
/// 测试项目
178+
/// Test project
179179
pub fn test(&self) -> XmakeCommandBuilder {
180180
XmakeCommandBuilder::test()(self.clone())
181181
}
182182

183-
/// 自定义命令
183+
/// Custom command
184184
pub fn custom<S: Into<String>>(&self, cmd: S) -> XmakeCommandBuilder {
185185
XmakeCommandBuilder::custom(cmd)(self.clone())
186186
}

0 commit comments

Comments
 (0)