Repository: microsoft/vscode (TypeScript) — Bug Fix

Issue:
Partial Profile created by settings unchecked (thus Settings using default profile) doesn't respect setting items which is described  with "Applies to all profiles"
<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` 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: 1.82.0-insider
Commit: 1606401f5b761397488f53b75130809fba073194
Date: 2023-08-07T05:34:01.211Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Linux x64 5.15.0-78-generic
- OS version: ubuntu 22.04.3 LTS

Steps to Reproduce:

1. change "Title Bar Style" settings of default profile to "custom"
2.  create a new profile, and uncheck settings(means using default profile settings). 
![image](https://github.com/microsoft/vscode/assets/9946624/d6128b6b-c395-4ad4-aa78-f73d1e324613)

3.  when click creat button, a pop up windows says "a settings has changed that requires a restart to take effect  vscode"
![image](https://github.com/microsoft/vscode/assets/9946624/2c42dd76-9fb3-48b3-aaaf-6562a78ec6a7)

4. click restart, and check "Title Bar Style" settings, find it is native ,and can't be changed. 
5. every time switch  profiles between default and other created profiled will popup the annoying  "a settings has changed that requires a restart to take effect  vscode" window, and only the default profile shows the custom title bar. 




Discussion:
i start use user profile since 1.81.0, and i don't know if such bug also appears on early version.  besides, vscode don't have this bug  when on windows 11.
actually this bug is very annoying ,because, when switch to user profile whose "Title Bar Style" settings is forced to native,  it has no menu bar at all! user can't do many operation throuth menu bar, because it is not there at all.  every thing is right when in default profile.

![image](https://github.com/microsoft/vscode/assets/9946624/fd4a3ced-e463-4c42-a3f7-1f1ec6a925ce)

it seems that windows 11 also has this problems. but the default "Title Bar Style" settings on windows is "custom",so it appears normally when switch between profiles (default profile "Title Bar Style" setting is custom ).   
i also find that when in user profile, change "Title Bar Style" settings in UI dose change settings.json contents, but it just don't influence the user profile currently on , it only influence default profile.
a guess is that when a profile is created with settings unchecked(use default profile settings), all settings with description " Applies to all profiles" will be forced to default value when the profile is switched on.

![image](https://github.com/microsoft/vscode/assets/9946624/398d596f-54b0-4e63-b679-56a58c5ab991)

it seems that this issue #189725  is the same bug with me
I suggest toggling `[ ] Settings` and using symlink as a workaround for now.

```bash
ln -srf ~/.config/Code/User/settings.json ~/.config/Code/User/profiles/$(jq --arg v <profile_name> -r '.userDataProfiles | .[] | select(.name==$v) | .location '  ~/.config/Code/User/globalStorage/storage.json)/settings.json
```
- note: *\<profile_name\>* is a placeholder, replace with appropriate value

![image](https://github.com/microsoft/vscode/assets/118117622/d7489551-5d44-4c6b-b055-514428054853)
I think I have the same problem or at least it's similar, it just happens the other way around... By default, I have the menu bar hidden, but when I create other profiles, the bar becomes visible. 🤔
Default profile
![image](https://github.com/microsoft/vscode/assets/60621046/54620c1a-e785-4b6d-9ee6-fa65d7ca9d63)

Other profile
![image](https://github.com/microsoft/vscode/assets/60621046/596ea774-ff0f-4cc0-a216-3bda726ae922)

To verify:

- Open window with default profile
- Change `update.mode` setting to non default value
- Restart application
- Create a profile that uses settings from default profile
- Make sure the application is not asked to restart
- Make sure the value of `update.mode` setting is set to the value that was set before.

Resolving patch:
diff --git a/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts b/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts
--- a/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts
+++ b/src/vs/workbench/contrib/preferences/browser/settingsTreeModels.ts
@@ -273,7 +273,7 @@ export class SettingsTreeSettingElement extends SettingsTreeElement {
 	}
 
 	private getTargetToInspect(setting: ISetting): SettingsTarget {
-		if (!this.userDataProfileService.currentProfile.isDefault) {
+		if (!this.userDataProfileService.currentProfile.isDefault && !this.userDataProfileService.currentProfile.useDefaultFlags?.settings) {
 			if (setting.scope === ConfigurationScope.APPLICATION) {
 				return ConfigurationTarget.APPLICATION;
 			}
diff --git a/src/vs/workbench/services/configuration/browser/configurationService.ts b/src/vs/workbench/services/configuration/browser/configurationService.ts
--- a/src/vs/workbench/services/configuration/browser/configurationService.ts
+++ b/src/vs/workbench/services/configuration/browser/configurationService.ts
@@ -47,7 +47,7 @@ import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/envir
 import { workbenchConfigurationNodeBase } from 'vs/workbench/common/configuration';
 
 function getLocalUserConfigurationScopes(userDataProfile: IUserDataProfile, hasRemote: boolean): ConfigurationScope[] | undefined {
-	return userDataProfile.isDefault
+	return (userDataProfile.isDefault || userDataProfile.useDefaultFlags?.settings)
 		? hasRemote ? LOCAL_MACHINE_SCOPES : undefined
 		: hasRemote ? LOCAL_MACHINE_PROFILE_SCOPES : PROFILE_SCOPES;
 }


Test patch:
diff --git a/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts b/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts
--- a/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts
+++ b/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts
@@ -1774,6 +1774,22 @@ suite('WorkspaceConfigurationService - Profiles', () => {
 		assert.strictEqual(testObject.getValue('configurationService.profiles.testSetting'), 'profileValue2');
 	}));
 
+	test('switch to non default profile using settings from default profile', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
+		await fileService.writeFile(instantiationService.get(IUserDataProfilesService).defaultProfile.settingsResource, VSBuffer.fromString('{ "configurationService.profiles.applicationSetting": "applicationValue", "configurationService.profiles.testSetting": "userValue" }'));
+		await fileService.writeFile(userDataProfileService.currentProfile.settingsResource, VSBuffer.fromString('{ "configurationService.profiles.applicationSetting": "profileValue", "configurationService.profiles.testSetting": "profileValue" }'));
+		await testObject.reloadConfiguration();
+
+		const profile = toUserDataProfile('custom3', 'custom3', joinPath(environmentService.userRoamingDataHome, 'profiles', 'custom2'), joinPath(environmentService.cacheHome, 'profilesCache'), { useDefaultFlags: { settings: true } }, instantiationService.get(IUserDataProfilesService).defaultProfile);
+		await fileService.writeFile(profile.settingsResource, VSBuffer.fromString('{ "configurationService.profiles.applicationSetting": "applicationValue2", "configurationService.profiles.testSetting": "profileValue2" }'));
+		const promise = Event.toPromise(testObject.onDidChangeConfiguration);
+		await userDataProfileService.updateCurrentProfile(profile);
+
+		const changeEvent = await promise;
+		assert.deepStrictEqual([...changeEvent.affectedKeys], ['configurationService.profiles.applicationSetting', 'configurationService.profiles.testSetting']);
+		assert.strictEqual(testObject.getValue('configurationService.profiles.applicationSetting'), 'applicationValue2');
+		assert.strictEqual(testObject.getValue('configurationService.profiles.testSetting'), 'profileValue2');
+	}));
+
 	test('In non-default profile, changing application settings shall include only application scope settings in the change event', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
 		await fileService.writeFile(instantiationService.get(IUserDataProfilesService).defaultProfile.settingsResource, VSBuffer.fromString('{}'));
 		await testObject.reloadConfiguration();