Skip to content

Commit 8063b4d

Browse files
committed
fix text block
1 parent 043db14 commit 8063b4d

File tree

9 files changed

+19819
-2363
lines changed

9 files changed

+19819
-2363
lines changed

debugger/package-lock.json

Lines changed: 17675 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

debugger/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@blueprintjs/core": "^3.20.0",
67
"@types/jest": "24.0.23",
78
"@types/node": "12.12.7",
89
"@types/react": "16.9.11",
910
"@types/react-dom": "16.9.4",
1011
"react": "^16.11.0",
1112
"react-dom": "^16.11.0",
12-
"react-scripts": "3.2.0",
13-
"typescript": "3.7.2",
14-
"@blueprintjs/core": "^3.20.0",
15-
"react-treebeard": "^3.2.4"
13+
"react-scripts": "^3.2.0",
14+
"react-treebeard": "^3.2.4",
15+
"typescript": "3.7.2"
1616
},
1717
"scripts": {
1818
"start": "react-scripts start",

debugger/yarn.lock

Lines changed: 2107 additions & 2328 deletions
Large diffs are not rendered by default.

palantir-java-format/src/main/java/com/palantir/javaformat/doc/Token.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ public void add(DocBuilder builder) {
104104
builder.add(this);
105105
}
106106

107+
// TODO(crogoz): this is where the token gets computed. I need to differentiate between multiLine Strings and single
108+
// Strings
107109
@Override
108110
protected float computeWidth() {
111+
if (token.getTok().getOriginalText().startsWith("\"\"\"")) {
112+
// hack hack hack to not consider the size of the textBlock such that we won't break
113+
return 0;
114+
}
109115
return token.getTok().length();
110116
}
111117

@@ -123,6 +129,10 @@ protected Range<Integer> computeRange() {
123129
public State computeBreaks(
124130
CommentsHelper commentsHelper, int maxWidth, State state, Obs.ExplorationNode observationNode) {
125131
String text = token.getTok().getOriginalText();
132+
if (token.getTok().getOriginalText().startsWith("\"\"\"")) {
133+
// hack hack hack to not consider the size of the textBlock such that we won't break
134+
return state.withColumn(state.column() + 3);
135+
}
126136
return state.withColumn(state.column() + text.length());
127137
}
128138

palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,10 +2677,15 @@ void visitDot(ExpressionTree node0) {
26772677
builder.open(OpenOp.builder()
26782678
.debugName("visitDot")
26792679
.plusIndent(plusFour)
2680-
.breakBehaviour(BreakBehaviours.preferBreakingLastInnerLevel(true))
2680+
.breakBehaviour(
2681+
isTextBlock
2682+
? BreakBehaviours.breakOnlyIfInnerLevelsThenFitOnOneLine(false)
2683+
: BreakBehaviours.preferBreakingLastInnerLevel(true))
26812684
.breakabilityIfLastLevel(
2682-
LastLevelBreakability.ACCEPT_INLINE_CHAIN_IF_SIMPLE_OTHERWISE_CHECK_INNER)
2683-
.columnLimitBeforeLastBreak(isTextBlock ? Integer.MAX_VALUE : METHOD_CHAIN_COLUMN_LIMIT)
2685+
isTextBlock
2686+
? LastLevelBreakability.ACCEPT_INLINE_CHAIN
2687+
: LastLevelBreakability.ACCEPT_INLINE_CHAIN_IF_SIMPLE_OTHERWISE_CHECK_INNER)
2688+
.columnLimitBeforeLastBreak(METHOD_CHAIN_COLUMN_LIMIT)
26842689
.isSimple(false)
26852690
.build());
26862691
scan(getArrayBase(node), null);
@@ -2793,6 +2798,7 @@ private void visitRegularDot(List<ExpressionTree> items, boolean needDot) {
27932798
int length = needDot0 ? minLength : 0;
27942799
for (ExpressionTree e : items) {
27952800
if (needDot) {
2801+
// Don't add a break after a text block
27962802
if (length > minLength) {
27972803
builder.breakOp(Break.builder()
27982804
.fillMode(FillMode.UNIFIED)

palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@Execution(ExecutionMode.CONCURRENT)
3434
public class FormatterIntegrationTest {
3535

36-
private static FileBasedTests tests = new FileBasedTests(FormatterIntegrationTest.class, "testdata2");
36+
private static FileBasedTests tests = new FileBasedTests(FormatterIntegrationTest.class, "testdata");
3737

3838
@ParameterizedClass.Parameters(name = "{0}")
3939
public static List<Object[]> data() throws IOException {
@@ -73,7 +73,7 @@ public void format() {
7373
assumeJavaVersionForTest(name);
7474
try {
7575
Formatter formatter = createFormatter();
76-
String output = createFormatter().formatSource(input);
76+
String output = formatter.formatSource(input);
7777
output = StringWrapper.wrap(Style.PALANTIR.maxLineLength(), output, formatter);
7878
if (isRecreate()) {
7979
tests.writeFormatterOutput(name, output);

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/RSL.input

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class RSLs {
5252
""", 42);
5353

5454
"""
55-
hello %s
55+
hello %s dsadasdsadad addkadkadakdakda hdsafdaf
56+
daskdabs
57+
adasd
5658
"""
5759
.formatted("world");
5860
f(
@@ -63,7 +65,7 @@ class RSLs {
6365
bar
6466
""");
6567
"""
66-
hello
68+
hello my dasdasdagdafkasfas fsdgaidahdahdafhalsdflas hasdsasadasdsadasdasdasds
6769
""".codePoints().forEach(System.err::println);
6870
String s =
6971
"""
@@ -104,4 +106,12 @@ class RSLs {
104106
this very long string that does something using arguments %s %s %s
105107
""",
106108
"@", "@", "something");
109+
110+
{
111+
"""
112+
No tools or answer found in the message. Please try again, following the instructions:\s
113+
114+
%s
115+
""".someOtherValue(e -> e.getValue().print()).myValue(System.err::println).formatted(toolFormatter.usage()).myOtherValue().someOtherValue().somethingElse();
116+
}
107117
}

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/crogoz.input

Lines changed: 0 additions & 20 deletions
This file was deleted.

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/crogoz.output

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)