python-lsp / python-lsp-server

Fork of the python-language-server project, maintained by the Spyder IDE team and the community
MIT License
1.76k stars 186 forks source link

pylsp is unresponsive #423

Open code2graph opened 10 months ago

code2graph commented 10 months ago

I started pylsp with

pylsp --verbose --tcp --host 127.0.0.1 --port 9999

Now I connected to it with following python code:

import json
import socket

def send_request(request):
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        sock.connect(('127.0.0.1', 9999))  # Assuming the LSP server is running on localhost and port 9999
        request_str = json.dumps(request)
        # Send the length of the request followed by the request itself
        sock.sendall((len(request_str).to_bytes(4, byteorder='little')) + request_str.encode('utf-8'))

        # Read the response length (first 4 bytes) and then the response
        response_length = int.from_bytes(sock.recv(4), byteorder='little')
        reponse = sock.recv(response_length).decode('utf-8')
        response = json.loads(reponse)

        return response

# Initialize the LSP session
initialize_request = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
        "processId": 12345,  # Arbitrary process ID
        "rootPath": "/path/to/my/repo",
        "capabilities": {},  # For simplicity, we're sending empty capabilities
    }
}

response = send_request(definition_request)
print("Definition:", response)

It does not return anything.

So I checked netstat and see :

tcp4       0      0  127.0.0.1.9999         *.*                    LISTEN

So it is listening to this port.

I also tried to do telnet and send the following command. But the server does not return anything. What am I missing here?

telnet 127.0.0.1 9999
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
        "processId": 12345,
        "rootPath": "/path/to/my/repo",
        "capabilities": {}
    }
}
sansmoraxz commented 3 months ago

Same here, looks like this has been an issue for a long time. At least for TCP.

Websockets do work though.