Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 20 additions & 10 deletions src/malls/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ def configure_argument_parser(parser: argparse.ArgumentParser, subparser: bool =

Users must choose EITHER file I/O OR TCP socket mode (mutually exclusive).
"""
description = """
MAL Language server.
By default uses STDI/O.
"""
if subparser:
subparser = argparse.ArgumentParser("mal-ls", "MAL Language Server")
subparser = argparse.ArgumentParser(prog="mal-ls", description=description)
parser.add_subparsers().add_parser(subparser)
parser = subparser
else:
parser.description = "MAL Language Server"
parser.description = description

# ---- Mutually Exclusive Group: File I/O vs. TCP Socket ----
mode_group = parser.add_mutually_exclusive_group(required=True)
mode_group = parser.add_mutually_exclusive_group()

# File I/O
file_group = mode_group.add_argument_group("File I/O", "Use file-based communication")
Expand Down Expand Up @@ -60,8 +64,12 @@ def configure_argument_parser(parser: argparse.ArgumentParser, subparser: bool =
help="Port to bind the TCP server to (default: 8080).",
)

mode_group.add_argument("--stdio", action="store_true", help="Use stdio")
mode_group.add_argument("--tcp", action="store_true", help="Use TCP mode")
mode_group.add_argument(
"--stdio", action=argparse.BooleanOptionalAction, default=True, help="Use stdio"
)
mode_group.add_argument(
"--tcp", action=argparse.BooleanOptionalAction, default=False, help="Use TCP mode"
)

# Loggin
logging = parser.add_argument_group("Logging", "Configure logging options")
Expand Down Expand Up @@ -92,7 +100,7 @@ def fileio(args: argparse.Namespace):


def uses_tcpsocket(args: argparse.Namespace) -> bool:
return bool(args.tcp or args.host or args.port)
return args.tcp


def tcpsocket(args: argparse.Namespace):
Expand Down Expand Up @@ -150,12 +158,14 @@ def main(args: argparse.Namespace | None = None):

configure_logging(args)

if uses_fileio(args):
i, o = fileio(args)
start_fileio_server(i, o)
elif uses_tcpsocket(args):
# Default to STDI/O
if uses_tcpsocket(args):
i, o = tcpsocket(args)
start_fileio_server(i, o)
else:
# In case a check is needed, use `uses_fileio(args)`
i, o = fileio(args)
start_fileio_server(i, o)


if __name__ == "__main__":
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/test_base_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def close(self):
self.steps -= 1


# TODO: create fake endpoint class (or similar) so the input can be stepped


# https://github.com/python-lsp/python-lsp-server/blob/develop/pylsp/python_lsp.py#L58
def server_output(
input: typing.BinaryIO, timeout: float | None = MAX_TIMEOUT
Expand Down
Loading