Skip to content

Add commands to set and unset ISE Compatibility features #2335

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

Merged
merged 19 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
481 changes: 43 additions & 438 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"onCommand:PowerShell.ShowSessionConsole",
"onCommand:PowerShell.ShowSessionMenu",
"onCommand:PowerShell.RestartSession",
"onCommand:PowerShell.EnableISEMode",
"onCommand:PowerShell.DisableISEMode",
"onView:PowerShellCommands"
],
"dependencies": {
Expand All @@ -47,13 +49,15 @@
"vscode-languageclient": "~5.2.1"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "~5.2.7",
"@types/mock-fs": "~4.10.0",
"@types/node": "~10.11.0",
"@types/node-fetch": "~2.5.4",
"@types/rewire": "~2.5.28",
"@types/semver": "~6.2.0",
"@types/sinon": "~7.5.1",
"@types/vscode": "1.34.0",
"mocha": "~5.2.0",
"mocha-junit-reporter": "~1.23.1",
"mocha-multi-reporters": "~1.1.7",
Expand All @@ -63,16 +67,15 @@
"tslint": "~5.20.1",
"typescript": "~3.5.3",
"vsce": "~1.64.0",
"vscode": "~1.1.36"
"vscode-test": "~1.3.0"
},
"extensionDependencies": [
"vscode.powershell"
],
"scripts": {
"compile": "tsc -v && tsc -p ./ && tslint -p ./",
"compile-watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
"test": "node ./out/test/runTests.js"
},
"contributes": {
"breakpoints": [
Expand Down Expand Up @@ -133,6 +136,16 @@
"title": "Expand Alias",
"category": "PowerShell"
},
{
"command": "PowerShell.EnableISEMode",
"title": "Enable ISE Mode",
"category": "PowerShell"
},
{
"command": "PowerShell.DisableISEMode",
"title": "Disable ISE Mode (restore to defaults)",
"category": "PowerShell"
},
{
"command": "PowerShell.RefreshCommandsExplorer",
"title": "Refresh Command Explorer",
Expand Down
61 changes: 61 additions & 0 deletions src/features/ISECompatibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as vscode from "vscode";
import { LanguageClient } from "vscode-languageclient";
import { IFeature } from "../feature";

interface ISetting {
path: string;
name: string;
value: string | boolean;
}

/**
* A feature to implement commands to make code like the ISE and reset the settings.
*/
export class ISECompatibilityFeature implements IFeature {
// Marking settings as public so we can use it within the tests without needing to duplicate the list of settings.
public static settings: ISetting[] = [
{ path: "workbench.activityBar", name: "visible", value: false },
{ path: "debug", name: "openDebug", value: "neverOpen" },
{ path: "editor", name: "tabCompletion", value: "on" },
{ path: "powershell.integratedConsole", name: "focusConsoleOnExecute", value: false },
{ path: "files", name: "defaultLanguage", value: "powershell" },
{ path: "workbench", name: "colorTheme", value: "PowerShell ISE" },
];
private iseCommandRegistration: vscode.Disposable;
private defaultCommandRegistration: vscode.Disposable;
private languageClient: LanguageClient;

constructor() {
this.iseCommandRegistration = vscode.commands.registerCommand(
"PowerShell.EnableISEMode", this.EnableISEMode);
this.defaultCommandRegistration = vscode.commands.registerCommand(
"PowerShell.DisableISEMode", this.DisableISEMode);
}

public dispose() {
this.iseCommandRegistration.dispose();
this.defaultCommandRegistration.dispose();
}

public setLanguageClient(languageclient: LanguageClient) {
this.languageClient = languageclient;
}

private async EnableISEMode() {
for (const iseSetting of ISECompatibilityFeature.settings) {
await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, iseSetting.value, true);
}
}

private async DisableISEMode() {
for (const iseSetting of ISECompatibilityFeature.settings) {
const currently = vscode.workspace.getConfiguration(iseSetting.path).get<string | boolean>(iseSetting.name);
if (currently === iseSetting.value) {
await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, undefined, true);
}
}
}
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { FindModuleFeature } from "./features/FindModule";
import { GenerateBugReportFeature } from "./features/GenerateBugReport";
import { GetCommandsFeature } from "./features/GetCommands";
import { HelpCompletionFeature } from "./features/HelpCompletion";
import { ISECompatibilityFeature } from "./features/ISECompatibility";
import { NewFileOrProjectFeature } from "./features/NewFileOrProject";
import { OpenInISEFeature } from "./features/OpenInISE";
import { PesterTestsFeature } from "./features/PesterTests";
Expand Down Expand Up @@ -146,6 +147,7 @@ export function activate(context: vscode.ExtensionContext): void {
new GenerateBugReportFeature(sessionManager),
new ExpandAliasFeature(logger),
new GetCommandsFeature(logger),
new ISECompatibilityFeature(),
new ShowHelpFeature(logger),
new FindModuleFeature(),
new PesterTestsFeature(sessionManager),
Expand Down
39 changes: 39 additions & 0 deletions test/features/ISECompatibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as assert from "assert";
import * as vscode from "vscode";
import { ISECompatibilityFeature } from "../../src/features/ISECompatibility";

suite("ISECompatibility feature", () => {
test("It sets ISE Settings", async () => {
await vscode.commands.executeCommand("PowerShell.EnableISEMode");
for (const iseSetting of ISECompatibilityFeature.settings) {
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name);
assert.equal(currently, iseSetting.value);
}
});
test("It unsets ISE Settings", async () => {
// Change state to something that DisableISEMode will change
await vscode.workspace.getConfiguration("workbench").update("colorTheme", "PowerShell ISE", true);
assert.equal(vscode.workspace.getConfiguration("workbench").get("colorTheme"), "PowerShell ISE");

await vscode.commands.executeCommand("PowerShell.DisableISEMode");
for (const iseSetting of ISECompatibilityFeature.settings) {
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name);
assert.notEqual(currently, iseSetting.value);
}
});
test("It leaves Theme after being changed after enabling ISE Mode", async () => {
await vscode.commands.executeCommand("PowerShell.EnableISEMode");
assert.equal(vscode.workspace.getConfiguration("workbench").get("colorTheme"), "PowerShell ISE");

await vscode.workspace.getConfiguration("workbench").update("colorTheme", "Dark+", true);
await vscode.commands.executeCommand("PowerShell.DisableISEMode");
for (const iseSetting of ISECompatibilityFeature.settings) {
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name);
assert.notEqual(currently, iseSetting.value);
}
assert.equal(vscode.workspace.getConfiguration("workbench").get("colorTheme"), "Dark+");
});
});
21 changes: 0 additions & 21 deletions test/index.ts

