I’m trying to build a language server from scratch just for learning how it works, so far I’ve got the initialize
method request and I’ve responded with empty capabilities and server info, but I’m not getting any further requests from neovim, (using STDIO
)
import rpc
import sys
import logging
import json
logging.basicConfig(filename='server.log',
level=logging.DEBUG,
filemode='w',
format='%(asctime)s %(levelname)s - %(message)s')
logging.info('Server logging initiated')
while True:
header = ''
while True:
line = sys.stdin.readline().strip()
if not line:
break
header = line
bytes_to_read = int(header[len('Content-Length: '):])
content = sys.stdin.read(bytes_to_read)
request = json.loads(content)
client_name = request['params']['clientInfo']['name']
client_version = request['params']['clientInfo']['version']
logging.info(f'Connected to client: {client_name} {client_version}')
logging.info(f'Received method: {request['method']}')
response = {
'jsonrpc': '2.0',
'id': request['id'],
'result': {
'serverInfo': {
'name': 'my-ls',
'version': '0.1.0'
},
'capabilities': {}
}
}
sys.stdout.write(f'Content-Length: {len(json.dumps(response))}rnrn')
sys.stdout.write(json.dumps(response))
sys.stdout.flush()
logging.info(f'Sent response')
here’s the log that I get:
2024-06-03 21:10:01,296 INFO - Server logging initiated
2024-06-03 21:10:01,296 INFO - Connected to client: Neovim 0.9.4
2024-06-03 21:10:01,296 INFO - Received method: initialize
2024-06-03 21:10:01,296 INFO - Sent response
what I expect to get is the initialized
method notification and further messages, once I sent the response for the initialize
method I get nothing. I checked neovims lsp.log
and it only shows the request that was sent.