-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathmain.ts
173 lines (145 loc) · 5.88 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
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
'use strict';
import os = require('os');
import path = require('path');
import vscode = require('vscode');
import settingsManager = require('./settings');
import { LanguageClient, LanguageClientOptions, Executable, RequestType, NotificationType } from 'vscode-languageclient';
import { registerExpandAliasCommand } from './features/ExpandAlias';
import { registerShowHelpCommand } from './features/ShowOnlineHelp';
import { registerOpenInISECommand } from './features/OpenInISE';
import { registerPowerShellFindModuleCommand } from './features/PowerShellFindModule';
import { registerConsoleCommands } from './features/Console';
var languageServerClient: LanguageClient = undefined;
export function activate(context: vscode.ExtensionContext): void {
var PowerShellLanguageId = 'powershell';
var settings = settingsManager.load('powershell');
vscode.languages.setLanguageConfiguration(PowerShellLanguageId,
{
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\'\"\,\.\<\>\/\?\s]+)/g,
indentationRules: {
// ^(.*\*/)?\s*\}.*$
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
// ^.*\{[^}"']*$
increaseIndentPattern: /^.*\{[^}"']*$/
},
comments: {
lineComment: '#',
blockComment: ['<#', '#>']
},
brackets: [
['{', '}'],
['[', ']'],
['(', ')'],
],
__electricCharacterSupport: {
docComment: { scope: 'comment.documentation', open: '/**', lineStart: ' * ', close: ' */' }
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
]
}
});
// The language server is only available on Windows
if (os.platform() == "win32")
{
let args = [];
if (settings.developer.editorServicesWaitForDebugger) {
args.push('/waitForDebugger');
}
if (settings.developer.editorServicesLogLevel) {
args.push('/logLevel:' + settings.developer.editorServicesLogLevel)
}
try
{
let serverPath = resolveLanguageServerPath(settings);
let serverOptions = {
run: {
command: serverPath,
args: args
},
debug: {
command: serverPath,
args: ['/waitForDebugger']
}
};
let clientOptions: LanguageClientOptions = {
documentSelector: [PowerShellLanguageId],
synchronize: {
configurationSection: PowerShellLanguageId,
//fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')
}
}
languageServerClient =
new LanguageClient(
'PowerShell Editor Services',
serverOptions,
clientOptions);
languageServerClient.onReady().then(
() => registerFeatures(),
(reason) => vscode.window.showErrorMessage("Could not start language service: " + reason));
languageServerClient.start();
}
catch (e)
{
vscode.window.showErrorMessage(
"The language service could not be started: " + e);
}
}
}
function registerFeatures() {
// Register other features
registerExpandAliasCommand(languageServerClient);
registerShowHelpCommand(languageServerClient);
registerConsoleCommands(languageServerClient);
registerOpenInISECommand();
registerPowerShellFindModuleCommand(languageServerClient);
}
export function deactivate(): void {
if (languageServerClient) {
// Close the language server client
languageServerClient.stop();
languageServerClient = undefined;
}
}
function resolveLanguageServerPath(settings: settingsManager.ISettings): string {
var editorServicesHostPath = settings.developer.editorServicesHostPath;
if (editorServicesHostPath) {
console.log("Found Editor Services path from config: " + editorServicesHostPath);
// Does the path end in a .exe? Alert the user if so.
if (path.extname(editorServicesHostPath) != '') {
throw "The editorServicesHostPath setting must point to a directory, not a file.";
}
// Make the path absolute if it's not
editorServicesHostPath =
path.resolve(
__dirname,
editorServicesHostPath,
getHostExeName(settings.useX86Host));
console.log(" Resolved path to: " + editorServicesHostPath);
}
else {
// Use the default path in the plugin's 'bin' folder
editorServicesHostPath =
path.join(
__dirname,
'..',
'bin',
getHostExeName(settings.useX86Host));
console.log("Using default Editor Services path: " + editorServicesHostPath);
}
return editorServicesHostPath;
}
function getHostExeName(useX86Host: boolean): string {
// The useX86Host setting is only relevant on 64-bit OS
var is64BitOS = process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432');
var archText = useX86Host && is64BitOS ? ".x86" : "";
return "Microsoft.PowerShell.EditorServices.Host" + archText + ".exe";
}