0

I try to communicate with clangd. The first initialization is fine, but when trying to open a document with "textDocument/didOpen" i get the response "method not found". I cannot find any other method in the specification for opening documents. Is it the wrong method, or am I doing something else wrong?

My request

Content-Length: 1771

{
  "id": 2,
  "jsonrpc": "2.0",
  "method": "textDocument/didOpen",
  "params": {
    "textDocument": {
      "languageId": "cpp",
      "text": "file content...",
      "uri": "file://src/main.cpp",
      "version": 1
    }
  }
}

The response I get:

Content-Length: 77

{
  "error": {
    "code": -32601,
    "message": "method not found"
  },
  "id": 2,
  "jsonrpc": "2.0"
}
Lasersköld
  • 2,028
  • 14
  • 20

1 Answers1

3

The language server protocol distinguishes between request messages which are client --> server messages to which the server will respond, and notification messages which are client --> server messages which are meant to notify the server about something and do not require a response.

The id field is only expected for request messages (it's used to associate the response with the request). However, textDocument/didOpen is a notification message. Removing the id field should fix the error.

Further reading:

HighCommander4
  • 50,428
  • 24
  • 122
  • 194
  • Thanks! That seems to do the job. I would never had figured that out on my own. My guess was that the server would just ignore the id, but of course it makes more sense to refuse a request if it knows it is a notification. – Lasersköld Oct 27 '22 at 07:28