Skip to content

Commit a6112c7

Browse files
committed
Ensure all opened files are displayed in non-preview mode
1 parent 6376893 commit a6112c7

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

packages/vscode/src/commands/apply-chat-response-command/apply-chat-response-command.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ async function handle_code_completion(completion: {
315315

316316
try {
317317
const document = await vscode.workspace.openTextDocument(safe_path)
318-
const editor = await vscode.window.showTextDocument(document)
318+
const editor = await vscode.window.showTextDocument(document, {
319+
preview: false
320+
})
319321

320322
// VSCode position is 0-based, so we subtract 1
321323
const line_index = completion.line - 1

packages/vscode/src/commands/apply-chat-response-command/utils/diff-patch-processor.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ const apply_diff_patch = (
312312
replace_chunks.pop()
313313
}
314314

315-
if (search_chunks.length != 0 || replace_chunks.length != 0) // Don't add search or replace blocks if empty
316-
{
315+
if (search_chunks.length != 0 || replace_chunks.length != 0) {
316+
// Don't add search or replace blocks if empty
317317
// Add the final search block to the searchReplaceBlocks
318318
// This is crucial for diffs that only have deletions
319319
search_replace_blocks.push(
@@ -343,24 +343,24 @@ const apply_diff_patch = (
343343
j++
344344
) {
345345
// Create a chunk of lines from originalCodeLinesNormalized
346-
const chunk = original_code_lines_normalized.slice(
347-
j,
348-
j + search_replace_block.search_lines.length
349-
)
350-
const chunk_string = chunk.map((line) => line.value).join('')
346+
// const chunk = original_code_lines_normalized.slice(
347+
// j,
348+
// j + search_replace_block.search_lines.length
349+
// )
350+
// const chunk_string = chunk.map((line) => line.value).join('')
351351

352352
// console.log('Chunk string: ' + chunk_string);
353353

354354
// If we have no search lines and only replace lines and our previous found index is 0
355355
// assume we are at the start of the file and set the search block start index to 0
356356
// This is a special case when a patch hunk starts with one or more + lines and no context lines
357-
if (search_replace_block.search_lines.length == 0 && previous_found_index == 0)
358-
{
357+
if (
358+
search_replace_block.search_lines.length == 0 &&
359+
previous_found_index == 0
360+
) {
359361
search_replace_block.search_block_start_index = -1 // insert at the start of the file
360362
found = true
361-
}
362-
else
363-
{
363+
} else {
364364
// Create a chunk of lines from originalCodeLinesNormalized
365365
const chunk = original_code_lines_normalized.slice(
366366
j,
@@ -372,7 +372,7 @@ const apply_diff_patch = (
372372
//console.log('Chunk string: ' + chunk_string);
373373
//console.log('Previous found index: ' + previous_found_index);
374374
//console.log('Chunk: ' + JSON.stringify(chunk, null, 2));
375-
375+
376376
// Check if the chunk matches the search string
377377
if (chunk_string == search_string) {
378378
// Check if found index is greater than the previous found index
@@ -397,7 +397,7 @@ const apply_diff_patch = (
397397
if (!found) {
398398
search_replace_block.search_block_start_index = -2 // Not found
399399

400-
const error_message = `Search block not found: ${search_string}`
400+
const error_message = `Search block not found: ${search_string}`
401401
Logger.error({
402402
function_name: 'apply_diff_patch',
403403
message: error_message
@@ -426,7 +426,8 @@ const apply_diff_patch = (
426426

427427
// Iterrate over the valid blocks and apply them
428428
for (const block of valid_blocks) {
429-
const start_index = block.get_start_index() == -1 ? 0 : block.get_start_index() // When -1, insert at the start of the file
429+
const start_index =
430+
block.get_start_index() == -1 ? 0 : block.get_start_index() // When -1, insert at the start of the file
430431
const search_count = block.get_search_count()
431432
const replacement_content = block.replace_lines // These are original lines
432433

packages/vscode/src/commands/apply-chat-response-command/utils/patch-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async function process_modified_files(
150150
try {
151151
const uri = vscode.Uri.file(safe_path)
152152
const document = await vscode.workspace.openTextDocument(uri)
153-
await vscode.window.showTextDocument(document)
153+
await vscode.window.showTextDocument(document, { preview: false })
154154

155155
// Format the document
156156
await format_document(document)

0 commit comments

Comments
 (0)