Skip to content

Commit b8c6f22

Browse files
committed
qt-build-utils: add Qml Language Server ini builder
1 parent 6bc6686 commit b8c6f22

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

crates/qt-build-utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod platform;
3434
pub use platform::QtPlatformLinker;
3535

3636
mod qml;
37-
pub use qml::{QmlDirBuilder, QmlPluginCppBuilder, QmlUri};
37+
pub use qml::{QmlDirBuilder, QmlLsIniBuilder, QmlPluginCppBuilder, QmlUri};
3838

3939
mod qrc;
4040
pub use qrc::{QResource, QResourceFile, QResources};

crates/qt-build-utils/src/qml/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
mod qmldir;
77
pub use qmldir::QmlDirBuilder;
88

9+
mod qmlls;
10+
pub use qmlls::QmlLsIniBuilder;
11+
912
mod qmlplugincpp;
1013
pub use qmlplugincpp::QmlPluginCppBuilder;
1114

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
2+
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
3+
//
4+
// SPDX-License-Identifier: MIT OR Apache-2.0
5+
6+
use std::{
7+
io,
8+
path::{Path, PathBuf},
9+
};
10+
11+
/// A helper for building QML Language Server configuration files
12+
#[derive(Default)]
13+
pub struct QmlLsIniBuilder {
14+
build_dir: Option<PathBuf>,
15+
no_cmake_calls: Option<bool>,
16+
}
17+
18+
impl QmlLsIniBuilder {
19+
/// Construct a [QmlLsIniBuilder]
20+
pub fn new() -> Self {
21+
Self::default()
22+
}
23+
24+
/// Use the given build_dir
25+
pub fn build_dir(mut self, build_dir: impl AsRef<Path>) -> Self {
26+
self.build_dir = Some(build_dir.as_ref().to_path_buf());
27+
self
28+
}
29+
30+
/// Enable or disable cmake calls
31+
pub fn no_cmake_calls(mut self, no_cmake_calls: bool) -> Self {
32+
self.no_cmake_calls = Some(no_cmake_calls);
33+
self
34+
}
35+
36+
/// Write the resultant qmlls ini file contents
37+
pub fn write(self, writer: &mut impl io::Write) -> io::Result<()> {
38+
if self.build_dir.is_none() && self.no_cmake_calls.is_none() {
39+
return Ok(());
40+
}
41+
42+
writeln!(writer, "[General]")?;
43+
44+
if let Some(build_dir) = self.build_dir {
45+
writeln!(
46+
writer,
47+
"buildDir=\"{}\"",
48+
build_dir.to_string_lossy().escape_default()
49+
)?;
50+
}
51+
52+
if let Some(no_cmake_calls) = self.no_cmake_calls {
53+
writeln!(
54+
writer,
55+
"no-cmake-calls={}",
56+
if no_cmake_calls { "true" } else { "false" }
57+
)?;
58+
}
59+
60+
Ok(())
61+
}
62+
}
63+
64+
#[cfg(test)]
65+
mod test {
66+
use super::*;
67+
68+
#[test]
69+
fn qmlls() {
70+
let mut result = Vec::new();
71+
QmlLsIniBuilder::new()
72+
.build_dir("/a/b/c")
73+
.no_cmake_calls(true)
74+
.write(&mut result)
75+
.unwrap();
76+
assert_eq!(
77+
String::from_utf8(result).unwrap(),
78+
"[General]
79+
buildDir=\"/a/b/c\"
80+
no-cmake-calls=true
81+
"
82+
);
83+
}
84+
}

0 commit comments

Comments
 (0)