Skip to content

Commit 1d5f72a

Browse files
committed
Add support for parsing commit message responses and improve command concurrency handling
- In `apply-response-command.ts`, replace the 500ms `setTimeout` during preview switch by tracking the full command lifecycle with a promise that resolves in the outer `finally` block after `restore_tab_groups` and cleanup complete, awaiting that promise deterministically instead. - Fix the async race condition in apply_response_command.ts by introducing a synchronous lock (e.g., let is_initializing = true;) at the very top of the command callback before any await calls, and ensure it is released in a finally block after in_progress = true is set. - the problem is that once 'is initializing' is true, command invocations are dropped - regarding spec files: review consistency in describe/it names - some response types are not parsed by the response parser, but, fo consistency, should - add necessary tests for `apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/commit-message-parser` └── apps └── editor └── src └── commands └── apply-response-command ├── apply-response-command.ts ├── handlers │ ├── diff-handler.ts │ ├── fast-replace-handler.ts │ ├── restore-preview-handler.ts │ ├── search-replace-handler.ts │ └── truncated-handler.ts ├── index.ts ├── response-processor.ts ├── types │ └── original-file-state.ts └── utils ├── file-checks.ts ├── file-operations.ts ├── preview │ ├── diff-utils.ts │ ├── file-preparer.ts │ ├── index.ts │ ├── preview.ts │ ├── temp-file-manager.ts │ ├── types.ts │ ├── virtual-document-provider.ts │ ├── vscode-ui.ts │ └── workspace-listener.ts ├── preview-handler.ts ├── response-parser │ ├── index.ts │ ├── parsers │ │ ├── code-at-cursor-parser │ │ │ ├── code-at-cursor-parser.ts │ │ │ ├── index.ts │ │ │ └── test │ │ │ ├── cases │ │ │ │ ├── standard │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── standard.txt │ │ │ │ └── with-text │ │ │ │ ├── 1-text.txt │ │ │ │ ├── 2-file.txt │ │ │ │ ├── 3-text.txt │ │ │ │ └── with-text.txt │ │ │ └── code-at-cursor-parser.spec.ts │ │ ├── commit-message-parser │ │ │ ├── commit-message-parser.ts │ │ │ ├── index.ts │ │ │ └── test │ │ │ └── commit-message-parser.spec.ts │ │ ├── diff-parser │ │ │ ├── diff-parser.ts │ │ │ ├── helpers │ │ │ │ ├── block-utils.ts │ │ │ │ ├── index.ts │ │ │ │ ├── patch-utils.ts │ │ │ │ └── path-utils.ts │ │ │ ├── index.ts │ │ │ └── test │ │ │ ├── cases │ │ │ │ ├── deletion-via-header │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── deletion-via-header.txt │ │ │ │ ├── deletion-via-redundant-header │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── deletion-via-redundant-header.txt │ │ │ │ ├── file-deletion │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── file-deletion.txt │ │ │ │ ├── git-and-hunk-header-same-line │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── git-and-hunk-header-same-line.txt │ │ │ │ ├── git-broken-hunk-header │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── git-broken-hunk-header.txt │ │ │ │ ├── git-two-header-types │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── git-two-header-types.txt │ │ │ │ ├── ignore-ellipsis │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── ignore-ellipsis.txt │ │ │ │ ├── inner-backticks │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── inner-backticks.txt │ │ │ │ ├── inner-triple-backticks │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── inner-triple-backticks.txt │ │ │ │ ├── markdown-missing-ending │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── markdown-missing-ending.txt │ │ │ │ ├── markdown-path-above │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── markdown-path-above.txt │ │ │ │ ├── markdown-path-above-no-hunk-header │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── markdown-path-above-no-hunk-header.txt │ │ │ │ ├── markdown-path-above-with-text-containing-path │ │ │ │ │ ├── 1-text.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── markdown-path-above-with-text-containing-path.txt │ │ │ │ ├── markdown-redundant-closing-backticks │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── markdown-redundant-closing-backticks.txt │ │ │ │ ├── markdown-repeated-path-above │ │ │ │ │ ├── 1-text.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── markdown-repeated-path-above.txt │ │ │ │ ├── markdown-unnecessary-empty-lines │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── markdown-path-above.txt │ │ │ │ ├── mix-delete-and-new-file │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── mix-delete-and-new-file.txt │ │ │ │ ├── mix-new-file-from-heading-and-diff │ │ │ │ │ ├── 1-text.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ ├── 3-file.txt │ │ │ │ │ └── mix-new-file-from-heading-and-diff.txt │ │ │ │ ├── mix-new-file-from-xml-tag-heading-and-diff │ │ │ │ │ ├── 1-text.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ ├── 3-file.txt │ │ │ │ │ └── mix-new-file-from-xml-tag-heading-and-diff.txt │ │ │ │ ├── mix-new-file-xml-and-diff-variant-1 │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── mix-new-file-xml-and-diff-variant-1.txt │ │ │ │ ├── mix-new-file-xml-and-diff-variant-2 │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── mix-new-file-xml-and-diff-variant-2.txt │ │ │ │ ├── mix-rename-and-update │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── mix-rename-and-update.txt │ │ │ │ ├── mix-rename-one-liner-and-diff │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── mix-rename-one-liner-and-diff.txt │ │ │ │ ├── multiple-edits-for-the-same-file │ │ │ │ │ ├── 1-text.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-edits-for-the-same-file.txt │ │ │ │ ├── multiple-files-git-and-hunk-header-same-line │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-git-and-hunk-header-same-line.txt │ │ │ │ ├── multiple-files-no-markdown-block │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-no-markdown-block.txt │ │ │ │ ├── multiple-files-no-prefix-single-markdown-block │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-no-prefix-single-markdown-block.txt │ │ │ │ ├── multiple-files-same-line-backticks │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-same-line-backticks.txt │ │ │ │ ├── multiple-files-separate-markdown-blocks │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-separate-markdown-blocks.txt │ │ │ │ ├── multiple-files-single-markdown-block │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-single-markdown-block.txt │ │ │ │ ├── multiple-files-text-between │ │ │ │ │ ├── 1-text.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ ├── 3-text.txt │ │ │ │ │ ├── 4-file.txt │ │ │ │ │ ├── 5-text.txt │ │ │ │ │ └── multiple-files-text-between.txt │ │ │ │ ├── multiple-files-with-git-headers-no-file-lines │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-with-git-headers-no-file-lines.txt │ │ │ │ ├── multiple-files-with-git-headers-separate-markdown-blocks │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-with-git-headers-separate-markdown-blocks.txt │ │ │ │ ├── multiple-files-with-quoted-paths │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-with-quoted-paths.txt │ │ │ │ ├── multiple-files-with-timestamps │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-files-with-timestamps.txt │ │ │ │ ├── multiple-new-files-separate-markdown-blocks │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ ├── 2-file.txt │ │ │ │ │ └── multiple-new-files-separate-markdown-blocks.txt │ │ │ │ ├── new-file-based-on-empty-file │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── new-file-based-on-empty-file.txt │ │ │ │ ├── new-file-with-git-header │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── new-file-with-git-header.txt │ │ │ │ ├── no-markdown-or-git-header │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── no-markdown-or-git-header.txt │ │ │ │ ├── no-prefix │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── no-prefix.txt │ │ │ │ ├── non-diff-code-blocks │ │ │ │ │ ├── 1-text.txt │ │ │ │ │ ├── 2-inline-file.txt │ │ │ │ │ ├── 3-file.txt │ │ │ │ │ └── non-diff-code-blocks.txt │ │ │ │ ├── rename │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── rename.txt │ │ │ │ ├── with-empty-lines-between │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── with-empty-lines-between.txt │ │ │ │ ├── with-git-header-no-file-lines │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── with-git-header-no-file-lines.txt │ │ │ │ ├── with-git-header-no-markdown │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── with-git-header-no-markdown.txt │ │ │ │ ├── with-quoted-paths │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── with-quoted-paths.txt │ │ │ │ ├── with-timestamps │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── with-timestamps.txt │ │ │ │ ├── with-xml-file-path │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── with-xml-file-path.txt │ │ │ │ ├── within-xml-tags │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── within-xml-tags.txt │ │ │ │ ├── within-xml-tags-unquoted-path │ │ │ │ │ ├── 1-file.txt │ │ │ │ │ └── within-xml-tags-unquoted-path.txt │ │ │ │ └── within-xml-tags-with-cdata │ │ │ │ ├── 1-file.txt │ │ │ │ └── within-xml-tags-with-cdata.txt │ │ │ └── diff-parser.spec.ts │ │ ├── index.ts │ │ ├── intelligent-file-search-results-parser │ │ │ ├── index.ts │ │ │ └── intelligent-file-search-results-parser.ts │ │ └── standard-parser │ │ ├── helpers │ │ │ ├── create-or-update-file-item.ts │ │ │ ├── extract-and-set-workspace-path.ts │ │ │ ├── flush-text-block.ts │ │ │ └── process-conflict-markers.ts │ │ ├── index.ts │ │ ├── standard-parser.ts │ │ └── test │ │ ├── cases │ │ │ ├── conflict-with-inline-file │ │ │ │ ├── 1-file.txt │ │ │ │ ├── 2-conflict-with-inline-file.txt │ │ │ │ └── conflict-with-inline-file.txt │ │ │ ├── delete-file-header │ │ │ │ ├── 1-text.txt │ │ │ │ ├── 2-file.txt │ │ │ │ ├── 3-text.txt │ │ │ │ └── delete-file-header.txt │ │ │ ├── merge-conflicts-in-separate-code-blocks │ │ │ │ ├── 1-file.txt │ │ │ │ └── merge-conflicts-in-separate-code-blocks.txt │ │ │ ├── merge-conflicts-merge-the-same-file │ │ │ │ ├── 1-text.txt │ │ │ │ ├── 2-file.txt │ │ │ │ └── merge-conflicts-merge-the-same-file.txt │ │ │ ├── merge-conflicts-three-dots │ │ │ │ ├── 1-file.txt │ │ │ │ └── merge-conflicts-three-dots.txt │ │ │ ├── multiple-markdowns-with-headings │ │ │ │ ├── 1-file.txt │ │ │ │ ├── 2-file.txt │ │ │ │ └── multiple-markdowns-with-headings.txt │ │ │ ├── path-above-code-block │ │ │ │ ├── 1-text.txt │ │ │ │ ├── 2-file.txt │ │ │ │ └── path-above-code-block.txt │ │ │ ├── path-above-code-block-bold │ │ │ │ ├── 1-file.txt │ │ │ │ └── path-above-code-block-bold.txt │ │ │ ├── path-above-code-block-raw │ │ │ │ ├── 1-file.txt │ │ │ │ └── path-above-code-block-raw.txt │ │ │ ├── path-above-code-block-renaming │ │ │ │ ├── 1-file.txt │ │ │ │ └── path-above-code-block-renaming.txt │ │ │ ├── path-in-backticks-comment-with-intermediate-text │ │ │ │ ├── 1-text.txt │ │ │ │ ├── 2-file.txt │ │ │ │ └── path-in-backticks-comment-with-intermediate-text.txt │ │ │ ├── path-in-backticks-no-intermediate-empty-lines │ │ │ │ ├── 1-file.txt │ │ │ │ └── path-in-backticks-no-intermediate-empty-lines.txt │ │ │ └── text-below-code-block │ │ │ ├── 1-file.txt │ │ │ ├── 2-text.txt │ │ │ └── text-below-code-block.txt │ │ └── standard-parser.spec.ts │ └── response-parser.ts └── state-manager.ts
1 parent 5d3d515 commit 1d5f72a

