Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/qt-build-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod platform;
pub use platform::QtPlatformLinker;

mod qml;
pub use qml::{QmlDirBuilder, QmlPluginCppBuilder, QmlUri};
pub use qml::{QmlDirBuilder, QmlLsIniBuilder, QmlPluginCppBuilder, QmlUri};

mod qrc;
pub use qrc::{QResource, QResourceFile, QResources};
Expand Down
3 changes: 3 additions & 0 deletions crates/qt-build-utils/src/qml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
mod qmldir;
pub use qmldir::QmlDirBuilder;

mod qmlls;
pub use qmlls::QmlLsIniBuilder;

mod qmlplugincpp;
pub use qmlplugincpp::QmlPluginCppBuilder;

Expand Down
84 changes: 84 additions & 0 deletions crates/qt-build-utils/src/qml/qmlls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
// SPDX-FileContributor: Andrew Hayzen <[email protected]>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

use std::{
io,
path::{Path, PathBuf},
};

/// A helper for building QML Language Server configuration files
#[derive(Default)]
pub struct QmlLsIniBuilder {
build_dir: Option<PathBuf>,
no_cmake_calls: Option<bool>,
}

impl QmlLsIniBuilder {
/// Construct a [QmlLsIniBuilder]
pub fn new() -> Self {
Self::default()
}

/// Use the given build_dir
pub fn build_dir(mut self, build_dir: impl AsRef<Path>) -> Self {
self.build_dir = Some(build_dir.as_ref().to_path_buf());
self
}

/// Enable or disable cmake calls
pub fn no_cmake_calls(mut self, no_cmake_calls: bool) -> Self {
self.no_cmake_calls = Some(no_cmake_calls);
self
}

/// Write the resultant qmlls ini file contents
pub fn write(self, writer: &mut impl io::Write) -> io::Result<()> {
if self.build_dir.is_none() && self.no_cmake_calls.is_none() {
return Ok(());
}

writeln!(writer, "[General]")?;

if let Some(build_dir) = self.build_dir {
writeln!(
writer,
"buildDir=\"{}\"",
build_dir.to_string_lossy().escape_default()
)?;
}

if let Some(no_cmake_calls) = self.no_cmake_calls {
writeln!(
writer,
"no-cmake-calls={}",
if no_cmake_calls { "true" } else { "false" }
)?;
}

Ok(())
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn qmlls() {
let mut result = Vec::new();
QmlLsIniBuilder::new()
.build_dir("/a/b/c")
.no_cmake_calls(true)
.write(&mut result)
.unwrap();
assert_eq!(
String::from_utf8(result).unwrap(),
"[General]
buildDir=\"/a/b/c\"
no-cmake-calls=true
"
);
}
}
Loading