-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathmain.ts
132 lines (106 loc) · 3.54 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
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
'use strict';
import path = require('path');
import vscode = require('vscode');
import configuration = require('./features/configuration');
import { LanguageClient, LanguageClientOptions, Executable } from 'vscode-languageclient';
import { RequestType, NotificationType, ResponseError } from 'vscode-jsonrpc';
import powerShellMessage = require('./features/ShowOnlineHelp');
export function activate(context: vscode.ExtensionContext): void {
var PowerShellLanguageId = 'PowerShell';
vscode.languages.setLanguageConfiguration(PowerShellLanguageId,
{
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\=\+\[\{\]\}\\\|\;\'\"\,\.\<\>\/\?\s]+)/g,
indentationRules: {
// ^(.*\*/)?\s*\}.*$
decreaseIndentPattern: /^(.*\*\/)?\s*\}.*$/,
// ^.*\{[^}"']*$
increaseIndentPattern: /^.*\{[^}"']*$/
},
comments: {
lineComment: '#',
blockComment: ['<#', '#>']
},
brackets: [
['{', '}'],
['[', ']'],
['(', ')'],
],
__electricCharacterSupport: {
brackets: [
{ tokenType:'delimiter.curly.ts', open: '{', close: '}', isElectric: true },
{ tokenType:'delimiter.square.ts', open: '[', close: ']', isElectric: true },
{ tokenType:'delimiter.paren.ts', open: '(', close: ')', isElectric: true }
],
docComment: { scope:'comment.documentation', open:'/**', lineStart:' * ', close:' */' }
},
__characterPairSupport: {
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"', notIn: ['string'] },
{ open: '\'', close: '\'', notIn: ['string', 'comment'] }
]
}
});
let serverPath = resolveLanguageServerPath();
let serverOptions = {
run: {
command: serverPath,
},
debug: {
command: serverPath,
args: ['/waitForDebugger']
}
};
let clientOptions: LanguageClientOptions = {
documentSelector: [PowerShellLanguageId],
synchronize: {
configurationSection: PowerShellLanguageId,
//fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')
}
}
let client =
new LanguageClient(
'PowerShell Editor Services',
serverOptions,
clientOptions);
client.start();
var disposable = vscode.commands.registerCommand('PowerShell.OnlineHelp', () => {
const editor = vscode.window.activeTextEditor;
var selection = editor.selection;
var doc = editor.document;
var cwr = doc.getWordRangeAtPosition(selection.active)
var text = doc.getText(cwr);
client.sendRequest(powerShellMessage.ShowOnlineHelpRequest.type, text);
});
}
function resolveLanguageServerPath() : string {
var config = configuration.load('PowerShell');
var editorServicesHostPath = config.editorServicesHostPath;
if (config.editorServicesHostPath)
{
console.log("Found Editor Services path from config: " + editorServicesHostPath);
// Make the path absolute if it's not
editorServicesHostPath =
path.resolve(
__dirname,
config.editorServicesHostPath);
console.log(" Resolved path to: " + editorServicesHostPath);
}
else
{
// Use the default path in the plugin's 'bin' folder
editorServicesHostPath =
path.join(
__dirname,
'..',
'bin',
'Microsoft.PowerShell.EditorServices.Host.exe');
console.log("Using default Editor Services path: " + editorServicesHostPath);
}
return editorServicesHostPath;
}