⚡️ don't repeat closing bracket with autocomplete

This commit is contained in:
Nate Sesti 2024-02-06 10:40:04 -08:00
parent 2bcc5574e6
commit fd9ca79a41

View file

@ -12,14 +12,26 @@ export async function* streamWithNewLines(stream: LineStream): LineStream {
}
}
const brackets = ["(", "[", "{", "`", '"""'];
const bracketsReverse = [")", "]", "}", "`", '"""'];
export async function* stopAtSimilarLine(
stream: LineStream,
line: string
): AsyncGenerator<string> {
line = line.trim();
for await (const nextLine of stream) {
if (
bracketsReverse.includes(nextLine.trim()) &&
bracketsReverse.includes(line.trim()) &&
line.trim() === nextLine.trim()
) {
continue;
}
const dist = distance(nextLine.trim(), line);
if (nextLine.length > 4 && line.length > 4 && dist / line.length < 0.1) {
let lineQualifies = nextLine.length > 4 && line.length > 4;
if (lineQualifies && dist / line.length < 0.1) {
break;
}
yield nextLine;