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

Commit

Permalink
Using jsonc to parse the settings to handle comments and fix #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Jul 3, 2019
1 parent 0fdeba8 commit c5246ea
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 115 deletions.
115 changes: 8 additions & 107 deletions .test-profiles/simple-profile/data/User/settings.json
Original file line number Diff line number Diff line change
@@ -1,112 +1,12 @@
{
"editor.fontSize": 24,
"profileSwitcher.profiles": ["Default"],
"editor.fontSize": 14,
"profileSwitcher.profiles": ["Default", "Big Font"],
"profileSwitcher.storage": {
"Default": {
"sync.gist": "40c333588d64df34c6f36f196010e5ee",
"sync.lastUpload": "",
"sync.autoDownload": false,
"sync.autoUpload": false,
"sync.lastDownload": "2017-11-03T04:41:33.893Z",
"sync.forceDownload": false,
"sync.anonymousGist": false,
"sync.host": "",
"sync.pathPrefix": "",
"sync.quietSync": false,
"sync.askGistName": false,
"workbench.colorTheme": "1984 - Light",
"files.autoSave": "afterDelay",
"editor.renderWhitespace": "all",
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": true,
"workbench.startupEditor": "newUntitledFile",
"files.autoSaveDelay": 5000,
"sync.removeExtensions": true,
"sync.syncExtensions": true,
"team.showWelcomeMessage": false,
"terminal.integrated.rendererType": "auto",
"explorer.confirmDelete": false,
"window.zoomLevel": 0,
"azureStorage.preview.staticWebsites": true,
"breadcrumbs.enabled": true,
"powershell.powerShellExePath": "C:\\WINDOWS\\SysWow64\\WindowsPowerShell\\v1.0\\powershell.exe",
"FSharp.enableReferenceCodeLens": true,
"FSharp.fsacRuntime": "netcore",
"workbench.iconTheme": "vscode-icons",
"peacock.favoriteColors": [
{
"name": "Angular Red",
"value": "#b52e31"
},
{
"name": "Auth0 Orange",
"value": "#eb5424"
},
{
"name": "Azure Blue",
"value": "#007fff"
},
{
"name": "C# Purple",
"value": "#68217A"
},
{
"name": "Gatsby Purple",
"value": "#639"
},
{
"name": "Go Cyan",
"value": "#5dc9e2"
},
{
"name": "Java Blue-Gray",
"value": "#557c9b"
},
{
"name": "JavaScript Yellow",
"value": "#f9e64f"
},
{
"name": "Mandalorian Blue",
"value": "#1857a4"
},
{
"name": "Node Green",
"value": "#215732"
},
{
"name": "React Blue",
"value": "#00b3e6"
},
{
"name": "Something Different",
"value": "#832561"
},
{
"name": "Vue Green",
"value": "#42b883"
}
],
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.fontSize": 14,
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true,
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"profileSwitcher.profiles": ["test1"],
"profileSwitcher.storage": {
"test1": {
"foo": "bar"
}
}
"editor.fontSize": 14
},
"Big Font": {
"editor.fontSize": 24
}
},
"profileSwitcher.extensions": {
Expand All @@ -118,6 +18,7 @@
"version": "1.9.0",
"name": "prettier-vscode"
}
]
],
"Big Font": []
}
}
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ All notable changes to the "vscode-profile-switcher" extension will be documente

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [0.3.0] - Unreleased
## [0.3.0] - 2019-07-03

### Added

- Working on support for enable/disable extensions as you change profiles (Issue [#2](https://github.com/aaronpowell/vscode-profile-switcher/issues/2))
- Add support for setting a Live Share profile that is auto-activated (PR [#4](https://github.com/aaronpowell/vscode-profile-switcher/pull/4))

### Changed

- Using [`jsonc`](https://npmjs.org/package/jsonc) for parsing the `settings.json` file so it won't fail if there are comments (see [#3](https://github.com/aaronpowell/vscode-profile-switcher/issues/3))

## [0.2.0] - 2019-06-28

### Added
Expand Down
61 changes: 58 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
},
"dependencies": {
"fs-extra": "^8.0.1",
"jsonc": "^2.0.0",
"vsls": "^0.3.1291"
}
}
12 changes: 8 additions & 4 deletions src/settingsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from "vscode";
import * as os from "os";
import * as path from "path";
import { Settings } from "./services/config";
import { jsonc } from "jsonc";

export enum OsType {
Windows = 1,
Expand Down Expand Up @@ -113,17 +114,20 @@ export default class SettingsHelper {
return {};
}

return await fs.readJSON(settingsPath, { encoding: "utf8" });
let fileContents = await fs.readFile(settingsPath, { encoding: "utf8" });

return jsonc.parse(fileContents);
}

public async updateUserSettings(update: Settings) {
let existingSettings = await this.getUserSettings();

let newSettings = Object.assign({}, existingSettings, update);

await fs.writeJSON(this.getSettingsPath(), newSettings, {
encoding: "utf8",
spaces: 4
let settingsAsJson = jsonc.stringify(newSettings, { space: 4 });

await fs.writeFile(this.getSettingsPath(), settingsAsJson, {
encoding: "utf8"
});
}

Expand Down

0 comments on commit c5246ea

Please # to comment.