⚡️ don't repeat closing bracket with autocomplete
This commit is contained in:
parent
2bcc5574e6
commit
fd9ca79a41
1 changed files with 13 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue