@@ -187,6 +187,10 @@ def cli(): ...
187187@click .option (
188188 "--stdio" , "stdio" , is_flag = True , default = False , help = "Use stdio communication"
189189)
190+ @click .option (
191+ "--tcp" , "tcp_auto" , is_flag = True , default = False ,
192+ help = "Start TCP server on a random free port; prints 'port:<N>' to stdout for client discovery"
193+ )
190194@click .option ("--host" , "host" , default = None , help = "Host for TCP and WS server" )
191195@click .option (
192196 "--port" , "port" , default = None , type = int , help = "Port for TCP and WS server"
@@ -197,6 +201,7 @@ def start_lsp(
197201 tcp : int | None ,
198202 ws : bool ,
199203 stdio : bool ,
204+ tcp_auto : bool ,
200205 host : str | None ,
201206 port : int | None ,
202207):
@@ -212,7 +217,11 @@ def start_lsp(
212217 except Exception as e :
213218 logger .info (e )
214219
215- if tcp is not None :
220+ if tcp_auto :
221+ comm_type = communication_utils .CommunicationType .TCP
222+ host = "127.0.0.1"
223+ port = None # main.start() will pick a free port and print it
224+ elif tcp is not None :
216225 comm_type = communication_utils .CommunicationType .TCP
217226 port = tcp
218227 host = "127.0.0.1"
@@ -221,7 +230,7 @@ def start_lsp(
221230 elif stdio is True :
222231 comm_type = communication_utils .CommunicationType .STDIO
223232 else :
224- raise ValueError ("Specify either --tcp, --ws or --stdio" )
233+ raise ValueError ("Specify either --tcp, --socket, -- ws or --stdio" )
225234
226235 asyncio .run (
227236 wm_lsp_server .start (comm_type = comm_type , host = host , port = port , log_level = log_level )
0 commit comments