From fd9ca79a41c1e97b597bade5e83b766d7d5ca3dc Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 6 Feb 2024 10:40:04 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20don't=20repeat=20closing?= =?UTF-8?q?=20bracket=20with=20autocomplete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/autocomplete/lineStream.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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;