forked from cdietrich/xtext-languageserver-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.ts
55 lines (45 loc) · 1.71 KB
/
extension.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
'use strict';
import * as net from 'net';
import {Trace} from 'vscode-jsonrpc';
import { window, workspace, commands, ExtensionContext, Uri } from 'vscode';
import { LanguageClient, LanguageClientOptions, StreamInfo, Position as LSPosition, Location as LSLocation } from 'vscode-languageclient/node';
let lc: LanguageClient;
export function activate(context: ExtensionContext) {
// The server is a started as a separate app and listens on port 5007
let connectionInfo = {
port: 5007
};
let serverOptions = () => {
// Connect to language server via socket
let socket = net.connect(connectionInfo);
let result: StreamInfo = {
writer: socket,
reader: socket
};
return Promise.resolve(result);
};
let clientOptions: LanguageClientOptions = {
documentSelector: ['mydsl'],
synchronize: {
fileEvents: workspace.createFileSystemWatcher('**/*.*')
}
};
// Create the language client and start the client.
lc = new LanguageClient('Xtext Server', serverOptions, clientOptions);
var disposable2 =commands.registerCommand("mydsl.a.proxy", async () => {
let activeEditor = window.activeTextEditor;
if (!activeEditor || !activeEditor.document || activeEditor.document.languageId !== 'mydsl') {
return;
}
if (activeEditor.document.uri instanceof Uri) {
commands.executeCommand("mydsl.a", activeEditor.document.uri.toString());
}
})
context.subscriptions.push(disposable2);
// enable tracing (.Off, .Messages, Verbose)
lc.setTrace(Trace.Verbose);
lc.start();
}
export function deactivate() {
return lc.stop();
}