-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
executable file
·63 lines (46 loc) · 1.75 KB
/
server.py
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
#!/usr/bin/env python
from pygls.features import COMPLETION, TEXT_DOCUMENT_DID_OPEN, TEXT_DOCUMENT_DID_CHANGE
from pygls.server import LanguageServer
from pygls.types import *
from pygls.workspace import *
import semprlsp
import sys
ruleChecker = semprlsp.RuleChecker()
server = LanguageServer()
conditionsAndEffects = set()
for c in ruleChecker.listConditions():
conditionsAndEffects.add(c)
for e in ruleChecker.listEffects():
conditionsAndEffects.add(e)
completionItems = [CompletionItem(i, kind=CompletionItemKind.Function) for i in conditionsAndEffects]
@server.feature(COMPLETION, trigger_characters=[])
def completions(params: CompletionParams):
return CompletionList(False, completionItems);
def get_diagnostics(rules):
errs = ruleChecker.getErrors(rules)
dias = []
for err in errs:
diagnostic = Diagnostic(
range=Range(Position(line=err.line, character=err.start),
Position(line=err.line, character=err.end)),
message=err.description,
severity=DiagnosticSeverity.Error,
source="semprlsp"
)
dias.append(diagnostic)
return dias
@server.feature(TEXT_DOCUMENT_DID_CHANGE)
def did_change(ls, params: DidChangeTextDocumentParams):
text_doc = ls.workspace.get_document(params.textDocument.uri)
rulestring = ""
for i,l in enumerate(text_doc.lines):
rulestring += l
dias = get_diagnostics(rulestring)
ls.publish_diagnostics(text_doc.uri, dias)
@server.feature(TEXT_DOCUMENT_DID_OPEN)
def did_open(ls, params : DidOpenTextDocumentParams):
dias = get_diagnostics(params.textDocument.text)
ls.publish_diagnostics(params.textDocument.uri, dias)
print("starting server")
server.start_tcp('localhost', 8066)
#server.start_io()