-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathMain.hx
More file actions
51 lines (47 loc) · 1.59 KB
/
Main.hx
File metadata and controls
51 lines (47 loc) · 1.59 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
51
package haxeLanguageServer;
import js.Node.process;
import jsonrpc.Protocol;
import jsonrpc.node.MessageReader;
import jsonrpc.node.MessageWriter;
function main() {
final reader = new MessageReader(process.stdin);
final writer = new MessageWriter(process.stdout);
final languageServerProtocol = new Protocol(writer.write);
languageServerProtocol.logError = message -> languageServerProtocol.sendNotification(LogMessageNotification.type, {type: Warning, message: message});
setupTrace(languageServerProtocol);
final context = new Context(languageServerProtocol);
reader.listen(languageServerProtocol.handleMessage);
function log(method:String, data:Dynamic) {
if (context.config.sendMethodResults) {
languageServerProtocol.sendNotification(LanguageServerMethods.DidRunMethod, {
kind: Lsp,
method: method,
debugInfo: null,
response: {
result: data
}
});
}
}
languageServerProtocol.didRespondToRequest = function(request, response) {
log(request.method, {
request: request,
response: response
});
}
languageServerProtocol.didSendNotification = function(notification) {
if (notification.method != LogMessageNotification.type && !notification.method.startsWith("haxe/")) {
log(notification.method, notification);
}
}
}
private function setupTrace(languageServerProtocol:Protocol) {
haxe.Log.trace = function(v, ?i) {
final r = [Std.string(v)];
if (i != null && i.customParams != null) {
for (v in i.customParams)
r.push(Std.string(v));
}
languageServerProtocol.sendNotification(LogMessageNotification.type, {type: Log, message: r.join(" ")});
}
}