2

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!

Lex Li
  • 60,503
  • 9
  • 116
  • 147
Sam Zhang
  • 320
  • 4
  • 17
  • I don't know the answer, but it may be helpful to look at how the [Theia IDE](https://theia-ide.org/) does it -- I believe it uses the Monaco Editor and can connect to clangd as a language server. – HighCommander4 Oct 04 '22 at 08:06
  • There's seriously no one who has implemented this as a project? I couldn't find a single post/website regarding this. I mean this sounds like such a great idea for a side project. Or maybe it isn't as simple as i thought this would be. – Tony Jan 04 '23 at 15:51
  • have you had any luck with this? – maysara Feb 04 '23 at 14:35

1 Answers1

2

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
CcccFz
  • 21
  • 5