Skip to content

Commit 9da6811

Browse files
committed
Bump version to 1.985.0 and update relevant files parser to reject responses containing code blocks
1 parent ac408a9 commit 9da6811

5 files changed

Lines changed: 17 additions & 58 deletions

File tree

‎apps/editor/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
44
"description": "Chatbot-first AI coding (CWC)",
5-
"version": "1.984.0",
5+
"version": "1.985.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",
88
"vscode:prepublish": "rimraf out && npm run compile",

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/relevant-files-parser/relevant-files-parser.ts‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,21 @@ type RelevantFilesItem = {
55
file_paths: string[]
66
}
77

8-
export const parse_relevant_files_from_response = (params: {
8+
export const parse_relevant_files = (params: {
99
response: string
1010
workspace_files: string[]
1111
}): RelevantFilesItem | null => {
12-
const trimmed_response = params.response.trim()
13-
14-
if (trimmed_response.includes('```')) {
15-
const code_blocks = trimmed_response.match(/```[\s\S]*?(?:```|$)/g)
16-
const has_valid_path_in_code_blocks = code_blocks?.some((block) =>
17-
params.workspace_files.some((file) => block.includes(file))
18-
)
19-
20-
if (!has_valid_path_in_code_blocks) {
21-
return null
22-
}
12+
if (params.response.includes('```')) {
13+
return null
2314
}
2415

25-
const found_paths = extract_paths_from_text(trimmed_response)
16+
const found_paths = extract_paths_from_text(params.response)
2617

2718
const valid_paths = found_paths
2819
.filter((path) => params.workspace_files.includes(path))
2920
.sort((a, b) => params.response.indexOf(a) - params.response.indexOf(b))
3021

31-
if (valid_paths.length === 0) {
22+
if (valid_paths.length == 0) {
3223
return null
3324
}
3425

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/relevant-files-parser/test/cases/code-blocks-valid/relevant-files.txt‎

Lines changed: 0 additions & 3 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,23 @@
11
import * as fs from 'fs'
22
import * as path from 'path'
3-
import { parse_relevant_files_from_response } from '../relevant-files-parser'
3+
import { parse_relevant_files } from '../relevant-files-parser'
44

5-
describe('response-parser', () => {
5+
describe('relevant files parser', () => {
66
const load_test_case_file = (test_case: string, filename: string): string => {
77
return fs.readFileSync(
88
path.join(__dirname, 'cases', test_case, filename),
99
'utf-8'
1010
)
1111
}
1212

13-
describe('parse_response relevant files', () => {
14-
it('filters and sorts valid paths from text', () => {
15-
const text = 'Look at src/b.ts, then src/a.ts and src/c.ts'
16-
const result = parse_relevant_files_from_response({
17-
response: text,
18-
workspace_files: ['src/a.ts', 'src/b.ts']
19-
})
20-
21-
expect(result).toMatchObject({
22-
type: 'relevant-files',
23-
file_paths: ['src/b.ts', 'src/a.ts']
24-
})
25-
})
26-
27-
it('allows code blocks if they contain valid paths', () => {
28-
const test_case = 'code-blocks-valid'
29-
const text = load_test_case_file(test_case, 'relevant-files.txt')
30-
const result = parse_relevant_files_from_response({
31-
response: text,
32-
workspace_files: ['src/hello.ts', 'src/main.ts']
33-
})
34-
35-
expect(result).toMatchObject({
36-
type: 'relevant-files',
37-
file_paths: ['src/hello.ts']
38-
})
13+
it('rejects when including code blocks', () => {
14+
const test_case = 'code-blocks-invalid'
15+
const text = load_test_case_file(test_case, 'relevant-files.txt')
16+
const result = parse_relevant_files({
17+
response: text,
18+
workspace_files: ['src/hello.ts', 'src/main.ts']
3919
})
4020

41-
it('rejects responses with code blocks that do not contain valid paths', () => {
42-
const test_case = 'code-blocks-invalid'
43-
const text = load_test_case_file(test_case, 'relevant-files.txt')
44-
const result = parse_relevant_files_from_response({
45-
response: text,
46-
workspace_files: ['src/hello.ts', 'src/main.ts']
47-
})
48-
49-
expect(result).toBeNull()
50-
})
21+
expect(result).toBeNull()
5122
})
5223
})

‎apps/editor/src/commands/apply-response-command/utils/response-parser/response-parser.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
extract_diffs,
33
parse_code_at_cursor,
44
parse_multiple_files,
5-
parse_relevant_files_from_response
5+
parse_relevant_files
66
} from './parsers'
77

88
export type FileItem = {
@@ -86,7 +86,7 @@ export const parse_response = (params: {
8686
params.is_single_root_folder_workspace ?? true
8787

8888
if (params.workspace_files) {
89-
const relevant_files = parse_relevant_files_from_response({
89+
const relevant_files = parse_relevant_files({
9090
response: params.response,
9191
workspace_files: params.workspace_files
9292
})

0 commit comments

Comments
 (0)