How to start clangd via web socket

427 views Asked by At

I wanted to integrate Clangd with Monaco Editor and while trying to achieve this I found that I can't start Clangd via Web Sockets.

When I run clangd in my terminal, it outputs Starting LSP over stdin/stdout, is there a way to let it launch a web socket server or do I have to implement this myself? I'm aware that the Python LSP has a --ws flag you can turn on to start a server. But I didn't find something like that with Clangd.

Or is there a better way to integrate Clangd with Monaco Editor? I'm currently going with Monaco Language Client.

Thanks in advance!

1

There are 1 answers

0
CcccFz On

Success Demo

You can use a proxy server that convert clangd stdout to websocket, like that:

  1. Run jsonrpc-ws-proxy, with servers.yml:

langservers:
  cpp:
    - clangd 
    - --compile-commands-dir
    - /proj

Notice that the /proj dir must cotains the compile_commands.json file that can generate by bear tool (apt install -y bear).

  1. reference to monaco-languageclient client example, and integrate to Monaco Editor