-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use pipe transport to communicate between LSP client server (#410)
- Loading branch information
1 parent
d2f75f7
commit fe031d8
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
"""IO handling to communicate with LSP client.""" | ||
|
||
import argparse | ||
import contextlib | ||
import socket | ||
import sys | ||
from typing import Optional, Sequence | ||
|
||
|
||
def parse_args(args: Optional[Sequence[str]] = None) -> argparse.Namespace: | ||
"""Parse command line arguments.""" | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--stdio", action="store_true") | ||
parser.add_argument("--socket", type=int, default=None) | ||
parser.add_argument("--pipe", type=str, default=None) | ||
parser.add_argument("--clientProcessId", type=int, default=None) | ||
|
||
return parser.parse_args(args) | ||
|
||
|
||
@contextlib.contextmanager | ||
def use_pipe(pipe_name: str): | ||
if sys.platform == "win32": | ||
with open(pipe_name, "r+b") as f: | ||
yield (f, f) | ||
else: | ||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock.connect(pipe_name) | ||
f = sock.makefile("rwb") | ||
yield (f, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters