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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed LuaJIT suffixes `LL`/`ULL` causing a panic when running in `--verify` mode ([#750](https://github.com/JohnnyMorganz/StyLua/issues/750))
- Fixed incorrect formatting of conditionals when `collapse_simple_statement` is enabled and the block begins with an empty line ([#744](https://github.com/JohnnyMorganz/StyLua/issues/744))
- Fixed formatting of dot function call chains with comment between dot and names ([#747](https://github.com/JohnnyMorganz/StyLua/issues/747))

## [0.18.1] - 2023-07-15

Expand Down
27 changes: 22 additions & 5 deletions src/formatters/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use crate::{
UpdateTrailingTrivia, UpdateTrivia,
},
trivia_util::{
self, contains_comments, trivia_is_newline, CommentSearch, GetLeadingTrivia,
self, contains_comments, prepend_newline_indent, take_leading_comments,
take_trailing_comments, trivia_is_newline, CommentSearch, GetLeadingTrivia,
GetTrailingTrivia,
},
},
Expand Down Expand Up @@ -425,10 +426,26 @@ pub fn format_index(ctx: &Context, index: &Index, shape: Shape) -> Index {
}
}

Index::Dot { dot, name } => Index::Dot {
dot: format_token_reference(ctx, dot, shape),
name: format_token_reference(ctx, name, shape),
},
Index::Dot { dot, name } => {
// If there are any comments in between the dot and name,
// then taken them out and put them before the dot
let (mut dot, mut dot_comments) =
take_trailing_comments(&format_token_reference(ctx, dot, shape));
let (name, name_comments) =
take_leading_comments(&format_token_reference(ctx, name, shape));

dot_comments.extend(name_comments);

if !dot_comments.is_empty() {
dot = prepend_newline_indent(
ctx,
&dot.update_leading_trivia(FormatTriviaType::Append(dot_comments)),
shape,
);
}

Index::Dot { dot, name }
}
other => panic!("unknown node {:?}", other),
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/formatters/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,8 @@ pub fn format_function_call(
let mut must_hang = false;
while let Some(suffix) = peekable_suffixes.next() {
must_hang = suffix.has_leading_comments(CommentSearch::All)
// Check for comment placed inside of suffix
|| matches!(suffix, Suffix::Index(Index::Dot { dot, name }) if dot.has_trailing_comments(CommentSearch::All) || name.has_leading_comments(CommentSearch::All))
// Check for a trailing comment (iff there is still a suffix after this)
|| (peekable_suffixes.peek().is_some()
&& suffix.has_trailing_comments(CommentSearch::All));
Expand Down
6 changes: 6 additions & 0 deletions tests/inputs/hang-call-chain-comments-2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- https://github.com/JohnnyMorganz/StyLua/issues/747

obj. --
func(). --
func(). --
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: tests/tests.rs
expression: format(&contents)
---
-- https://github.com/JohnnyMorganz/StyLua/issues/747

obj
--
.func()
--
.func()
--
.func()