Fix formatting of argument lists (#1283)
This fixes several issues: 1. Leading/trailing line comments surrounding a lambda should make that lambda not "trailing", because the formatting otherwise looks bad and also isn't stable 2. Fix incorrect algorithm for detecting trailing lambda (currently, any number of lambdas makes the alg return `true`)
This commit is contained in:
1 parent
4226c21a42
commit
d29ae07e14
6 files changed
+82
-33
No files matched your search
@@ -77,8 +77,8 @@ public class GenericParser {
|
||||
}
|
||||
var lastImport = parseImportDecl();
|
||||
imports.add(lastImport);
|
||||
// keep trailling affixes as part of the import
|
||||
while (lookahead.isAffix() && lastImport.span.sameLine(spanLookahead)) {
|
||||
// keep trailing affixes as part of the import
|
||||
while (lookahead.isAffix() && lastImport.span.isSameLine(spanLookahead)) {
|
||||
imports.add(makeAffix(next()));
|
||||
}
|
||||
if (!isImport()) break;
|
||||
@@ -662,7 +662,7 @@ public class GenericParser {
|
||||
if (operator.getPrec() < minPrecedence) break;
|
||||
// `-` and `[]` must be in the same line as the left operand and have no semicolons inbetween
|
||||
if ((operator == Operator.MINUS || operator == Operator.SUBSCRIPT)
|
||||
&& (fullOpToken.hasSemicolon || !expr.span.sameLine(fullOpToken.tk.span))) break;
|
||||
&& (fullOpToken.hasSemicolon || !expr.span.isSameLine(fullOpToken.tk.span))) break;
|
||||
var children = new ArrayList<Node>();
|
||||
children.add(expr);
|
||||
ff(children);
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.pkl.parser.syntax.generic;
|
||||
|
||||
import org.pkl.parser.Span;
|
||||
|
||||
public record FullSpan(
|
||||
int charIndex, int length, int lineBegin, int colBegin, int lineEnd, int colEnd) {
|
||||
|
||||
@@ -30,11 +28,7 @@ public record FullSpan(
|
||||
end.colEnd);
|
||||
}
|
||||
|
||||
public Span toSpan() {
|
||||
return new Span(charIndex, length);
|
||||
}
|
||||
|
||||
public boolean sameLine(FullSpan other) {
|
||||
public boolean isSameLine(FullSpan other) {
|
||||
return lineEnd == other.lineBegin;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user