fix: keep first line indentation independent

This commit is contained in:
Johannes Kirschbauer 2024-03-15 09:22:06 +01:00 committed by mergify[bot]
parent 62cde58158
commit 0d0b653dd9
2 changed files with 46 additions and 5 deletions

View File

@ -4,11 +4,10 @@ use rnix::{SyntaxKind, SyntaxNode, SyntaxToken};
use rowan::{ast::AstNode, GreenToken, NodeOrToken, WalkEvent};
use std::fs::File;
use std::io::Write;
use std::iter::Enumerate;
use std::path::PathBuf;
use std::println;
use std::{env, fs};
use textwrap::{dedent, indent};
use textwrap::dedent;
use walkdir::WalkDir;
const EXAMPLE_LANG: &str = "nix";
@ -207,8 +206,9 @@ fn parse_doc_comment(
return Some(s.trim().to_owned());
}
};
let mut markdown = format_code(doc, indent);
let mut markdown = handle_indentation(&doc)
.map(|t| format_code(t, indent))
.unwrap_or_default();
// example and type can contain indented code
let formatted_example = format_code(example, indent);
@ -244,7 +244,7 @@ fn parse_doc_comment(
markdown.push_str(&format!("\n\n{left}:::"));
}
markdown
format!("{}\n", markdown.trim_end())
}
fn get_binding_name(token: &SyntaxToken) -> Option<String> {

41
codemod/test/mixed.nix Normal file
View File

@ -0,0 +1,41 @@
{
/*Short tagline
in multiline
with empty lines
```nix
{
a = {
b = {
c = {
d = 1;
};
};
};
}
```
Codeblocks must keep indentation.
Type:
Indent :: a ->
{
a: {
b: {
c: {
d: Int;
};
};
};
}
Example:
packageDir "foo"
=> {
foo = {
src = ./.;
};
}
*/
packageDir = dir: 1;
}