eclipse-lsp4j / lsp4j

A Java implementation of the language server protocol intended to be consumed by tools and language servers implemented in Java.
https://eclipse.org/lsp4j
Other
613 stars 145 forks source link

`id` parameter in response is of type `String` when editor expects `id` to be of type `Number` #687

Closed StratusFearMe21 closed 1 year ago

StratusFearMe21 commented 1 year ago

When the Helix text editor begins a conversation with the languagetool-languageserver (made with this library), it first sends this request to the language server

{
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "capabilities": {
      "textDocument": {
        "codeAction": {
          "codeActionLiteralSupport": {
            "codeActionKind": {
              "valueSet": [
                "",
                "quickfix",
                "refactor",
                "refactor.extract",
                "refactor.inline",
                "refactor.rewrite",
                "source",
                "source.organizeImports"
              ]
            }
          }
        },
        "completion": {
          "completionItem": {
            "insertReplaceSupport": true,
            "resolveSupport": {
              "properties": [
                "documentation",
                "detail",
                "additionalTextEdits"
              ]
            },
            "snippetSupport": false
          },
          "completionItemKind": {}
        },
        "hover": {
          "contentFormat": [
            "markdown"
          ]
        },
        "publishDiagnostics": {},
        "rename": {
          "dynamicRegistration": false,
          "honorsChangeAnnotations": false,
          "prepareSupport": false
        },
        "signatureHelp": {
          "signatureInformation": {
            "activeParameterSupport": true,
            "documentationFormat": [
              "markdown"
            ],
            "parameterInformation": {
              "labelOffsetSupport": true
            }
          }
        }
      },
      "window": {
        "workDoneProgress": true
      },
      "workspace": {
        "applyEdit": true,
        "configuration": true,
        "didChangeConfiguration": {
          "dynamicRegistration": false
        },
        "executeCommand": {
          "dynamicRegistration": false
        },
        "symbol": {
          "dynamicRegistration": false
        },
        "workspaceFolders": true
      }
    },
    "processId": 27748,
    "rootPath": "/home/isaacm/School/Lang",
    "rootUri": "file:///home/isaacm/School/Lang",
    "workspaceFolders": [
      {
        "name": "Lang",
        "uri": "file:///home/isaacm/School/Lang"
      }
    ]
  },
  "id": 0
}

The language server responds with this

{
  "jsonrpc": "2.0",
  "id": "0",
  "result": {
    "capabilities": {
      "textDocumentSync": 1,
      "codeActionProvider": true,
      "executeCommandProvider": {
        "commands": [
          "langugageTool.acceptSuggestion"
        ]
      }
    }
  }
}

In the original request, the id was of type Number, however, the language server responds with an id of type String, this confuses the text editor due to it expecting Int(0) and not Str("0")

2022-12-12T19:24:33.068 helix_lsp::transport [ERROR] Discarding Language Server response without a request (id=Str("0")) Ok(Object {"capabilities": Object {"codeActionProvider": Bool(true), "executeCommandProvider": Object {"commands": Array [String("langugageTool.acceptSuggestion")]}, "textDocumentSync": Number(1)}})

While debugging, I found that this error is caused by the request alone. When I netcatted this request directly into the language server, in both formatted and minified form, the language server responded with the same incorrect id type.

cat test.json | nc -l -p 3432
languagetool-languageserver 3432

Happy hacking! And thanks in advance for taking my issue into consideration!

StratusFearMe21 commented 1 year ago

Whoops, didn't realize that the language server that does this uses lsp4j version 0.2.0, oops

StratusFearMe21 commented 1 year ago

Yup, 0.4.0 fixed this issue