-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathISECompatibility.ts
61 lines (54 loc) · 2.43 KB
/
ISECompatibility.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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);
}
}
}
}