Skip to content

Commit

Permalink
Use pipe transport to communicate between LSP client server (microsof…
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored Jan 10, 2024
1 parent d2f75f7 commit fe031d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
32 changes: 32 additions & 0 deletions bundled/tool/lsp_io.py
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)
9 changes: 8 additions & 1 deletion bundled/tool/lsp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def update_environ_path() -> None:
# **********************************************************
# pylint: disable=wrong-import-position,import-error
import lsp_edit_utils as edit_utils
import lsp_io
import lsp_jsonrpc as jsonrpc
import lsp_utils as utils
import lsprotocol.types as lsp
Expand Down Expand Up @@ -661,4 +662,10 @@ def log_always(message: str) -> None:
# Start the server.
# *****************************************************
if __name__ == "__main__":
LSP_SERVER.start_io()
args = lsp_io.parse_args()
if args.pipe:
with lsp_io.use_pipe(args.pipe) as (rpipe, wpipe):
LSP_SERVER.start_io(rpipe, wpipe)
else:
# default is always the stdio option.
LSP_SERVER.start_io()
2 changes: 2 additions & 0 deletions src/common/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
LanguageClientOptions,
RevealOutputChannelOn,
ServerOptions,
TransportKind,
} from 'vscode-languageclient/node';
import { DEBUG_SERVER_SCRIPT_PATH, SERVER_SCRIPT_PATH } from './constants';
import { traceError, traceInfo, traceVerbose } from './logging';
Expand Down Expand Up @@ -56,6 +57,7 @@ async function createServer(
command,
args,
options: { cwd, env: newEnv },
transport: TransportKind.pipe,
};

// Options to control the language client
Expand Down

0 comments on commit fe031d8

Please sign in to comment.