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 7 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
12 changes: 12 additions & 0 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 Down Expand Up @@ -133,6 +135,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 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 this.settings) {
await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, iseSetting.value, true);
}
}

private async DisableISEMode() {
for (const iseSetting of this.settings) {
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(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
36 changes: 36 additions & 0 deletions test/features/ISECompatibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as assert from "assert";
import * as vscode from "vscode";
import { ISECompatibilityFeature } from "../../src/features/ISECompatibility";

const ISECompatibility: ISECompatibilityFeature = new ISECompatibilityFeature();

suite("ISECompatibility feature", () => {
test("It sets ISE Settings", async () => {
await vscode.commands.executeCommand("PowerShell.EnableISEMode");
for (const iseSetting of ISECompatibility.settings) {
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name);
assert.equal(currently, iseSetting.value);
}
});
test("It unsets ISE Settings", async () => {
await vscode.commands.executeCommand("PowerShell.DisableISEMode");
for (const iseSetting of ISECompatibility.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");
await vscode.workspace.getConfiguration("workbench").update("colorTheme", "Dark+", true);
await vscode.commands.executeCommand("PowerShell.DisableISEMode");
for (const iseSetting of ISECompatibility.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+");
});
});
ISECompatibility.dispose();
9 changes: 2 additions & 7 deletions vscode-powershell.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,8 @@ 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."
}
Write-Host "`n### Running extension tests" -ForegroundColor Green
exec { & npm run test }
}

task TestEditorServices {
Expand Down