Merge pull request #3098 from continuedev/tomasz/restore-multiline-stop

Restore multiline stops
This commit is contained in:
Nate Sesti 2024-11-28 17:29:31 -08:00 • committed by GitHub
commit ed1abc556b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 73 additions and 103 deletions

View file

@ -6,7 +6,7 @@ import { stopAtStartOf, stopAtStopTokens } from "./charStream";
import {
avoidEmptyComments,
avoidPathLine,
noDoubleNewlineAfterClosingBracket,
noDoubleNewLine,
showWhateverWeHaveAtXMs,
skipPrefixes,
stopAtLines,
@ -49,7 +49,7 @@ export class StreamTransformPipeline {
);
lineGenerator = avoidPathLine(lineGenerator, helper.lang.singleLineComment);
lineGenerator = skipPrefixes(lineGenerator);
lineGenerator = noDoubleNewlineAfterClosingBracket(lineGenerator);
lineGenerator = noDoubleNewLine(lineGenerator);
for (const lineFilter of helper.lang.lineFilters ?? []) {
lineGenerator = lineFilter({ lines: lineGenerator, fullStop });

View file

@ -553,42 +553,16 @@ export async function* showWhateverWeHaveAtXMs(
}
}
export async function* noDoubleNewlineAfterClosingBracket(
lines: LineStream,
): LineStream {
const bracketTypeCounts = new Map<string, number>();
export async function* noDoubleNewLine(lines: LineStream): LineStream {
let isFirstLine = true;
for await (const line of lines) {
if (line.trim() === "") {
// Double newline detected
// Check if any bracket counts are negative
let hasNegativeCount = false;
for (const count of bracketTypeCounts.values()) {
if (count < 0) {
hasNegativeCount = true;
break;
}
}
if (hasNegativeCount) {
// Stop the generator if we've closed brackets we didn't open
return;
}
if (line.trim() === "" && !isFirstLine) {
return;
}
isFirstLine = false;
yield line;
// Update bracket counts
for (const char of line) {
if (BRACKETS[char]) {
// It's an opening bracket
const count = bracketTypeCounts.get(char) || 0;
bracketTypeCounts.set(char, count + 1);
} else if (BRACKETS_REVERSE[char]) {
// It's a closing bracket
const openingBracket = BRACKETS_REVERSE[char];
const count = bracketTypeCounts.get(openingBracket) || 0;
bracketTypeCounts.set(openingBracket, count - 1);
}
}
}
}

View file

@ -110,6 +110,7 @@ Here is a list of features:
- Feature 2`,
},
{
// options: { only: true },
description: "Should autocomplete a Java method within a class",
filename: "Calculator.java",
input: `
@ -150,8 +151,7 @@ public class Calculator {
POSTGRES_DB: mydb
`,
expectedCompletion: `
POSTGRES_DB: mydb
`,
POSTGRES_DB: mydb`,
},
{
description:
@ -283,8 +283,7 @@ async getContextForPath(
): Promise<AutocompleteCodeSnippet[]> {
const snippets: AutocompleteCodeSnippet[] = [];
`,
expectedCompletion: `console.log('TEST');
`,
expectedCompletion: `console.log('TEST');`,
},
{
description: "Should autocomplete React effect hook",
@ -333,6 +332,67 @@ export const Timer = () => {
llmOutput: ` this;`,
expectedCompletion: `this;`,
},
{
description: "Should complete YAML list item and preserve structure",
filename: "test.yaml",
input: `
services:
- name: web
image: nginx
- name: app<|fim|>
volumes:
- volume1
- volume2
`,
llmOutput: `
image: node
`,
expectedCompletion: `
image: node`,
},
{
description:
"Should complete YAML key-value pair inside a nested structure",
filename: "test.yaml",
input: `
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb<|fim|>
`,
llmOutput: `
PGDATA: /var/lib/postgresql/data/pgdata
`,
expectedCompletion: `
PGDATA: /var/lib/postgresql/data/pgdata`,
},
{
description: "Should complete YAML block within an existing block",
filename: "test.yaml",
input: `
pipelines:
branches:
master:
- step:
name: Build and Test
script:
- npm install
- npm run test
- step:
name: Deploy<|fim|>
`,
llmOutput: `
script:
- npm run deploy
`,
expectedCompletion: `
script:
- npm run deploy`,
},
{
description:
"Should autocomplete SQL query with subquery and alias in SELECT clause",
@ -1030,70 +1090,6 @@ Smart<|fim|>`,
llmOutput: "ob, 2023-02-10",
expectedCompletion: "ob, 2023-02-10",
},
{
description: "Should complete YAML list item and preserve structure",
filename: "test.yaml",
input: `
services:
- name: web
image: nginx
- name: app<|fim|>
volumes:
- volume1
- volume2
`,
llmOutput: `
image: node
`,
expectedCompletion: `
image: node
`,
},
{
description:
"Should complete YAML key-value pair inside a nested structure",
filename: "test.yaml",
input: `
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb<|fim|>
`,
llmOutput: `
PGDATA: /var/lib/postgresql/data/pgdata
`,
expectedCompletion: `
PGDATA: /var/lib/postgresql/data/pgdata
`,
},
{
description: "Should complete YAML block within an existing block",
filename: "test.yaml",
input: `
pipelines:
branches:
master:
- step:
name: Build and Test
script:
- npm install
- npm run test
- step:
name: Deploy<|fim|>
`,
llmOutput: `
script:
- npm run deploy
`,
expectedCompletion: `
script:
- npm run deploy
`,
},
{
description:
"Should autocomplete a Rust function implementation inside a struct",

View file

@ -10,7 +10,7 @@ const STARCODER2_T_ARTIFACTS = ["t.", "\nt", "<file_sep>"];
const PYTHON_ENCODING = "#- coding: utf-8";
const CODE_BLOCK_END = "```";
const multilineStops: string[] = [DOUBLE_NEWLINE, WINDOWS_DOUBLE_NEWLINE];
// const multilineStops: string[] = [DOUBLE_NEWLINE, WINDOWS_DOUBLE_NEWLINE];
const commonStops = [SRC_DIRECTORY, PYTHON_ENCODING, CODE_BLOCK_END];
export function getStopTokens(