Skip to content
Draft
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
10 changes: 9 additions & 1 deletion tools/bend-fmt-lsp/src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,15 @@ export function formatBend(source: string, options: FormatOptions = {}): string
const width = line.indent.length;
if (!loose[index]) while (pins.length > 0 && pins[pins.length - 1].from > width) pins.pop();
const anchor = anchors[index];
const pin = anchor ? bodyPins.get(anchor) : pins.filter((pin) => pin.from <= width).pop();
let pin = anchor ? bodyPins.get(anchor) : undefined;
if (!anchor) {
for (let at = pins.length - 1; at >= 0; at--) {
if (pins[at].from <= width) {
pin = pins[at];
break;
}
}
}
if (anchor && pin && pins.at(-1) !== pin) pins.push(pin);
const prefix = pin ? pin.prefix + " ".repeat(width - pin.from + pin.to - pin.prefix.length)
: spaces ? " ".repeat(depths[index] * size) : "\t".repeat(depths[index]);
Expand Down