This file was deleted.

30 changes: 30 additions & 0 deletions test/runTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as path from "path";

import { runTests } from "vscode-test";

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, "../../");

// The path to the extension test runner script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, "./testRunner");

// Download VS Code, unzip it and run the integration test from the local directory.
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs: ["."] });
} catch (err) {
// tslint:disable-next-line:no-console
console.error(err);
// tslint:disable-next-line:no-console
console.error("Failed to run tests");
process.exit(1);
}
}

main();
49 changes: 49 additions & 0 deletions test/testRunner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import * as glob from "glob";
import * as Mocha from "mocha";
import * as path from "path";

export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: "tdd", // the TDD UI is being used in extension.test.ts (suite, test, etc.)
useColors: !process.env.TF_BUILD, // colored output from test results
reporter: "mocha-multi-reporters",
timeout: 5000,
reporterOptions: {
reporterEnabled: "spec, mocha-junit-reporter",
mochaJunitReporterReporterOptions: {
mochaFile: path.join(__dirname, "..", "..", "test-results.xml"),
},
},
});

const testsRoot = path.resolve(__dirname, "..");

return new Promise((c, e) => {
glob("**/**.test.js", { cwd: testsRoot }, (err: any, files: any[]) => {
if (err) {
return e(err);
}

// Add files to the test suite
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));

try {
// Run the mocha test
mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
e(err);
}
});
});
}
11 changes: 5 additions & 6 deletions vscode-powershell.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,12 @@ task BuildAll BuildEditorServices, Build
#region Test tasks

task Test Build, {
if (!$global:IsLinux) {
Write-Host "`n### Running extension tests" -ForegroundColor Green
exec { & npm run test }
}
else {
Write-Warning "Skipping extension tests on Linux platform because vscode does not support it."
if ($env:TF_BUILD -and $global:IsLinux) {
Write-Warning "Skipping extension tests in Linux CI because vscode does not support it."
return
}
Write-Host "`n### Running extension tests" -ForegroundColor Green
exec { & npm run test }
}

task TestEditorServices {
Expand Down