Implement updateValue() method for PreferenceService#9178
Conversation
1b94533 to
8be966b
Compare
I like the idea but VS Code uses workspace as the default if I am not mistaken:
Could you please check the docs, @colin-grant-work. Maybe, I am overlooking something. Thank you!
|
I agree, looks like I'm not committed to changing the default scope. It was my understanding that what was requested in the bug report ticket was a more general change to the behavior of |
8be966b to
34603ac
Compare
PreferenceService.set()PreferenceScope.User
| } | ||
| private async toggleAutoSave(): Promise<void> { | ||
| this.preferencesService.set(EditorCommandContribution.AUTOSAVE_PREFERENCE, this.isAutoSaveOn() ? 'off' : 'on'); | ||
| this.preferencesService.set(EditorCommandContribution.AUTOSAVE_PREFERENCE, this.isAutoSaveOn() ? 'off' : 'on', PreferenceScope.User); |
There was a problem hiding this comment.
From what I understood, the issue with setting the preference with PreferenceScope.User means that it will not work for the following use-case which is supported in vscode:
editor.autoSave: falsein the workspace settings ({workspace}/.theia/settings.json).- attempt to toggle the
autoSavewith the command. - the preference value (
{workspace}/.theia/settings.json) is not updated while in vscode it is (.vscode).
There was a problem hiding this comment.
Hm... so that clarifies where the problem with the current implementation really is. editor.autoSave should not be available in folder scope - it should only be set in a local settings.json in a single-root workspace, and in a multi-root workspace, only the workspace value should be picked up, not any folder scopes. If we're picking up a folder value in a multi-root workspace, that's a bug, and I'll look into that. Otherwise, it looks like setting it at workspace level is VSCode's behavior, and would avoid any awkward override situations.
There was a problem hiding this comment.
@colin-grant-work I might have confused the workspace vs folder scopes, what I mean is the value under {workspace}/.vscode/settings.json is updated when toggling the command which does not happen in Theia if we are to specifically set the scope to User.
There was a problem hiding this comment.
Yes, if there is a bug that is making us pick up folder-scoped preferences, that's the fix to do. Then we should not set it in user scope.
There was a problem hiding this comment.
From what I understood, the issue with setting the preference with
PreferenceScope.Usermeans that it will not work for the following use-case which is supported in vscode:
editor.autoSave: falsein the workspace settings ({workspace}/.theia/settings.json).- attempt to toggle the
autoSavewith the command.- the preference value (
{workspace}/.theia/settings.json) is not updated while in vscode it is (.vscode).
First, we can check if the workspace config contains editor.autoSave. If yes, we change the value there. If no, we change it in the user config. Can this work?
- Users get the Code behavior via the menu or command palette.
- If users want to modify it manually via the
settings.json, they know what they're doing. - If you're an extension developer, you either want to trigger the default functionality via the command, so we are good. Or you are doing custom things via the preferences service API.
Thoughts? Am I overlooking something?
There was a problem hiding this comment.
So the code that actually performs this update in VSCode is not the update method to which you posted the docs earlier in this thread. It's the updateValue method, for which I don't think we have an equivalent. That code looks pretty similar to what you're describing: it loops through all scopes, finding the lowest one in which the value of the given preference isn't currently undefined (with user scope as default), and sets the value there. If the value is being deleted, it deletes it in all scopes in which it's defined.
If we want to have that logic available for this command, we can implement methods to mirror that in the PreferenceService, or we can just do it manually for this command.
There was a problem hiding this comment.
we can implement methods to mirror that in the
PreferenceService
Good idea. Let's keep the new API aligned to the updateValue from Code. We can use this new API for auto-save and maybe for others too (theming?).
As an extension developer, I would prefer to use an API that has the same semantics as a VS Code extension API. What do you think?
There was a problem hiding this comment.
I've implemented this. I'll add some tests next week to make sure it's doing what it should.
There was a problem hiding this comment.
I've implemented this. I'll add some tests next week to make sure it's doing what it should.
@vince-fugnitto, the tests are still planned 😃
34603ac to
400d483
Compare
kittaakos
left a comment
There was a problem hiding this comment.
I tried it; it works very well. The code looks great. Thank you so much, @colin-grant-work 👍
vince-fugnitto
left a comment
There was a problem hiding this comment.
@colin-grant-work I believe the tests will need adjusting, they currently fail when testing the preferences.
PreferenceScope.UserupdateValue() method for PreferenceService
ba28e45 to
865e92d
Compare
|
@vince-fugnitto, I've implemented some tests here and modified the tests that were failing. If you wouldn't mind taking a look, I think it should be just about good to go. |
vince-fugnitto
left a comment
There was a problem hiding this comment.
The changes look good to me, and I confirmed that autoSave now behaves like expected.
I only have a minor comment about the api-test where the import has an error but does not affect functionality.
| const { assert } = chai; | ||
|
|
||
| const { PreferenceService, PreferenceScope } = require('@theia/core/lib/browser/preferences/preference-service'); | ||
| const { PreferenceService, PreferenceScope, PreferenceInspection } = require('@theia/core/lib/browser/preferences/preference-service'); |
There was a problem hiding this comment.
I wonder if there is a way to avoid the error we get by this import:
Property 'PreferenceInspection' does not exist on type 'typeof import("/home/evinfug/workspaces/theia/packages/core/src/browser/preferences/preference-service")
There was a problem hiding this comment.
The behavior there seems to be a bit inconsistent between environments, but I've modified the code in a way that seems to make the IDE happy in all of the environments available to me.
Signed-off-by: Colin Grant <colin.grant@ericsson.com>
865e92d to
ce50a61
Compare
What it does
Fixes #9152 by implementing an
updateValuemethod parallel to that available in VSCodeIn addition, an error was previously thrown if
setwas called with asectionName(tasks,launch) in User scope, but that is no longer appropriate because some section configurations are available in user scope,so now that check is delegated to. I have removed any check for scope validity, because some tests specifically relied on being able to set a preference that was not (yet) valid. It could be argued that a check should happen early, but a warning will be shown later during the processing of a preference change - and the change won't take effect - if a preference is set that is not valid.PreferenceSchema.isValidInScope()Here is one of the tests relying on setting a preference that is only made valid later:
theia/packages/core/src/browser/preferences/preference-service.spec.ts
Lines 262 to 274 in bb17f71
How to test
PreferenceService.set('tasks', {version: '2.0.0', tasks: []});. E.g. add this toPreferencesContribution.registerCommands():Review checklist
Reminder for reviewers
Signed-off-by: Colin Grant colin.grant@ericsson.com