51 files changed

Lines changed: 230 additions & 119 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 134 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import { Checkpoint } from '@/features/checkpoints/types'
3333
import { WebSocketManager } from '@/services/websocket-manager'
3434

3535
let in_progress = false
36+
let initialization_mutex = Promise.resolve()
37+
let command_lifecycle_promise: Promise<void> | null = null
38+
let resolve_command_lifecycle: (() => void) | null = null
3639

3740
interface SavedEditorState {
3841
uri: string
@@ -62,137 +65,157 @@ export const apply_response_command = (params: {
6265
return vscode.commands.registerCommand(
6366
'codeWebChat.applyResponse',
6467
async (args?: ApplyResponseCommandArgs) => {
65-
if (!vscode.workspace.workspaceFolders?.length) {
66-
vscode.window.showErrorMessage(
67-
t('command.apply-response.error.no-workspace-folder')
68-
)
69-
return
70-
}
68+
const previous_mutex = initialization_mutex
69+
let release_mutex!: () => void
70+
initialization_mutex = new Promise((resolve) => {
71+
release_mutex = resolve
72+
})
73+
74+
await previous_mutex
7175

72-
let response = args?.response
73-
if (response === undefined) {
74-
response = await vscode.env.clipboard.readText()
75-
if (!response) {
76-
vscode.window.showInformationMessage(
77-
t('command.apply-response.info.clipboard-empty')
76+
let response: string | undefined
77+
let response_items: ReturnType<typeof parse_response> = []
78+
let is_intelligent_file_search_results = false
79+
let is_code_at_cursor = false
80+
81+
try {
82+
if (!vscode.workspace.workspaceFolders?.length) {
83+
vscode.window.showErrorMessage(
84+
t('command.apply-response.error.no-workspace-folder')
7885
)
7986
return
8087
}
81-
} else if (!response) {
82-
vscode.window.showErrorMessage(
83-
t('command.apply-response.error.response-missing')
84-
)
85-
return
86-
}
8788

88-
if (response.trim().startsWith('**Commit message:**')) {
89-
const commit_message = response
90-
.trim()
91-
.substring('**Commit message:**'.length)
92-
.trim()
93-
await vscode.commands.executeCommand(
94-
'codeWebChat.internal.generateCommitMessageWithProvidedTextAndCommit',
95-
commit_message
96-
)
97-
return
98-
}
89+
response = args?.response
90+
if (response === undefined) {
91+
response = await vscode.env.clipboard.readText()
92+
if (!response) {
93+
vscode.window.showInformationMessage(
94+
t('command.apply-response.info.clipboard-empty')
95+
)
96+
return
97+
}
98+
} else if (!response) {
99+
vscode.window.showErrorMessage(
100+
t('command.apply-response.error.response-missing')
101+
)
102+
return
103+
}
99104

100-
const resolve_fn = get_response_preview_promise_resolve()
105+
while (in_progress && !get_response_preview_promise_resolve()) {
106+
await new Promise((resolve) => setTimeout(resolve, 100))
107+
}
101108

102-
if (in_progress && !resolve_fn) {
103-
return
104-
}
109+
const resolve_fn = get_response_preview_promise_resolve()
105110

106-
const is_single_root_folder_workspace =
107-
(vscode.workspace.workspaceFolders?.length ?? 0) <= 1
111+
const is_single_root_folder_workspace =
112+
(vscode.workspace.workspaceFolders?.length ?? 0) <= 1
108113

109-
const workspace_files = await get_all_workspace_files({
110-
workspace_provider: params.workspace_provider
111-
})
114+
const workspace_files = await get_all_workspace_files({
115+
workspace_provider: params.workspace_provider
116+
})
112117

113-
const response_items = parse_response({
114-
response,
115-
is_single_root_folder_workspace,
116-
workspace_files
117-
})
118+
response_items = parse_response({
119+
response,
120+
is_single_root_folder_workspace,
121+
workspace_files
122+
})
118123

119-
const is_intelligent_file_search_results = response_items.some(
120-
(i) => i.type == 'intelligent-file-search-results'
121-
)
124+
const commit_message_item = response_items.find(
125+
(i) => i.type == 'commit-message'
126+
) as any
122127

123-
const is_code_at_cursor = response_items.some(
124-
(item) => item.type == 'code-at-cursor'
125-
)
128+
if (commit_message_item) {
129+
await vscode.commands.executeCommand(
130+
'codeWebChat.internal.generateCommitMessageWithProvidedTextAndCommit',
131+
commit_message_item.message
132+
)
133+
return
134+
}
126135

127-
if (is_code_at_cursor) {
128-
const item = response_items.find(
129-
(i) => i.type == 'code-at-cursor'
130-
) as any
136+
is_intelligent_file_search_results = response_items.some(
137+
(i) => i.type == 'intelligent-file-search-results'
138+
)
131139

132-
await vscode.commands.executeCommand(
133-
'codeWebChat.internal.applyCodeAtCursor',
134-
{
135-
file_path: item.file_path,
136-
workspace_name: item.workspace_name,
137-
line: item.line,
138-
character: item.character,
139-
content: item.content
140-
}
140+
is_code_at_cursor = response_items.some(
141+
(item) => item.type == 'code-at-cursor'
141142
)
142-
return
143-
}
144143

145-
if (resolve_fn && !is_intelligent_file_search_results) {
146-
const history = params.prompt_view_provider.response_history
144+
if (is_code_at_cursor) {
145+
const item = response_items.find(
146+
(i) => i.type == 'code-at-cursor'
147+
) as any
148+
149+
await vscode.commands.executeCommand(
150+
'codeWebChat.internal.applyCodeAtCursor',
151+
{
152+
file_path: item.file_path,
153+
workspace_name: item.workspace_name,
154+
line: item.line,
155+
character: item.character,
156+
content: item.content
157+
}
158+
)
159+
return
160+
}
147161

148-
let created_at_for_switch: number
162+
if (resolve_fn && !is_intelligent_file_search_results) {
163+
const history = params.prompt_view_provider.response_history
149164

150-
if (!args?.created_at) {
151-
const new_item: ResponseHistoryItem = {
152-
response,
153-
raw_instructions: args?.raw_instructions,
154-
created_at: Date.now(),
155-
url: args?.url,
156-
recent_api_configuration: args?.recent_api_configuration,
157-
is_not_looked_at: true
158-
}
165+
let created_at_for_switch: number
159166

160-
created_at_for_switch = new_item.created_at
161-
history.push(new_item)
162-
params.prompt_view_provider.send_message({
163-
command: 'RESPONSE_HISTORY',
164-
history
165-
})
166-
} else {
167-
created_at_for_switch = args.created_at
168-
}
167+
if (!args?.created_at) {
168+
const new_item: ResponseHistoryItem = {
169+
response,
170+
raw_instructions: args?.raw_instructions,
171+
created_at: Date.now(),
172+
url: args?.url,
173+
recent_api_configuration: args?.recent_api_configuration,
174+
is_not_looked_at: true
175+
}
169176

170-
if (params.prompt_view_provider.preview_switch_choice_resolver) {
171-
// The "switch preview" modal is already visible for a previous
172-
// response. The current response has been added to the history,
173-
// so we can just return and avoid showing a second modal.
174-
return
175-
}
177+
created_at_for_switch = new_item.created_at
178+
history.push(new_item)
179+
params.prompt_view_provider.send_message({
180+
command: 'RESPONSE_HISTORY',
181+
history
182+
})
183+
} else {
184+
created_at_for_switch = args.created_at
185+
}
176186

177-
const choice = await new Promise<'Switch' | undefined>((resolve) => {
178-
params.prompt_view_provider.preview_switch_choice_resolver = resolve
179-
params.prompt_view_provider.show_preview_ongoing_modal()
180-
})
181-
params.prompt_view_provider.preview_switch_choice_resolver = undefined
187+
if (params.prompt_view_provider.preview_switch_choice_resolver) {
188+
return
189+
}
190+
191+
const choice = await new Promise<'Switch' | undefined>((resolve) => {
192+
params.prompt_view_provider.preview_switch_choice_resolver = resolve
193+
params.prompt_view_provider.show_preview_ongoing_modal()
194+
})
195+
params.prompt_view_provider.preview_switch_choice_resolver = undefined
182196

183-
if (choice == 'Switch') {
184-
args = { ...args, created_at: created_at_for_switch }
185-
resolve_fn({ accepted_files: [] })
186-
if (ongoing_preview_cleanup_promise) {
187-
await ongoing_preview_cleanup_promise
197+
if (choice == 'Switch') {
198+
args = { ...args, created_at: created_at_for_switch }
199+
resolve_fn({ accepted_files: [] })
200+
if (ongoing_preview_cleanup_promise) {
201+
await ongoing_preview_cleanup_promise
202+
}
203+
if (command_lifecycle_promise) {
204+
await command_lifecycle_promise
205+
}
206+
} else {
207+
return
188208
}
189-
await new Promise((r) => setTimeout(r, 500)) // Wait for all fileystem operation to finish
190-
} else {
191-
return
192209
}
210+
211+
in_progress = true
212+
} finally {
213+
release_mutex()
193214
}
194215

195-
in_progress = true
216+
command_lifecycle_promise = new Promise((resolve) => {
217+
resolve_command_lifecycle = resolve
218+
})
196219

197220
if (args?.created_at) {
198221
const target_created_at = args.created_at
@@ -257,7 +280,7 @@ export const apply_response_command = (params: {
257280

258281
const preview_data = await process_response({
259282
args,
260-
response,
283+
response: response!,
261284
response_items,
262285
extension_context: params.extension_context,
263286
prompt_view_provider: params.prompt_view_provider,
@@ -495,6 +518,11 @@ export const apply_response_command = (params: {
495518
checkpoint_to_delete: before_checkpoint
496519
})
497520
}
521+
if (resolve_command_lifecycle) {
522+
resolve_command_lifecycle()
523+
resolve_command_lifecycle = null
524+
command_lifecycle_promise = null
525+
}
498526
}
499527
}
500528
)

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/code-at-cursor-parser/test/code-at-cursor-parser.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parse_response } from '../../..'
22
import * as fs from 'fs'
33
import * as path from 'path'
44

5-
describe('response-parser', () => {
5+
describe('code-at-cursor-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),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export type CommitMessageItem = {
2+
type: 'commit-message'
3+
message: string
4+
}
5+
6+
export const parse_commit_message = (
7+
response: string
8+
): CommitMessageItem | null => {
9+
const trimmed = response.trim()
10+
if (trimmed.startsWith('**Commit message:**')) {
11+
const message = trimmed.substring('**Commit message:**'.length).trim()
12+
return {
13+
type: 'commit-message',
14+
message
15+
}
16+
}
17+
return null
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './commit-message-parser'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { parse_response } from '../../..'
2+
import { parse_commit_message } from '../commit-message-parser'
3+
4+
describe('commit-message-parser', () => {
5+
describe('parse_commit_message', () => {
6+
it('parses a valid commit message response', () => {
7+
const text = '**Commit message:**\nfeat: add commit message parser'
8+
const result = parse_commit_message(text)
9+
10+
expect(result).toMatchObject({
11+
type: 'commit-message',
12+
message: 'feat: add commit message parser'
13+
})
14+
})
15+
16+
it('returns null if response does not start with the prefix', () => {
17+
const text =
18+
'Some text before\n**Commit message:**\nfeat: add commit message parser'
19+
const result = parse_commit_message(text)
20+
21+
expect(result).toBeNull()
22+
})
23+
24+
it('trims whitespace around the message', () => {
25+
const text = ' **Commit message:** \n\n fix: whitespace issues \n\n'
26+
const result = parse_commit_message(text)
27+
28+
expect(result).toMatchObject({
29+
type: 'commit-message',
30+
message: 'fix: whitespace issues'
31+
})
32+
})
33+
})
34+
35+
describe('parse_response integration', () => {
36+
it('returns a commit message item when parsing a valid commit message response', () => {
37+
const text = '**Commit message:**\nchore: update dependencies'
38+
const result = parse_response({
39+
response: text,
40+
is_single_root_folder_workspace: true
41+
})
42+
43+
expect(result).toHaveLength(1)
44+
expect(result[0]).toMatchObject({
45+
type: 'commit-message',
46+
message: 'chore: update dependencies'
47+
})
48+
})
49+
})
50+
})

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/test/diff-parser.spec.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ describe('diff-parser', () => {
1010
)
1111
}
1212

13-
it('parses diff format without markdown code block or git header', () => {
13+
describe('parse_response', () => {
14+
it('parses diff format without markdown code block or git header', () => {
1415
const test_case = 'no-markdown-or-git-header'
1516
const text = load_test_case_file(test_case, `${test_case}.txt`)
1617
const result = parse_response({
@@ -961,4 +962,5 @@ describe('diff-parser', () => {
961962
content: load_test_case_file(test_case, '1-file.txt')
962963
})
963964
})
965+
})
964966
})

0 commit comments

Comments
 (0)