-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver.js
44 lines (34 loc) · 1004 Bytes
/
server.js
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
'use strict';
const langServer = require('vscode-languageserver');
const alexVSCode = require('alex-vscode');
const connection = langServer.createConnection(process.stdin, process.stdout);
const documents = new langServer.TextDocuments();
function validate(document) {
const results = alexVSCode(document);
if (results.length === 0) {
return;
}
connection.sendDiagnostics({
uri: document.uri,
diagnostics: results.map(result => {
result.message = 'alex: ' + result.message;
return result;
})
});
}
function validateAll() {
return documents.all().map(document => validate(document));
}
connection.onInitialize(() => {
validateAll();
return {
capabilities: {
textDocumentSync: documents.syncKind
}
};
});
connection.onDidChangeConfiguration(() => validateAll());
connection.onDidChangeWatchedFiles(() => validateAll());
documents.onDidChangeContent(event => validate(event.document));
documents.listen(connection);
connection.listen();