Change:
<!-- Do Not Delete This! bugreporttemplate --<!-- Please read our Rules of Conduct: --<!-- Read our guide about submitting issues: --<!-- Search existing issues to avoid creating duplicates. --<!-- Test using the latest Insiders build to see if your issue has already been fixed: --<!-- Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. --<!-- Launch with to check. --Does this issue occur when all extensions are disabled?: Yes <!-- If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. --<!-- Issues caused by an extension need to be reported directly to the extension publisher. The 'Help Report Issue' dialog can assist with this. --- VS Code Version: Version: 1.84.0 (system setup) OS: WindowsNT x64 10.0. Steps to Reproduce: "Add to Workspace Recommendations" any extension and select whichever place you like (i.e. among workspace & workspace folder) the or some comments inside_ the array once step 1. the comment from step 3. got erased. <!-- -- Titles & summaries: "add to rec" removes comments from extensions-recommendations array in the configuration file "add to rec" rewrites & hence erases any comments in extensions-recommendations array "add to rec" rewrites & hence erases any comments in Sample file:
Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.84.2. Please try upgrading to the latest version and checking whether this issue remains. Happy Coding!
i wish there were patch updates if i have to update that frequently
p.s.: wow, never tried doing it from command palette pps: i think that no longer exists now
thanks all a lot

Discussion:
import { distinct, flatten } from 'vs/base/common/arrays'; import { Emitter, Event } from 'vs/base/common/event'; <del> import { parse } from 'vs/base/common/json'; </del> <ins> import { JSONPath, parse } from 'vs/base/common/json'; </ins> import { Disposable } from 'vs/base/common/lifecycle'; import { getIconClasses } from 'vs/editor/common/services/getIconClasses'; import { FileKind, IFileService } from 'vs/platform/files/common/files';

