@@ -119,17 +119,20 @@ export async function applyChanges(doc: vscode.TextDocument, range: vscode.Range
119119}
120120
121121/**
122- * Creates a temporary file for diff comparison by cloning the original file.
123- * This is the base implementation used by other diff-related functions .
122+ * Creates a temporary file for diff comparison by cloning the original file
123+ * and applying the proposed changes within the selected range .
124124 *
125125 * @param {vscode.Uri } originalFileUri - The URI of the original file.
126- * @param {string } scheme - The URI scheme to use for the temporary file.
127- * @returns {Promise<{tempFileUri: vscode.Uri, doc: vscode.TextDocument}> } - A promise that resolves to the URI of the temporary file and the document.
126+ * @param {any } message - The message object containing the proposed code changes.
127+ * @param {vscode.Selection } selection - The selection range in the document where the changes are applied.
128+ * @returns {Promise<vscode.Uri> } - A promise that resolves to the URI of the temporary file.
128129 */
129- async function createTempFileForDiffBase (
130+ export async function createTempFileForDiff (
130131 originalFileUri : vscode . Uri ,
132+ message : any ,
133+ selection : vscode . Selection ,
131134 scheme : string
132- ) : Promise < { tempFileUri : vscode . Uri ; doc : vscode . TextDocument } > {
135+ ) : Promise < vscode . Uri > {
133136 const errorCode = 'createTempFile'
134137 const id = Date . now ( )
135138 const languageId = ( await vscode . workspace . openTextDocument ( originalFileUri ) ) . languageId
@@ -149,7 +152,7 @@ async function createTempFileForDiffBase(
149152 throw ToolkitError . chain ( error , 'Failed to write to temp file' , { code : errorCode } )
150153 }
151154
152- // Open the temp file as a document
155+ // Apply the proposed changes to the temp file
153156 const doc = await vscode . workspace . openTextDocument ( tempFileUri . path )
154157 const languageIdStatus = await vscode . languages . setTextDocumentLanguage ( doc , languageId )
155158 if ( languageIdStatus ) {
@@ -158,60 +161,13 @@ async function createTempFileForDiffBase(
158161 getLogger ( ) . error ( 'Diff: Unable to set languageId for %s to: %s' , tempFileUri . fsPath , languageId )
159162 }
160163
161- return { tempFileUri, doc }
162- }
163-
164- /**
165- * Creates a temporary file for diff comparison by cloning the original file
166- * and applying the proposed changes within the selected range.
167- *
168- * @param {vscode.Uri } originalFileUri - The URI of the original file.
169- * @param {any } message - The message object containing the proposed code changes.
170- * @param {vscode.Selection } selection - The selection range in the document where the changes are applied.
171- * @param {string } scheme - The URI scheme to use for the temporary file.
172- * @returns {Promise<vscode.Uri> } - A promise that resolves to the URI of the temporary file.
173- */
174- export async function createTempFileForDiff (
175- originalFileUri : vscode . Uri ,
176- message : any ,
177- selection : vscode . Selection ,
178- scheme : string
179- ) : Promise < vscode . Uri > {
180- const { tempFileUri, doc } = await createTempFileForDiffBase ( originalFileUri , scheme )
181-
182164 const code = getIndentedCode ( message , doc , selection )
183165 const range = getSelectionFromRange ( doc , selection )
184166
185167 await applyChanges ( doc , range , code )
186168 return tempFileUri
187169}
188170
189- /**
190- * Creates a temporary file for diff comparison by cloning the original file
191- * and replacing the entire content with the provided content.
192- *
193- * @param {vscode.Uri } originalFileUri - The URI of the original file.
194- * @param {string } content - The content to replace the entire document with.
195- * @param {string } scheme - The URI scheme to use for the temporary file.
196- * @returns {Promise<vscode.Uri> } - A promise that resolves to the URI of the temporary file.
197- */
198- export async function createTempFileForDiffWithContent (
199- originalFileUri : vscode . Uri ,
200- content : string ,
201- scheme : string
202- ) : Promise < vscode . Uri > {
203- const { tempFileUri, doc } = await createTempFileForDiffBase ( originalFileUri , scheme )
204-
205- // Create a range that covers the entire document
206- const entireDocumentRange = new vscode . Range (
207- new vscode . Position ( 0 , 0 ) ,
208- new vscode . Position ( doc . lineCount - 1 , doc . lineAt ( doc . lineCount - 1 ) . text . length )
209- )
210-
211- await applyChanges ( doc , entireDocumentRange , content )
212- return tempFileUri
213- }
214-
215171/**
216172 * Indents the given code based on the current document's indentation at the selection start.
217173 *
0 commit comments