forked from palantir/python-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.ts
More file actions
51 lines (44 loc) · 1.88 KB
/
Copy pathextension.ts
File metadata and controls
51 lines (44 loc) · 1.88 KB
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
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
import * as net from 'net';
import { workspace, Disposable, ExtensionContext } from 'vscode';
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, ErrorAction, ErrorHandler, CloseAction, TransportKind } from 'vscode-languageclient';
function startLangServer(command: string, args: string[], documentSelector: string[]): Disposable {
const serverOptions: ServerOptions = {
command,
args,
};
const clientOptions: LanguageClientOptions = {
documentSelector: documentSelector,
synchronize: {
configurationSection: "pyls"
}
}
return new LanguageClient(command, serverOptions, clientOptions).start();
}
function startLangServerTCP(addr: number, documentSelector: string[]): Disposable {
const serverOptions: ServerOptions = function() {
return new Promise((resolve, reject) => {
var client = new net.Socket();
client.connect(addr, "127.0.0.1", function() {
resolve({
reader: client,
writer: client
});
});
});
}
const clientOptions: LanguageClientOptions = {
documentSelector: documentSelector,
}
return new LanguageClient(`tcp lang server (port ${addr})`, serverOptions, clientOptions).start();
}
export function activate(context: ExtensionContext) {
const executable = workspace.getConfiguration("pyls").get<string>("executable");
context.subscriptions.push(startLangServer(executable, ["-vv"], ["python"]));
// For TCP server needs to be started seperately
// context.subscriptions.push(startLangServerTCP(2087, ["python"]));
}