-
Notifications
You must be signed in to change notification settings - Fork 204
/
messages.ts
101 lines (83 loc) · 3.02 KB
/
messages.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
// To make it easier for me to serilize json on stdin
export class BufferedBySeperatorHandler {
static seperator = new Buffer('fHxhdG9tdHN8fA==', 'base64').toString(); // Mustn't speak his name
totalTrailing: string[] = [];
incompleteEnding = '';
constructor(public callback: (data: any) => any) { }
handle(data: any) {
var m = data.toString(); // Fix this and use encoding.
if (!m && this.totalTrailing.length) { // process totalTrailing
m = this.totalTrailing.shift();
// If length == 1. We should account for our previous incompleteEnding
if (this.totalTrailing.length == 1 && this.incompleteEnding) {
m = m + this.incompleteEnding;
this.incompleteEnding = '';
// Adding an incompleteEnding might have made it *two* messages
// so keep processing
this.handle(m);
return;
}
}
else {
m = m.toString();
var parts = m.split(BufferedBySeperatorHandler.seperator);
if (parts.length == 2 && parts[1] == '') { // Great the perfect match!
}
else if (parts.length > 1) { // oh oh ... an unperfect match and we have more than 1 items
// -1 because the last part is just because we always end on trailer
// Potential TODO: If the last part isn't "seperator" then we have an incomplete part
var more = parts.slice(1, parts.length - 1);
this.totalTrailing = this.totalTrailing.concat(more);
// If the last part is not "" we have an imperfect ending
this.incompleteEnding = parts[parts.length - 1];
}
m = parts[0];
}
// TADA
this.callback(m);
// Process remaining
if (this.totalTrailing.length) {
this.handle('');
}
}
}
export var orphanExitCode = 100;
// Parent makes queries
// Child responds
export interface Message<T> {
message: string;
id: string;
data: T;
}
///////////////////////////////////////////// MESSAGES ///////////////////////////////////////////
///ts:import=programManager
import programManager = require('../main/lang/programManager'); ///ts:import:generated
export var echo = 'echo';
export interface EchoQuery {
echo: any;
}
export interface EchoResponse {
echo: any;
}
export var updateText = 'updateText';
export interface UpdateTextQuery {
filePath: string;
text: string;
}
export interface UpdateTextResponse { }
export var getErrorsForFile = 'getErrorsForFile';
export interface GetErrorsForFileQuery {
filePath: string;
}
export interface GetErrorsForFileResponse {
errors: programManager.TSError[];
}
export var getCompletionsAtPosition = 'getCompletionsAtPosition';
export interface GetCompletionsAtPositionQuery {
filePath: string;
position: number;
prefix: string;
}
export interface GetCompletionsAtPositionResponse {
completions: programManager.Completion[];
}