Skip to content

Commit 1dffb2f

Browse files
authored
User pygls as base for the server (#672)
1 parent 89265cd commit 1dffb2f

File tree

5 files changed

+652
-25
lines changed

5 files changed

+652
-25
lines changed

pylsp/__main__.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44
import argparse
55
import logging
66
import logging.config
7-
import sys
87
import time
98

109
try:
1110
import ujson as json
1211
except Exception:
1312
import json
1413

15-
from ._version import __version__
16-
from .python_lsp import (
17-
PythonLSPServer,
18-
start_io_lang_server,
19-
start_tcp_lang_server,
20-
start_ws_lang_server,
21-
)
14+
from pylsp import __version__
15+
from pylsp.server import LSP_SERVER
2216

2317
LOG_FORMAT = "%(asctime)s {} - %(levelname)s - %(name)s - %(message)s".format(
2418
time.localtime().tm_zone
@@ -73,25 +67,18 @@ def main() -> None:
7367
args = parser.parse_args()
7468
_configure_logger(args.verbose, args.log_config, args.log_file)
7569

70+
if args.check_parent_process:
71+
LSP_SERVER.check_parent_process()
72+
7673
if args.tcp:
77-
start_tcp_lang_server(
78-
args.host, args.port, args.check_parent_process, PythonLSPServer
79-
)
74+
LSP_SERVER.start_tcp(args.host, args.port)
8075
elif args.ws:
81-
start_ws_lang_server(args.port, args.check_parent_process, PythonLSPServer)
76+
LSP_SERVER.start_ws(
77+
args.host,
78+
args.port,
79+
)
8280
else:
83-
stdin, stdout = _binary_stdio()
84-
start_io_lang_server(stdin, stdout, args.check_parent_process, PythonLSPServer)
85-
86-
87-
def _binary_stdio():
88-
"""Construct binary stdio streams (not text mode).
89-
90-
This seems to be different for Window/Unix Python2/3, so going by:
91-
https://stackoverflow.com/questions/2850893/reading-binary-data-from-stdin
92-
"""
93-
stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
94-
return stdin, stdout
81+
LSP_SERVER.start_io()
9582

9683

9784
def _configure_logger(verbose=0, log_config=None, log_file=None) -> None:

pylsp/_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import threading
1313
import time
14-
from typing import Optional
14+
from typing import Any, Iterable, List, Optional
1515

1616
import docstring_to_markdown
1717
import jedi
@@ -416,3 +416,10 @@ def get_eol_chars(text):
416416
if match:
417417
return match.group(0)
418418
return None
419+
420+
421+
def flatten(lst: Iterable[Iterable[Any]]) -> List[Any] | None:
422+
"""Flatten a iterable of iterables into a single list."""
423+
if not lst:
424+
return None
425+
return [i for sublst in lst for i in sublst]

0 commit comments

Comments
 (0)