Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode settings.json Completely Overwritten #84

Open
SeanMcLoughlin opened this issue Jun 9, 2021 · 7 comments
Open

VSCode settings.json Completely Overwritten #84

SeanMcLoughlin opened this issue Jun 9, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@SeanMcLoughlin
Copy link

I had set Yin-Yang to change the color scheme in VS Code based on time of day, and it appears that it completely overwrote my settings.json file with just the color scheme.

Yin-Yang needs to either append to, or update the JSON -- not completely overwrite the file. I would have lost years worth of settings accumulating if I hadn't had another computer with my old settings.json still intact.

Machine configuration:
DE: plasmashell 5.21.5
OS: Manjaro 21.0.6

@l0drex
Copy link
Collaborator

l0drex commented Jun 9, 2021

Well, that should not have happened. It's likely there was an error while trying to read your settings file, since only then an empty settings file gets created (see this line here). So you should probably check if it is well formed, e.g. no missing brackets.

Could you please replicate the issue by doing the following:

  1. Create another backup of your settings.json.
  2. Disable everything except VS Code in yin-yang.
  3. Run yin-yang -t from a terminal.
  4. Paste the output here.
  5. (Re-enable the automatic theme change, if you had it enabled before).

@SeanMcLoughlin
Copy link
Author

> yin-yang -t
SETTINGS  1
Changing "Default" to "Atom One Dark" in <my home folder>/.config/Code/User/settings.json
open(): No such file or directory

This reproduces the issue and overwrites the file. But my settings.json appears to not have any errors in it.

I have the dark theme set to "Atom One Dark" and the light theme set to "Atom One Light" in the VS Code section of Yin-Yang.

I'm also running on the AUR version of the app -- v2.1

@l0drex
Copy link
Collaborator

l0drex commented Jun 9, 2021

Interesting. Seems like the inplace_change() function is the issue here.

Good news is that in my pull request, VS Code doesn't use this function anymore, bad news is that other plugins still use it. I'm going to investigate this further.

@SeanMcLoughlin
Copy link
Author

json.load doesn't accept a final comma in src/plugins/vscode.py, but vscode accepts it as valid for settings.json. See this discussion on StackOverflow. So my settings file was considered invalid by the plugin.

There may be a safer function to read the json. The SO post above has a solution with ast. Or maybe yin-yang could clean up users' settings.json so python can parse it.

@l0drex
Copy link
Collaborator

l0drex commented Jun 9, 2021

I actually don't think that this a good idea, since ast isn't really meant to do that. Checking the user's settings file would be a lot of work.

Instead, I think there should just be an exception if the file is malformed and do nothing else.

Does VS Code automatically form the JSON files in such a way or did you manually edit it? If VS Code created those, then it may actually be needed.

@SeanMcLoughlin
Copy link
Author

SeanMcLoughlin commented Jun 9, 2021

I don't think vscode created any JSON that way by default, but any plug-ins that edit the settings file can theoretically add an extra comma.

For example, my settings file's last line was setting my Python virtualenv location. This was added by the Python extension, and it had a comma at the end of it.

@l0drex l0drex added the bug Something isn't working label Jul 30, 2021
@dflvunoooooo
Copy link

I am having this problem too. My settings got overwritten seemingly randomly for weeks and I couldn't figure out why. I just per chance noticed it was at the same time, when yin yang changes the theme, all settings are deleted. Is there anything that can be done about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants