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

Commit

Permalink
overhaul to implement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Jun 28, 2019
1 parent 181c332 commit 3971fc6
Show file tree
Hide file tree
Showing 9 changed files with 486 additions and 106 deletions.
54 changes: 25 additions & 29 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,29 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm: watch"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
}
]
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: watch"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test",
"--user-data-dir=${workspaceFolder}/.vscode-test/user"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "npm: watch"
}
]
}
61 changes: 60 additions & 1 deletion package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "npm run compile && node ./node_modules/vscode/bin/test",
"package": "npx vsce package",
"publish": "npx vsce publish"
"publish": "npx vsce publish",
"lint": "tslint --project tsconfig.json -e src/*.d.ts -t verbose"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/fs-extra": "^7.0.0",
"@types/mocha": "^2.2.42",
"@types/node": "^11.13.0",
"chai": "^4.2.0",
"tslint": "^5.12.1",
"typescript": "^3.3.1",
"vscode": "^1.1.28"
Expand Down
7 changes: 7 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Commands {
SelectProfile = "extension.selectProfile",
SaveProfile = "extension.saveProfile",
DeleteProfile = "extension.deleteProfile"
}

export default Commands;
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const ExtensionName = "vscode-profile-switcher";
export const ExtensionPublisher = "aaronpowell";
export const ExtensionId = `${ExtensionPublisher}.${ExtensionName}`;

export const ConfigKey = "profileSwitcher";
export const ConfigProfilesKey = "profiles";
export const ConfigStorageKey = "storage";
92 changes: 17 additions & 75 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import * as vscode from "vscode";
import SettingsHelper from "./settingsHelper";

function getProfiles(profileSwitcherSettings: vscode.WorkspaceConfiguration) {
return profileSwitcherSettings.get<string[]>("profiles", []).sort();
}
import Commands from "./commands";
import Config from "./services/config";

export async function activate(context: vscode.ExtensionContext) {
let config = new SettingsHelper(context);
let settingsHelper = new SettingsHelper(context);
let config = new Config();

context.subscriptions.push(
vscode.commands.registerCommand("extension.selectProfile", async () => {
let profileSwitcherSettings = vscode.workspace.getConfiguration(
"profileSwitcher"
);
let profiles = getProfiles(profileSwitcherSettings);
vscode.commands.registerCommand(Commands.SelectProfile, async () => {
let profiles = config.getProfiles();

if (!profiles.length) {
await vscode.window.showInformationMessage(
Expand All @@ -30,21 +26,15 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}

let storage = profileSwitcherSettings.get<{ [key: string]: any }>(
"storage",
{}
);
let profileSettings = config.getProfileSettings(profile);

await config.updateUserSettings(storage[profile]);
await settingsHelper.updateUserSettings(profileSettings);
})
);

context.subscriptions.push(
vscode.commands.registerCommand("extension.saveProfile", async () => {
let profileSwitcherSettings = vscode.workspace.getConfiguration(
"profileSwitcher"
);
let profiles = getProfiles(profileSwitcherSettings);
vscode.commands.registerCommand(Commands.SaveProfile, async () => {
let profiles = config.getProfiles();

let profile = await vscode.window.showQuickPick(
[...profiles, "New profile"],
Expand All @@ -62,36 +52,11 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}

profiles.push(profile);
}

await profileSwitcherSettings.update(
"profiles",
profiles,
vscode.ConfigurationTarget.Global
);

let userSettings = await config.getUserSettings();

// We don't want to save profile info in the profile storage
if (userSettings["profileSwitcher.profiles"]) {
delete userSettings["profileSwitcher.profiles"];
}

if (userSettings["profileSwitcher.storage"]) {
delete userSettings["profileSwitcher.storage"];
await config.addProfile(profile);
}

let storage = profileSwitcherSettings.get<{ [key: string]: any }>(
"storage",
{}
);
storage[profile] = userSettings;
await profileSwitcherSettings.update(
"storage",
storage,
vscode.ConfigurationTarget.Global
);
let userSettings = await settingsHelper.getUserSettings();
await config.addProfileSettings(profile, userSettings);

vscode.window.showInformationMessage(
`Profile ${profile} has been saved.`
Expand All @@ -100,11 +65,8 @@ export async function activate(context: vscode.ExtensionContext) {
);

context.subscriptions.push(
vscode.commands.registerCommand("extension.deleteProfile", async () => {
let profileSwitcherSettings = vscode.workspace.getConfiguration(
"profileSwitcher"
);
let profiles = getProfiles(profileSwitcherSettings);
vscode.commands.registerCommand(Commands.DeleteProfile, async () => {
let profiles = config.getProfiles();

if (!profiles.length) {
await vscode.window.showInformationMessage(
Expand All @@ -121,28 +83,8 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}

let newProfiles = profiles
.slice(0, profiles.indexOf(profile))
.concat(profiles.slice(profiles.indexOf(profile) + 1, profiles.length));

await profileSwitcherSettings.update(
"profiles",
newProfiles,
vscode.ConfigurationTarget.Global
);

let storage = profileSwitcherSettings.get<{ [key: string]: any }>(
"storage",
{}
);

delete storage[profile];

await profileSwitcherSettings.update(
"storage",
storage,
vscode.ConfigurationTarget.Global
);
await config.removeProfile(profile);
await config.removeProfileSettings(profile);

await vscode.window.showInformationMessage(
`Profile ${profile} has been deleted.`
Expand Down
Loading

0 comments on commit 3971fc6

Please # to comment.