Skip to content
Merged
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
26 changes: 26 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Rust

on:
push:
branches: [ master ]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -Dwarnings

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose --workspace
1 change: 1 addition & 0 deletions .idea/compose.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"compose-utils",
"compose",
"compose-error-codes",
"compose-error-codes-doc-tests",
"compose-doc-macros",
"compose-doc",
"compose-codespan-reporting"
Expand All @@ -36,10 +37,12 @@ compose-macros = { path = "compose-macros" }
compose-syntax = { path = "compose-syntax" }
compose-utils = { path = "compose-utils" }
compose-error-codes = { path = "compose-error-codes" }
compose-error-codes-doc-tests = { path = "compose-error-codes-doc-tests" }
compose-editor = { path = "compose-editor" }
compose-doc-macros = { path = "compose-doc-macros" }
compose-doc = { path = "compose-doc" }
compose-codespan-reporting = { path = "compose-codespan-reporting" }
itertools = "0.14.0"

[workspace.lints.rust]
unsafe_code = "deny"
Expand Down
9 changes: 8 additions & 1 deletion compose-cli/src/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ pub(crate) fn explain(code: &str) -> Result<(), CliError> {
Some(code) => {
let md_text = code.description;

let explained = match compose_doc::transform_markdown(md_text, &Config::ansi()) {
let explained = match compose_doc::transform_markdown(
md_text,
&Config::new()
.with_ansi()
// make sure that the explain command works even if the explanation is technically not fully accurate
.with_output_block_error_mode(compose_doc::ErrorHandlingMode::Ignore)
.with_code_block_error_mode(compose_doc::ErrorHandlingMode::Ignore),
) {
Ok(v) => v,
Err(e) => {
eprintln!(
Expand Down
4 changes: 2 additions & 2 deletions compose-cli/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ impl World for SystemWorld {
&self.library
}

fn write(&self, f: &dyn Fn(&mut dyn Write) -> std::io::Result<()>) -> std::io::Result<()> {
fn write(&self, f: &mut dyn FnMut(&mut dyn Write) -> std::io::Result<()>) -> std::io::Result<()> {
f(&mut std::io::stdout())
}

fn read(&self, f: &dyn Fn(&mut dyn Read) -> std::io::Result<()>) -> std::io::Result<()> {
fn read(&self, f: &mut dyn FnMut(&mut dyn Read) -> std::io::Result<()>) -> std::io::Result<()> {
f(&mut std::io::stdin())
}

Expand Down
32 changes: 18 additions & 14 deletions compose-doc-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
use compose_doc::ErrorHandlingMode;
use proc_macro::TokenStream as BoundaryStream;
use quote::quote;
use syn::spanned::Spanned;
use syn::{parse_macro_input, Attribute, Item};
use syn::{Attribute, Item, parse_macro_input};
use unindent::unindent;

#[proc_macro]
pub fn compose_doc(input: BoundaryStream) -> BoundaryStream {
let ComposeDocInput { attrs, item } = parse_macro_input!(input as ComposeDocInput);

let lines: Vec<_> = attrs.iter()
.filter_map(extract_doc_line)
.collect();
let lines: Vec<_> = attrs.iter().filter_map(extract_doc_line).collect();

let markdown = unindent(&lines.join("\n"));

// Transform markdown
let transformed =
match compose_doc::transform_markdown(&markdown, &compose_doc::Config::no_color()) {
Ok(t) => t,
Err(e) => {
return syn::Error::new_spanned(&item, format!("{}: {}", e.line, e.message))
.to_compile_error()
.into();
}
};
let transformed = match compose_doc::transform_markdown(
&markdown,
&compose_doc::Config::new()
.with_no_color()
.with_code_block_error_mode(ErrorHandlingMode::EmitAsTests)
.with_output_block_error_mode(ErrorHandlingMode::EmitAsTests),

) {
Ok(t) => t,
Err(e) => {
return syn::Error::new_spanned(&item, format!("{}: {}", e.line, e.message))
.to_compile_error()
.into();
}
};

let doc_lines = transformed.lines().map(|line| quote! { #[doc = #line] });

Expand All @@ -38,7 +43,6 @@ pub fn compose_doc(input: BoundaryStream) -> BoundaryStream {
output.into()
}


struct ComposeDocInput {
attrs: Vec<Attribute>,
item: Item,
Expand Down
11 changes: 6 additions & 5 deletions compose-doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,17 @@ If a block:
- emits diagnostics not marked with `error(...)` or `warn(...)`, or
- claims to emit diagnostics that aren’t produced by the code,

then `transform_markdown` will fail with a line-referenced error.
then [`transform_markdown`] will fail with a line-referenced error.

---

## 🛠️ Configuration

```rust
use compose_doc::Config;
let config = Config::ansi(); // diagnostics with colour
let config = Config::no_color(); // plain-text diagnostics

let config = Config::new().with_ansi(); // diagnostics with colour
let config = Config::new().with_no_color(); // plain-text diagnostics
```
*/
mod block;
Expand Down Expand Up @@ -285,7 +286,7 @@ mod tests {
"#};

let output =
transform_markdown(input, &Config::no_color()).expect("failed to transform markdown");
transform_markdown(input, &Config::new().with_no_color()).expect("failed to transform markdown");

assert_eq!(
output.trim(),
Expand Down Expand Up @@ -332,7 +333,7 @@ mod tests {
"#};

let output =
transform_markdown(input, &Config::no_color()).expect("failed to transform markdown");
transform_markdown(input, &Config::new().with_no_color()).expect("failed to transform markdown");

assert_eq!(
output.trim(),
Expand Down
Loading