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
2 changes: 1 addition & 1 deletion src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ foo := \"xx\"

goodbye := \"y\"

hello a b c: x y z
hello a b c: x y z #hello
#! blah
#blarg
{{ foo + bar }}abc{{ goodbye + \"x\" }}xyz
Expand Down
13 changes: 11 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,8 +1398,16 @@ impl<'run, 'src> Parser<'run, 'src> {
dependencies.append(&mut subsequents);
}

if self.next_are(&[Comment, Eol, Indent]) || self.next_are(&[Eol, Indent]) {
self.expect_eol()?;
let trailing_comment = if self.next_are(&[Comment, Eol, Indent]) {
self
.accept(Comment)?
.map(|comment| comment.lexeme().trim_end())
} else {
None
};

if self.next_are(&[Eol, Indent]) {
self.expect(Eol)?;
}

let body = self.parse_body()?;
Expand Down Expand Up @@ -1454,6 +1462,7 @@ impl<'run, 'src> Parser<'run, 'src> {
quiet,
recipe_path: None,
shebang: shebang || script,
trailing_comment,
variable_references: HashSet::new(),
})
}
Expand Down
6 changes: 6 additions & 0 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub(crate) struct Recipe<'src, D = Dependency<'src>> {
pub(crate) recipe_path: Option<Modulepath>,
pub(crate) shebang: bool,
#[serde(skip)]
pub(crate) trailing_comment: Option<&'src str>,
#[serde(skip)]
pub(crate) variable_references: HashSet<Number>,
}

Expand Down Expand Up @@ -773,6 +775,10 @@ impl<D: Display> ColorDisplay for Recipe<'_, D> {
write!(f, " {dependency}")?;
}

if let Some(trailing_comment) = self.trailing_comment {
write!(f, " {trailing_comment}")?;
}

for (i, line) in self.body.iter().enumerate() {
if i == 0 {
writeln!(f)?;
Expand Down
1 change: 1 addition & 0 deletions src/unresolved_recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ impl<'src> UnresolvedRecipe<'src> {
quiet: self.quiet,
recipe_path: Some(recipe_path),
shebang: self.shebang,
trailing_comment: self.trailing_comment,
variable_references,
})
}
Expand Down
8 changes: 4 additions & 4 deletions tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1848,14 +1848,14 @@ fn trailing_comment_does_not_become_doc_comment() {
}

#[test]
fn trailing_comment_recipe_with_body_is_stripped() {
fn trailing_comment_recipe_with_body() {
assert_dump(
"
foo: # bar
echo baz
",
"
foo:
foo: # bar
echo baz
",
);
Expand All @@ -1874,7 +1874,7 @@ fn trailing_comment_export() {
}

#[test]
fn trailing_comment_recipe_with_dependencies_and_body_is_stripped() {
fn trailing_comment_recipe_with_dependencies_and_body() {
assert_dump(
"
foo: bar # baz
Expand All @@ -1883,7 +1883,7 @@ fn trailing_comment_recipe_with_dependencies_and_body_is_stripped() {
bar:
",
"
foo: bar
foo: bar # baz
echo qux

bar:
Expand Down
Loading