@@ -77,26 +77,13 @@ async function tryWriteGlobalDocumentationFile(
7777 // Ensure directory exists
7878 await vscode . workspace . fs . createDirectory ( vscode . Uri . file ( path . dirname ( targetUri . fsPath ) ) ) ;
7979
80- // Read existing content (if any)
81- let existingContent = "" ;
82- try {
83- const buffer = await vscode . workspace . fs . readFile ( targetUri ) ;
84- existingContent = Buffer . from ( buffer ) . toString ( "utf8" ) ;
85- } catch ( readError : unknown ) {
86- // If the file doesn't exist, proceed without error
87- if ( ! ( readError instanceof vscode . FileSystemError ) || readError . code !== "FileNotFound" ) {
88- throw readError ;
89- }
90- }
91-
92- // Normalize line breaks for the current OS
80+ // Normalize line breaks for the current OS and build content.
81+ // Overwrite file content instead of appending.
9382 const normalizedContent = content . split ( / \r ? \n / ) . join ( EOL ) ;
94- const newSection = `${ GLOBAL_DOC_HEADER } ${ EOL } ${ normalizedContent } ${ EOL } ` ;
95- const needsSeparator = existingContent . length > 0 && ! existingContent . endsWith ( EOL . repeat ( 2 ) ) ;
96- const separator = needsSeparator ? EOL . repeat ( 2 ) : "" ;
97- const combinedContent = existingContent ? `${ existingContent } ${ separator } ${ newSection } ` : newSection ;
83+ const newContent = `${ GLOBAL_DOC_HEADER } ${ EOL } ${ normalizedContent } ${ EOL } ` ;
9884
99- await vscode . workspace . fs . writeFile ( targetUri , Buffer . from ( combinedContent , "utf8" ) ) ;
85+ // This write overwrites any previous content
86+ await vscode . workspace . fs . writeFile ( targetUri , Buffer . from ( newContent , "utf8" ) ) ;
10087
10188 // Open the file beside for editing
10289 const document = await vscode . workspace . openTextDocument ( targetUri ) ;
0 commit comments