Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions pylsp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
import argparse
import logging
import logging.config
import sys
import time

try:
import ujson as json
except Exception:
import json

from ._version import __version__
from .python_lsp import (
PythonLSPServer,
start_io_lang_server,
start_tcp_lang_server,
start_ws_lang_server,
)
from pylsp import __version__
from pylsp.server import LSP_SERVER

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

if args.check_parent_process:
LSP_SERVER.check_parent_process()

if args.tcp:
start_tcp_lang_server(
args.host, args.port, args.check_parent_process, PythonLSPServer
)
LSP_SERVER.start_tcp(args.host, args.port)
elif args.ws:
start_ws_lang_server(args.port, args.check_parent_process, PythonLSPServer)
LSP_SERVER.start_ws(
args.host,
args.port,
)
else:
stdin, stdout = _binary_stdio()
start_io_lang_server(stdin, stdout, args.check_parent_process, PythonLSPServer)


def _binary_stdio():
"""Construct binary stdio streams (not text mode).

This seems to be different for Window/Unix Python2/3, so going by:
https://stackoverflow.com/questions/2850893/reading-binary-data-from-stdin
"""
stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
return stdin, stdout
LSP_SERVER.start_io()


def _configure_logger(verbose=0, log_config=None, log_file=None) -> None:
Expand Down
9 changes: 8 additions & 1 deletion pylsp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
import threading
import time
from typing import Optional
from typing import Any, Iterable, List, Optional

import docstring_to_markdown
import jedi
Expand Down Expand Up @@ -416,3 +416,10 @@ def get_eol_chars(text):
if match:
return match.group(0)
return None


def flatten(lst: Iterable[Iterable[Any]]) -> List[Any] | None:
"""Flatten a iterable of iterables into a single list."""
if not lst:
return None
return [i for sublst in lst for i in sublst]
Loading
Loading