Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text block indentation when the text block has no prefix #1165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,10 @@ private void indentTextBlocks(
ImmutableList<String> initialLines = text.lines().collect(toImmutableList());
String stripped = stripIndent(initialLines.stream().skip(1).collect(joining(separator)));
ImmutableList<String> lines = stripped.lines().collect(toImmutableList());
int deindent =
initialLines.get(1).stripTrailing().length() - lines.get(0).stripTrailing().length();

int startColumn = lineMap.getColumnNumber(startPosition);
String prefix =
(deindent == 0 || lines.stream().anyMatch(x -> x.length() + startColumn > columnLimit))
Comment on lines -200 to -205
Copy link
Contributor Author

@dweiss dweiss Sep 24, 2024

Choose a reason for hiding this comment

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

We don't have to compute "deindent" at all here, I think, since no text block is allowed to appear at the top level of the syntax tree (?). Even if we wanted to allow it, the condition should be

String prefix = (startColumn == 0 || lines.stream().anyMatch(x -> x.length() + startColumn > columnLimit)) 
   ...
``.

(lines.stream().anyMatch(x -> x.length() + startColumn > columnLimit))
? ""
: " ".repeat(startColumn - 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ ipsum
""";
String k =
"""
lorem
ipsum
""";
Comment on lines -51 to -53
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The expected output in this test was incorrect, it should have an indent.

lorem
ipsum
""";

{
f(
Expand Down