Skip to content

Commit 83d357b

Browse files
committed
Rename "code completion" to "code at cursor" across all related files and functionality
1 parent 0fbecc0 commit 83d357b

20 files changed

Lines changed: 75 additions & 68 deletions

File tree

apps/editor/src/commands/apply-chat-response-command/apply-chat-response-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const apply_chat_response_command = (params: {
136136
(item) =>
137137
item.type == 'diff' ||
138138
item.type == 'file' ||
139-
item.type == 'completion'
139+
item.type == 'code-at-cursor'
140140
)
141141

142142
if (has_content_to_preview) {

apps/editor/src/commands/apply-chat-response-command/response-processor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ export const process_chat_response = async (
322322

323323
return null
324324
} else {
325-
if (clipboard_items.some((item) => item.type == 'completion')) {
325+
if (clipboard_items.some((item) => item.type == 'code-at-cursor')) {
326326
const completion = clipboard_items.find(
327-
(item) => item.type == 'completion'
327+
(item) => item.type == 'code-at-cursor'
328328
)!
329329
const workspace_map = new Map<string, string>()
330330
vscode.workspace.workspaceFolders!.forEach((folder) => {

apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ describe('clipboard-parser', () => {
11201120

11211121
expect(result).toHaveLength(1)
11221122
expect(result[0]).toMatchObject({
1123-
type: 'completion',
1123+
type: 'code-at-cursor',
11241124
file_path: 'src/index.ts',
11251125
line: 25,
11261126
character: 5,
@@ -1146,7 +1146,7 @@ describe('clipboard-parser', () => {
11461146
content: load_test_case_file('completions', test_case, '1-text.txt')
11471147
})
11481148
expect(result[1]).toMatchObject({
1149-
type: 'completion',
1149+
type: 'code-at-cursor',
11501150
file_path: 'src/index.ts',
11511151
line: 25,
11521152
character: 5,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
extract_diffs,
3-
parse_code_completion,
3+
parse_code_at_cursor,
44
parse_multiple_files,
55
parse_relevant_files
66
} from './parsers'
@@ -22,8 +22,8 @@ export type DiffItem = {
2222
new_file_path?: string
2323
}
2424

25-
export type CompletionItem = {
26-
type: 'completion'
25+
export type CodeAtCursorItem = {
26+
type: 'code-at-cursor'
2727
file_path: string
2828
content: string
2929
line: number
@@ -50,7 +50,7 @@ export type InlineFileItem = {
5050
export type ClipboardItem =
5151
| FileItem
5252
| DiffItem
53-
| CompletionItem
53+
| CodeAtCursorItem
5454
| TextItem
5555
| InlineFileItem
5656
| RelevantFilesItem
@@ -82,13 +82,13 @@ export const parse_response = (params: {
8282
const is_single_root_folder_workspace =
8383
params.is_single_root_folder_workspace ?? true
8484

85-
const code_completion_items = parse_code_completion({
85+
const code_at_cursor_items = parse_code_at_cursor({
8686
response: params.response,
8787
is_single_root_folder_workspace
8888
})
8989

90-
if (code_completion_items && code_completion_items.length > 0) {
91-
return code_completion_items
90+
if (code_at_cursor_items && code_at_cursor_items.length > 0) {
91+
return code_at_cursor_items
9292
}
9393

9494
const relevant_files = parse_relevant_files({ response: params.response })

apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/code-completion-parser.ts renamed to apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/code-at-cursor-parser.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { cleanup_api_response } from '@/utils/cleanup-api-response'
22
import {
3-
CompletionItem,
3+
CodeAtCursorItem,
44
TextItem,
55
extract_workspace_and_path
66
} from '../clipboard-parser'
77

88
const extract_path_and_position = (
99
line: string
1010
): { path: string; line: number; character: number } | null => {
11-
const path_pos_regex =
12-
/###\s+Code completion:\s+`?([^`]+)`?\s+\((\d+):(\d+)\)/
11+
const path_pos_regex = /###\s+Code at cursor:\s+`?([^`]+)`?\s+\((\d+):(\d+)\)/
1312

1413
const match = line.match(path_pos_regex)
1514

@@ -29,10 +28,10 @@ const extract_path_and_position = (
2928
return null
3029
}
3130

32-
export const parse_code_completion = (params: {
31+
export const parse_code_at_cursor = (params: {
3332
response: string
3433
is_single_root_folder_workspace: boolean
35-
}): (CompletionItem | TextItem)[] | null => {
34+
}): (CodeAtCursorItem | TextItem)[] | null => {
3635
const lines = params.response.split('\n')
3736
let code_block_start_index = -1
3837
let code_block_end_index = -1
@@ -75,7 +74,7 @@ export const parse_code_completion = (params: {
7574
return null
7675
}
7776

78-
const results: (CompletionItem | TextItem)[] = []
77+
const results: (CodeAtCursorItem | TextItem)[] = []
7978
const text_before = lines.slice(0, header_index).join('\n').trim()
8079
if (text_before) {
8180
results.push({ type: 'text', content: text_before })
@@ -92,7 +91,7 @@ export const parse_code_completion = (params: {
9291
)
9392

9493
results.push({
95-
type: 'completion',
94+
type: 'code-at-cursor',
9695
file_path: relative_path,
9796
content: cleanup_api_response({ content: content_lines.join('\n') }),
9897
line: completion_info.line,

apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './code-completion-parser'
1+
export * from './code-at-cursor-parser'
22
export * from './file-content-only-parser'
33
export * from './multiple-files-parser/multiple-files-parser'
44
export * from './diff-parser/diff-parser'

apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/completions/code-completion-with-text/code-completion-with-text.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Some text before.
22

3-
### Code completion: `src/index.ts` (25:5)
3+
### Code at cursor: `src/index.ts` (25:5)
44

55
```typescript
66
console.log("completion");

apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/completions/code-completion/code-completion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Code completion: `src/index.ts` (25:5)
1+
### Code at cursor: `src/index.ts` (25:5)
22

33
```typescript
44
console.log("completion");

apps/editor/src/commands/apply-chat-response-command/utils/preview/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const preview = async (params: {
9494
} else if (
9595
item.type == 'file' ||
9696
item.type == 'diff' ||
97-
item.type == 'completion'
97+
item.type == 'code-at-cursor'
9898
) {
9999
const key = is_single_root_folder_workspace
100100
? item.file_path

apps/editor/src/constants/instructions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ export const code_at_cursor_instructions_for_panel = (
88
) =>
99
`Find correct replacement text for the <missing_text> symbol.
1010
<system>
11-
Your response must begin with a markdown heading identifying the file and the cursor position, followed by a markdown code block containing the replacement text, followed by a brief explanation. The heading must be: "### Code completion: \`${file_path}\` (${
11+
Your response must begin with a markdown heading identifying the file and the cursor position, followed by a markdown code block containing the replacement text, followed by a brief explanation. The heading must be: "### Code at cursor: \`${file_path}\` (${
1212
row + 1
1313
}:${
1414
column + 1
1515
})". Always refer to the symbol "<missing_text>" as "cursor position" and "replacement" as "completion". Example:
1616
17-
### Code completion: \`${file_path}\` (${row + 1}:${column + 1})
17+
### Code at cursor: \`${file_path}\` (${row + 1}:${column + 1})
1818
1919
\`\`\`typescript
2020
!== undefined

0 commit comments

Comments
 (0)