private async addOrRemoveWorkspaceFolderRecommendation(extensionId: string, workspaceFolder: IWorkspaceFolder, extensionsConfigContent: IExtensionsConfigContent, add: boolean): Promise<void> { const values: IJSONValue[] = []; if (add) { <del> values.push({ path: ['recommendations'], value: [...extensionsConfigContent.recommendations || [], extensionId] }); if (extensionsConfigContent.unwantedRecommendations && extensionsConfigContent.unwantedRecommendations.some(e => e === extensionId)) { values.push({ path: ['unwantedRecommendations'], value: extensionsConfigContent.unwantedRecommendations.filter(e => e !== extensionId) }); </del> <ins> if (Array.isArray(extensionsConfigContent.recommendations)) { values.push({ path: ['recommendations', -1], value: extensionId }); } else { values.push({ path: ['recommendations'], value: [extensionId] }); } const unwantedRecommendationEdit = this.getEditToRemoveValueFromArray(['unwantedRecommendations'], extensionsConfigContent.unwantedRecommendations, extensionId); if (unwantedRecommendationEdit) { values.push(unwantedRecommendationEdit); </ins> } } else if (extensionsConfigContent.recommendations) { <del> values.push({ path: ['recommendations'], value: extensionsConfigContent.recommendations.filter(e => e !== extensionId) }); </del> <ins> const recommendationEdit = this.getEditToRemoveValueFromArray(['recommendations'], extensionsConfigContent.recommendations, extensionId); if (recommendationEdit) { values.push(recommendationEdit); } </ins> } if (values.length) {

const values: IJSONValue[] = []; if (extensionsConfigContent) { if (add) { <del> values.push({ path: ['extensions', 'recommendations'], value: [...extensionsConfigContent.recommendations || [], extensionId] }); if (extensionsConfigContent.unwantedRecommendations && extensionsConfigContent.unwantedRecommendations.some(e => e === extensionId)) { values.push({ path: ['extensions', 'unwantedRecommendations'], value: extensionsConfigContent.unwantedRecommendations.filter(e => e !== extensionId) }); </del> <ins> const path: JSONPath = ['extensions', 'recommendations']; if (Array.isArray(extensionsConfigContent.recommendations)) { values.push({ path: [...path, -1], value: extensionId }); } else { values.push({ path, value: [extensionId] }); } const unwantedRecommendationEdit = this.getEditToRemoveValueFromArray(['extensions', 'unwantedRecommendations'], extensionsConfigContent.unwantedRecommendations, extensionId); if (unwantedRecommendationEdit) { values.push(unwantedRecommendationEdit); </ins> } } else if (extensionsConfigContent.recommendations) { <del> values.push({ path: ['extensions', 'recommendations'], value: extensionsConfigContent.recommendations.filter(e => e !== extensionId) }); </del> <ins> const recommendationEdit = this.getEditToRemoveValueFromArray(['extensions', 'recommendations'], extensionsConfigContent.recommendations, extensionId); if (recommendationEdit) { values.push(recommendationEdit); } </ins> } } else if (add) { values.push({ path: ['extensions'], value: { recommendations: [extensionId] } });

private async addOrRemoveWorkspaceFolderUnwantedRecommendation(extensionId: string, workspaceFolder: IWorkspaceFolder, extensionsConfigContent: IExtensionsConfigContent, add: boolean): Promise<void> { const values: IJSONValue[] = []; if (add) { <del> values.push({ path: ['unwantedRecommendations'], value: [...extensionsConfigContent.unwantedRecommendations || [], extensionId] }); if (extensionsConfigContent.recommendations && extensionsConfigContent.recommendations.some(e => e === extensionId)) { values.push({ path: ['recommendations'], value: extensionsConfigContent.recommendations.filter(e => e !== extensionId) }); </del> <ins> const path: JSONPath = ['unwantedRecommendations']; if (Array.isArray(extensionsConfigContent.unwantedRecommendations)) { values.push({ path: [...path, -1], value: extensionId }); } else { values.push({ path, value: [extensionId] }); } const recommendationEdit = this.getEditToRemoveValueFromArray(['recommendations'], extensionsConfigContent.recommendations, extensionId); if (recommendationEdit) { values.push(recommendationEdit); </ins> } } else if (extensionsConfigContent.unwantedRecommendations) { <del> values.push({ path: ['unwantedRecommendations'], value: extensionsConfigContent.unwantedRecommendations.filter(e => e !== extensionId) }); </del> <ins> const unwantedRecommendationEdit = this.getEditToRemoveValueFromArray(['unwantedRecommendations'], extensionsConfigContent.unwantedRecommendations, extensionId); if (unwantedRecommendationEdit) { values.push(unwantedRecommendationEdit); } </ins> } if (values.length) { return this.jsonEditingService.write(workspaceFolder.toResource(EXTENSIONS_CONFIG), values, true);

const values: IJSONValue[] = []; if (extensionsConfigContent) { if (add) { <del> values.push({ path: ['extensions', 'unwantedRecommendations'], value: [...extensionsConfigContent.unwantedRecommendations || [], extensionId] }); if (extensionsConfigContent.recommendations && extensionsConfigContent.recommendations.some(e => e === extensionId)) { values.push({ path: ['extensions', 'recommendations'], value: extensionsConfigContent.recommendations.filter(e => e !== extensionId) }); </del> <ins> const path: JSONPath = ['extensions', 'unwantedRecommendations']; if (Array.isArray(extensionsConfigContent.recommendations)) { values.push({ path: [...path, -1], value: extensionId }); } else { values.push({ path, value: [extensionId] }); } const recommendationEdit = this.getEditToRemoveValueFromArray(['extensions', 'recommendations'], extensionsConfigContent.recommendations, extensionId); if (recommendationEdit) { values.push(recommendationEdit); </ins> } } else if (extensionsConfigContent.unwantedRecommendations) { <del> values.push({ path: ['extensions', 'unwantedRecommendations'], value: extensionsConfigContent.unwantedRecommendations.filter(e => e !== extensionId) }); </del> <ins> const unwantedRecommendationEdit = this.getEditToRemoveValueFromArray(['extensions', 'unwantedRecommendations'], extensionsConfigContent.unwantedRecommendations, extensionId); if (unwantedRecommendationEdit) { values.push(unwantedRecommendationEdit); } </ins> } } else if (add) { values.push({ path: ['extensions'], value: { unwantedRecommendations: [extensionId] } });

}; } <ins> private getEditToRemoveValueFromArray(path: JSONPath, array: string[] | undefined, value: string): IJSONValue | undefined { const index = array?.indexOf(value); if (index !== undefined && index !== -1) { return { path: [...path, index], value: undefined }; } return undefined; } </ins> } registerSingleton(IWorkspaceExtensionsConfigService, WorkspaceExtensionsConfigService, InstantiationType.Delayed);