Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

keys are missing from settings.json after profile load, all comments are deleted #26

Open
cyberbiont opened this issue Mar 12, 2020 · 9 comments

Comments

@cyberbiont
Copy link

cyberbiont commented Mar 12, 2020

If I get it right, setting.json handling is done via "additive" approach and all of the changes should be piled up, but nothing should be deleted.
However, after saving and immediately loading profile:

  • all comments are deleted. They are valid in VS code's settings.json and I use them a lot, so they should be preserved.
  • apart from commented lines, I also lost a bunch of different keys, some of which are perfectly valid JSON, namely:
 "workbench.colorCustomizations":  {
    "activityBar.activeBackground": "#1f7606"
}
"markdownlint.config": {
    "default": false,
    "no-hard-tabs": false,
    "first-line-heading": false,
    "no-bare-urls": false,
    "line-length": false
    // "no-multiple-blanks": false
  },
  "eslint.codeAction.showDocumentation":  {
    "enable": true
  },
 "files.associations": {
    ".vuerc": "json"
  },
 "editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.fixAll.eslint": true,
    "source.fixAll.stylelint": false
 },
  "eslint.codeAction.showDocumentation": {
    "enable": true
  },

I don't know how merging is done on settings.json, but something is wrong with it.

@WybeBosch
Copy link

WybeBosch commented Jun 22, 2020

Im having the same issues, it seems to be working fine except that it doesnt copy over "some" keys. And these keys and their contents are correctly saved within the profile (i can see them saved inside the profile text)

Its just that they are not appended back into the user settings page...
And these are all build in vscode settings, not related to extensions.
keys in question for me:

    "files.exclude": {
        "**/Icon?": true
    },
    "workbench.colorCustomizations": {
        "activityBar.activeBackground": "#294A5B"
    },
    "editor.tokenColorCustomizations": {
        "strings": "#97bf6e",
        "functions": "#b8bec9",
        "keywords": "#B182D1",
        "textMateRules": [
            {
                "name": "Variables",
                "scope": "variable.other.readwrite",
                "settings": {
                    "foreground": "#b8bec9"
                }
            },
            {
                "name": "Variables-level1",
                "scope": "support.variable",
                "settings": {
                    "foreground": "#E0C084"
                }
            },
            {
                "name": "Variables-level2",
                "scope": "variable.other.object",
                "settings": {
                    "foreground": "#6FACE6"
                }
            },
            {
                "name": "Variables-level3",
                "scope": "variable.other.object.property",
                "settings": {
                    "foreground": "#b8bec9"
                }
            },
            {
                "name": "Calc operators",
                "scope": "keyword.operator",
                "settings": {
                    "foreground": "#b8bec9"
                }
            },
            {
                "name": "Regex",
                "scope": "string.regexp,constant.other.character-class.regexp",
                "settings": {
                    "foreground": "#97bf6e"
                }
            }
        ]
    },

I really want to use the Profile Switcher extension since i have about 90 extensions but need most only in certain scenarios. Until 100% of my settings are saved/applied correctly im going to have to pass for now :(

@cyberbiont
Copy link
Author

Stay tuned. I have wrote my own VS Code extension for profiles switching that takes another approach. It will be probably released soon enough once I will have time to polish it and publish it.

@WybeBosch
Copy link

Stay tuned. I have wrote my own VS Code extension for profiles switching that takes another approach. It will be probably released soon enough once I will have time to polish it and publish it.

Hope life has been treating you well during these times, any update on the proposed extension? :)

@cyberbiont
Copy link
Author

Hope life has been treating you well during these times, any update on the proposed extension? :)

Sorry to keep you waiting, I had really no time for this lately.
But my schedule will be a little more relaxed next month and hopefully I will release it in a couple of weeks, stay tuned.
At least I tested it in use and it seems to be working well.

@codeunifier
Copy link

I'm having similar issues to @WybeBosch. Particularly I'd like to see workbench.colorCustomization settings brought in. Saving a profile saves the colors in the profile object, but they're not applied when switching to the profile. I'm using the Peacock extension and this would pair really well if those colors would work.

@aaronpowell
Copy link
Owner

Comments are actually really hard to deal with. They aren't valid JSON, which means that you can't just treat the stuff as normal JSON and JavaScript objects, you have to get a parser that understands the comments, can handle them, can do inserts into locations and keep the comment structure in place (if there's a multi-line comment, you don't want to insert in the middle of it do you).

I do use node-jsonc-parser to read the settings in, so that I can read the information out of it, but not to write back out (the parse method also strips comments).

I'd assume that VS Code does something different with that library (I think it's what they use), but I haven't had the time to work out how they handle files with comments, especially reading/writing them. My guess is they don't treat them as JSON at all, they use an AST of some form.

@aaronpowell
Copy link
Owner

Lost keys shouldn't happen though, unless the key is invalid JSON, so if someone can share a setting.json that has keys that get lost of profile switching, I can take a look.

@cyberbiont
Copy link
Author

@WybeBosch
Finally, it has arrived!
vscode-profiles
Give it a spin

@WybeBosch
Copy link

@cyberbiont my dude you are amazing! I will check it out!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants