Skip to content

Commit 88ab89f

Browse files
authored
Merge pull request #12 from common-workflow-language/move-to-pygls
Move from pylspclient to pygls
2 parents 2783605 + 4a0bea1 commit 88ab89f

File tree

5 files changed

+84
-236
lines changed

5 files changed

+84
-236
lines changed

cwl_language_server/callbacks.py

-157
This file was deleted.

cwl_language_server/main.py

+83-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,85 @@
1-
#!/usr/bin/env python
2-
import sys
3-
4-
import pylspclient
5-
6-
import callbacks
7-
8-
def main():
9-
stdin = sys.stdout.buffer
10-
stdout = sys.stdin.buffer
11-
json_rpc_endpoint = pylspclient.JsonRpcEndpoint(stdin, stdout)
12-
lsp_endpoint = pylspclient.LspEndpoint(json_rpc_endpoint,
13-
method_callbacks={
14-
'initialize': callbacks.initialize,
15-
'textDocument/completion': callbacks.completion,
16-
},
17-
notify_callbacks={
18-
'initialized': callbacks.initialized,
19-
'workspace/didChangeConfiguration': callbacks.didChangeConfiguration,
20-
'textDocument/didOpen': callbacks.didOpen,
21-
'textDocument/didChange': callbacks.didChange,
22-
'textDocument/didClose': callbacks.didClose,
23-
})
24-
lsp_endpoint.start()
1+
#!/usr/bin/env python3
2+
3+
from glob import glob
4+
from os.path import dirname, basename
5+
from urllib.parse import urlparse
6+
7+
from pygls.server import LanguageServer
8+
from pygls.features import (COMPLETION, TEXT_DOCUMENT_DID_CHANGE,
9+
TEXT_DOCUMENT_DID_CLOSE, TEXT_DOCUMENT_DID_OPEN,
10+
WORKSPACE_DID_CHANGE_CONFIGURATION)
11+
from pygls.types import (CompletionItem, CompletionList, CompletionParams,
12+
ConfigurationItem, ConfigurationParams, Diagnostic,
13+
DidChangeTextDocumentParams,
14+
DidCloseTextDocumentParams, DidOpenTextDocumentParams,
15+
Position, Range, DidChangeConfigurationParams)
16+
17+
server = LanguageServer()
18+
19+
20+
@server.feature(COMPLETION, trigger_characters=[': ', '- '])
21+
def completions(ls, params: CompletionParams):
22+
ls.show_message_log('cwlls: Start completion...')
23+
ctx = params.context
24+
line = params.position.line
25+
col = params.position.character
26+
uri = params.textDocument.uri
27+
28+
doc = ls.workspace.get_document(params.textDocument.uri)
29+
30+
field = doc.lines[line][0:col].lstrip().rstrip(': ')
31+
if not field:
32+
return CompletionList(False, [])
33+
34+
if field in completion_list:
35+
return completion_list[field]
36+
if field == 'run':
37+
cwls = glob("{}/*.cwl".format(dirname(urlparse(uri).path)))
38+
return [CompletionItem(basename(cwl))
39+
for cwl in cwls if cwl != urlparse(uri).path]
40+
return CompletionList(False, [])
41+
42+
43+
completion_list = {
44+
'cwlVersion': [
45+
CompletionItem('draft-2', deprecated=True),
46+
CompletionItem('draft-3.dev1', deprecated=True),
47+
CompletionItem('draft-3.dev2', deprecated=True),
48+
CompletionItem('draft-3.dev3', deprecated=True),
49+
CompletionItem('draft-3.dev4', deprecated=True),
50+
CompletionItem('draft-3.dev5', deprecated=True),
51+
CompletionItem('draft-3', deprecated=True),
52+
CompletionItem('draft-4.dev1', deprecated=True),
53+
CompletionItem('draft-4.dev2', deprecated=True),
54+
CompletionItem('draft-4.dev3', deprecated=True),
55+
CompletionItem('v1.0.dev4', deprecated=True),
56+
CompletionItem('v1.0'),
57+
],
58+
}
59+
60+
61+
@server.feature(TEXT_DOCUMENT_DID_CHANGE)
62+
def did_change(ls, params: DidChangeTextDocumentParams):
63+
"""Text document did change notification."""
64+
ls.show_message_log('cwlls: Start didChange...')
65+
66+
67+
@server.feature(TEXT_DOCUMENT_DID_CLOSE)
68+
def did_close(ls, params: DidCloseTextDocumentParams):
69+
"""Text document did close notification."""
70+
ls.show_message_log('cwlls: Start didClose...')
71+
72+
73+
@server.feature(TEXT_DOCUMENT_DID_OPEN)
74+
async def did_open(ls, params: DidOpenTextDocumentParams):
75+
"""Text document did open notification."""
76+
ls.show_message_log('cwlls: Start didOpen...')
77+
78+
79+
@server.feature(WORKSPACE_DID_CHANGE_CONFIGURATION)
80+
def did_change_configuration(ls, params: DidChangeConfigurationParams):
81+
ls.show_message_log('cwlls: Start didChangeConfiguration...')
82+
2583

2684
if __name__ == '__main__':
27-
main()
85+
server.start_io()

examples/echo.cwl

-19
This file was deleted.

examples/first-step.py

-34
This file was deleted.

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
typing-extensions
2-
git+https://github.com/yeger00/pylspclient.git@
2+
git+https://github.com/openlawlibrary/pygls.git@

0 commit comments

Comments
 (0)