Skip to content

Add @include_string macro#10920

Open
expenses wants to merge 3 commits intoslint-ui:masterfrom
expenses:include-string-macro
Open

Add @include_string macro#10920
expenses wants to merge 3 commits intoslint-ui:masterfrom
expenses:include-string-macro

Conversation

@expenses
Copy link
Contributor

@expenses expenses commented Mar 2, 2026

This is almost entirely bashed out by AI. It mostly looks good, though parse_include_string and from_at_include_string_node could probably be more concise. Will clean up before merging.

@expenses expenses requested a review from tronical March 2, 2026 12:34
@tronical
Copy link
Member

tronical commented Mar 2, 2026

This is marked a draft, so just a quick glance. I'm generally in favor of this feature. It needs to be documented and the lsp needs to support it in its path completion. Also the tree-sitter grammar needs to be adjusted.

@tronical
Copy link
Member

tronical commented Mar 2, 2026

I had three more thoughts about this feature:

  • For Rust this should probably use include_str!.
  • For C++, if an included file is changed, the build system needs to re-run the Slint compiler.
  • For live-preview launched via lsp as well as for the in-app live-preview, the preview needs to update if the included file changes.

@expenses expenses marked this pull request as ready for review March 3, 2026 14:24
Copy link
Member

@tronical tronical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good direction - would love to have this in the next release.

Request to address the comments, #10920 (comment) ,
#10920 (comment) as well as the need for test coverage, including the errors.

Comment on lines +556 to +567
let resolved_path = ctx
.type_loader
.and_then(|loader| loader.resolve_import_path(Some(&(*node).clone().into()), &s))
.map(|i| i.0.to_string_lossy().into())
.unwrap_or_else(|| {
crate::pathutils::join(
&crate::pathutils::dirname(node.source_file.path()),
path,
)
.map(|p| p.to_string_lossy().into())
.unwrap_or(s.clone())
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code is duplicated from from_at_image_url_node, I think it presents a good candidate for moving that into a helper function.

.unwrap_or(s.clone())
});

match std::fs::read_to_string(&resolved_path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the approach of embedding the text should be the same that we also use for images. So for Rust we use include_bytes!() (could be include_str!()), and for C++ we read the file at slint-compiler run-time and then embed it as an array or perhaps a u8 literal.

I have the feeling that this will require a dedicated Expression that can be handled in the generators as well as from_at_markdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants