diff --git a/core/autocomplete/lineStream.ts b/core/autocomplete/lineStream.ts index cf5391736..07a231bce 100644 --- a/core/autocomplete/lineStream.ts +++ b/core/autocomplete/lineStream.ts @@ -12,14 +12,26 @@ export async function* streamWithNewLines(stream: LineStream): LineStream { } } +const brackets = ["(", "[", "{", "`", '"""']; +const bracketsReverse = [")", "]", "}", "`", '"""']; + export async function* stopAtSimilarLine( stream: LineStream, line: string ): AsyncGenerator { 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;