Repository: microsoft/vscode (TypeScript)
Date: 2023-01-17 16:29:13+00:00
Task type: Bug Fix

Issue:
`WorkspaceConfiguration.get` & `WorkspaceConfiguration.inspect` seems to return the wrong values when using Profiles
I'm not sure if this only applies when debugging or not, but here is the setup when this happens:

1. Set a setting, e.g. `"gitlens.graph.dimMergeCommits": true` in the default profile
2. Create a new <whatever> profile, and ensure that the above setting doesn't exist in it
3. Open the code to an extension (that will call `WorkspaceConfiguration.[get|inspect]`) in a window on the default profile
4. Start debugging the extension a launch config with `--profile=<whatever>`
5. :bug: see that `workspace.getConfiguration('gitlens').inspect('graph.dimMergeCommits') will return an object with a `globalValue` of `true`, but that is not correct because the profile doesn't have that setting set, and the default is `false`
6. :bug: see that `workspace.getConfiguration('gitlens').get('graph.dimMergeCommits') will return `true`, but it should be `false`

Things seem to work fine as long as the default profile doesn't have the value set, but once it does you get the behavior above.

/cc @sandy081 


Issue discussion:
Based on what I could notice, it doesn’t seem to be a _debug only_ issue. 

It isn’t a problem for most of my extensions (at least no user complained up until now) but I noticed such behavior while working with my Project Manager extension, because the `globalStorageUri` value doesn’t respect the current profile. Then, looking a bit more, I noticed such conflict too, which blocks me from use different settings for each profile, unfortunately.

BTW, I created https://github.com/microsoft/vscode/issues/160466 to report the `globalStorageUri` issue
@eamodio Wondering if you tried insiders to see if this issue still exists?
@sandy081 yes, insiders is my daily driver. And this issue has been around since the beginning of profiles just finally dug more into it to get a better idea of what was happening to report it. 
Sorry about this. It is specifically happening for settings contributed by extensions. I am not updating the model after they are registered. Fixed it.

To Verify:

- Create a sample extension with following setting and extension code
```json
"contributes": {
		"configuration":[
			{
				"title": "Test configuration",
				"properties": {
					"test.enabled": {
						"type": "boolean",
						"default": false
					  }
				}
			}
		],
}
```
```ts
import * as vscode from 'vscode';
export async function activate() {
    console.log(vscode.workspace.getConfiguration().get('test.enabled'));
}
```
- Install this extension in default profile and open update the `test.enabled` setting to `true` in user settings
- Create a new profile from the default profile
- Reload the window
- Make sure you see `false` in the console.

Solution patch:
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
@@ -753,6 +753,9 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
 		if (this.workspace) {
 			const previousData = this._configuration.toData();
 			const change = this._configuration.compareAndUpdateDefaultConfiguration(configurationModel, properties);
+			if (this.applicationConfiguration) {
+				this._configuration.updateApplicationConfiguration(this.applicationConfiguration.reparse());
+			}
 			if (this.remoteUserConfiguration) {
 				this._configuration.updateLocalUserConfiguration(this.localUserConfiguration.reparse());
 				this._configuration.updateRemoteUserConfiguration(this.remoteUserConfiguration.reparse());


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
@@ -1641,6 +1641,43 @@ suite('WorkspaceConfigurationService - Profiles', () => {
 		assert.strictEqual(testObject.getValue('configurationService.profiles.testSetting'), 'profileValue');
 	}));
 
+	test('registering normal setting after init', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
+		await fileService.writeFile(instantiationService.get(IUserDataProfilesService).defaultProfile.settingsResource, VSBuffer.fromString('{ "configurationService.profiles.testSetting3": "defaultProfile" }'));
+		await testObject.reloadConfiguration();
+
+		configurationRegistry.registerConfiguration({
+			'id': '_test',
+			'type': 'object',
+			'properties': {
+				'configurationService.profiles.testSetting3': {
+					'type': 'string',
+					'default': 'isSet',
+				}
+			}
+		});
+
+		assert.strictEqual(testObject.getValue('configurationService.profiles.testSetting3'), 'isSet');
+	}));
+
+	test('registering application scope setting after init', () => runWithFakedTimers<void>({ useFakeTimers: true }, async () => {
+		await fileService.writeFile(instantiationService.get(IUserDataProfilesService).defaultProfile.settingsResource, VSBuffer.fromString('{ "configurationService.profiles.applicationSetting3": "defaultProfile" }'));
+		await testObject.reloadConfiguration();
+
+		configurationRegistry.registerConfiguration({
+			'id': '_test',
+			'type': 'object',
+			'properties': {
+				'configurationService.profiles.applicationSetting3': {
+					'type': 'string',
+					'default': 'isSet',
+					scope: ConfigurationScope.APPLICATION
+				}
+			}
+		});
+
+		assert.strictEqual(testObject.getValue('configurationService.profiles.applicationSetting3'), 'defaultProfile');
+	}));
+
 	test('switch to 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" }'));