forked from PowerShell/vscode-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
217 lines (187 loc) · 8.06 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
"use strict";
import path = require("path");
import vscode = require("vscode");
import TelemetryReporter from "vscode-extension-telemetry";
import { DocumentSelector } from "vscode-languageclient";
import { IFeature } from "./feature";
import { CodeActionsFeature } from "./features/CodeActions";
import { ConsoleFeature } from "./features/Console";
import { CustomViewsFeature } from "./features/CustomViews";
import { DebugSessionFeature } from "./features/DebugSession";
import { PickPSHostProcessFeature } from "./features/DebugSession";
import { PickRunspaceFeature } from "./features/DebugSession";
import { SpecifyScriptArgsFeature } from "./features/DebugSession";
import { ExamplesFeature } from "./features/Examples";
import { ExpandAliasFeature } from "./features/ExpandAlias";
import { ExtensionCommandsFeature } from "./features/ExtensionCommands";
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";
import { RemoteFilesFeature } from "./features/RemoteFiles";
import { RunCodeFeature } from "./features/RunCode";
import { ShowHelpFeature } from "./features/ShowHelp";
import { Logger, LogLevel } from "./logging";
import { SessionManager } from "./session";
import Settings = require("./settings");
import { PowerShellLanguageId } from "./utils";
import utils = require("./utils");
// The most reliable way to get the name and version of the current extension.
// tslint:disable-next-line: no-var-requires
const PackageJSON: any = require("../../package.json");
// NOTE: We will need to find a better way to deal with the required
// PS Editor Services version...
const requiredEditorServicesVersion = "2.0.0";
// the application insights key (also known as instrumentation key) used for telemetry.
const AI_KEY: string = "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217";
let logger: Logger;
let sessionManager: SessionManager;
let extensionFeatures: IFeature[] = [];
let telemetryReporter: TelemetryReporter;
const documentSelector: DocumentSelector = [
{ language: "powershell", scheme: "file" },
{ language: "powershell", scheme: "untitled" },
];
export function activate(context: vscode.ExtensionContext): void {
// create telemetry reporter on extension activation
telemetryReporter = new TelemetryReporter(PackageJSON.name, PackageJSON.version, AI_KEY);
// If both extensions are enabled, this will cause unexpected behavior since both register the same commands
if (PackageJSON.name.toLowerCase() === "powershell-preview"
&& vscode.extensions.getExtension("ms-vscode.powershell")) {
vscode.window.showWarningMessage(
"'PowerShell' and 'PowerShell Preview' are both enabled. Please disable one for best performance.");
}
checkForUpdatedVersion(context, PackageJSON.version);
vscode.languages.setLanguageConfiguration(
PowerShellLanguageId,
{
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\'\"\,\.\<\>\/\?\s]+)/g,
indentationRules: {
// ^(.*\*/)?\s*\}.*$
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
// ^.*\{[^}"']*$
increaseIndentPattern: /^.*\{[^}"']*$/,
},
comments: {
lineComment: "#",
blockComment: ["<#", "#>"],
},
brackets: [
["{", "}"],
["[", "]"],
["(", ")"],
],
onEnterRules: [
{
// e.g. /** | */
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: vscode.IndentAction.IndentOutdent, appendText: " * " },
},
{
// e.g. /** ...|
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: vscode.IndentAction.None, appendText: " * " },
},
{
// e.g. * ...|
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: vscode.IndentAction.None, appendText: "* " },
},
{
// e.g. */|
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
action: { indentAction: vscode.IndentAction.None, removeText: 1 },
},
{
// e.g. *-----*/|
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
action: { indentAction: vscode.IndentAction.None, removeText: 1 },
},
],
});
// Create the logger
logger = new Logger();
// Set the log level
const extensionSettings = Settings.load();
logger.MinimumLogLevel = LogLevel[extensionSettings.developer.editorServicesLogLevel];
sessionManager =
new SessionManager(
requiredEditorServicesVersion,
logger,
documentSelector,
PackageJSON.displayName,
PackageJSON.version,
telemetryReporter);
// Create features
extensionFeatures = [
new ConsoleFeature(logger),
new ExamplesFeature(),
new OpenInISEFeature(),
new GenerateBugReportFeature(sessionManager),
new ExpandAliasFeature(logger),
new GetCommandsFeature(logger),
new ISECompatibilityFeature(),
new ShowHelpFeature(logger),
new FindModuleFeature(),
new PesterTestsFeature(sessionManager),
new RunCodeFeature(sessionManager),
new ExtensionCommandsFeature(logger),
new CodeActionsFeature(logger),
new NewFileOrProjectFeature(),
new RemoteFilesFeature(),
new DebugSessionFeature(context, sessionManager, logger),
new PickPSHostProcessFeature(),
new SpecifyScriptArgsFeature(context),
new HelpCompletionFeature(logger),
new CustomViewsFeature(),
new PickRunspaceFeature(),
];
sessionManager.setExtensionFeatures(extensionFeatures);
if (extensionSettings.startAutomatically) {
sessionManager.start();
}
}
function checkForUpdatedVersion(context: vscode.ExtensionContext, version: string) {
const showReleaseNotes = "Show Release Notes";
const powerShellExtensionVersionKey = "powerShellExtensionVersion";
const storedVersion = context.globalState.get(powerShellExtensionVersionKey);
if (!storedVersion) {
// TODO: Prompt to show User Guide for first-time install
} else if (version !== storedVersion) {
vscode
.window
.showInformationMessage(
`The PowerShell extension has been updated to version ${version}!`,
showReleaseNotes)
.then((choice) => {
if (choice === showReleaseNotes) {
vscode.commands.executeCommand(
"markdown.showPreview",
vscode.Uri.file(path.resolve(__dirname, "../../CHANGELOG.md")));
}
});
}
context.globalState.update(
powerShellExtensionVersionKey,
version);
}
export function deactivate(): void {
// Clean up all extension features
extensionFeatures.forEach((feature) => {
feature.dispose();
});
// Dispose of the current session
sessionManager.dispose();
// Dispose of the logger
logger.dispose();
// Dispose of telemetry reporter
telemetryReporter.dispose();
}