Skip to content

Commit

Permalink
Don't output lines with no annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed Jan 25, 2024
1 parent aa95401 commit 31da28a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/cursorless-vscode-e2e/src/suite/serializeTargetRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,32 @@ export function serializeTargetRange(
const lines: string[] = [];

codeLines.forEach((codeLine, lineNumber) => {
// Output the line itself, prefixed by `n| `, eg `3| const foo = "bar"`
lines.push(
codeLine.length > 0 ? `${lineNumber}| ${codeLine}` : `${lineNumber}|`,
);

let annotationLine: string | undefined;
if (lineNumber === start.line) {
const prefix = fill(" ", start.character + 2) + ">";
if (start.line === end.line) {
lines.push(prefix + fill("-", end.character - start.character) + "<");
annotationLine =
prefix + fill("-", end.character - start.character) + "<";
} else {
lines.push(prefix + fill("-", codeLine.length - start.character));
annotationLine = prefix + fill("-", codeLine.length - start.character);
}
} else if (lineNumber > start.line && lineNumber < end.line) {
if (codeLine.length > 0) {
lines.push(" " + fill("-", codeLine.length));
annotationLine = " " + fill("-", codeLine.length);
} else {
lines.push("");
annotationLine = "";
}
} else if (lineNumber === end.line) {
lines.push(" " + fill("-", end.character) + "<");
} else {
lines.push("");
annotationLine = " " + fill("-", end.character) + "<";
}

if (annotationLine != null) {
// Only output anything if there is an annotation line
lines.push(
// Output the line itself, prefixed by `n| `, eg `3| const foo = "bar"`
codeLine.length > 0 ? `${lineNumber}| ${codeLine}` : `${lineNumber}|`,
annotationLine,
);
}
});

Expand Down

0 comments on commit 31da28a

Please sign in to comment.