nvim-langserver-shim icon indicating copy to clipboard operation
nvim-langserver-shim copied to clipboard

Testing with the OCaml language server

Open ghost opened this issue 9 years ago • 12 comments

This is a follow up from the discussion in the Reason editorsupport channel about using the language server for reason. I have moved the server out into a separate package at ocaml-language-server and the vscode reason client now uses this too.

The README describes the different ways to launch it. You should just be able to start it with ocaml-language-server --stdio if you want to run it over stdio.

Let me know if you try it and run into problems. There are some custom requests used that I have not documented yet but you can find most of them here.

ghost avatar Nov 22 '16 21:11 ghost

Awesome! I will try that out over this week. That seems very straightforward. Thanks for your help!

tjdevries avatar Nov 22 '16 23:11 tjdevries

Seems like having a doc section for all list of languages would be great

prabirshrestha avatar Nov 23 '16 05:11 prabirshrestha

I should point them to here: https://github.com/Microsoft/language-server-protocol/wiki/Protocol-Implementations

I will add this to the docs.

tjdevries avatar Nov 23 '16 15:11 tjdevries

@freebroccolo Any idea why I would be getting this message?

debug: Sending request: 158,
{'id': 1, 
  'jsonrpc': '2.0', 
  'method': 'initialize', 
  'params': {'capabilities': {}, 'rootPath': 'file:///home/user/test/example-ocaml-merlin'}
}

Message was: {
  "response": {
    "id": 1,
    "jsonrpc": "2.0",
    "error": {
      "code": -32603,
      "message": "Request initialize failed with message: Cannot read property \"\"path\"\" of undefined"
    }
  },
  "request": {
    "id": 1,
    "jsonrpc": "2.0",
    "method": "initialize",
    "params": {
      "capabilities": {
        
      },
      "rootPath": "file:\/\/\/home\/user\/test\/example-ocaml-merlin"
    }
  }
}
error: Could not connect to: 158

tjdevries avatar Nov 23 '16 18:11 tjdevries

(I can post an issue, but I'm guess I'm just not setting something up correctly)

tjdevries avatar Nov 23 '16 18:11 tjdevries

@tjdevries I believe that's due to the fact that the server is expecting the client settings to be synchronized and path is one of the keys. Those settings are used for different things like the paths to binaries (see here).

The default settings can be found here.

Although it does not show it in the master branch for the client yet, the reason.server.languages setting also does allow values like ["ocaml", "reason"].

ghost avatar Nov 23 '16 19:11 ghost

Also, you can find where the configuration settings are synchronized as the server is launched here. The vscode.workspace.getConfiguration("reason") fetches those and they are sent in initializationOptions. Then the server gets them here.

ghost avatar Nov 23 '16 19:11 ghost

I've gone ahead and modified the server initialization to set defaults automatically if they aren't sent by the client.

ghost avatar Nov 25 '16 06:11 ghost

So I'm trying to figure out how to respond to a few of your internal requests, and I'm not sure exactly what the response should look like. I have this situation currently:

# I receive this and I'm not sure how to respond.
info: ( 62:     on_request): {'request': {'id': 0, 'jsonrpc': '2.0', 'method': 'reason.client.giveWordAtPosition', 'params': {'uri': 'file:///home/tj/Downloads/example-ocaml-merlin/src/main.ml', 'position': {'character': 9, 'line': 6}}}}

tjdevries avatar Nov 26 '16 23:11 tjdevries

@tjdevries most of the implementations for those on the client side can be found here.

That particular request is handled here. Basically it is asking for the editor to expand the position to the word range and then return the document text in that range.

ghost avatar Nov 26 '16 23:11 ghost

Do I just send the string directly or do I need to format it into a langserver message? I have it currently sending a langserver request, but it doesn't seem to be doing anything.

tjdevries avatar Nov 27 '16 00:11 tjdevries

I believe it has to be formatted as a JSON-RPC response since the request is for a method that returns a string. So I think it should look something like this:

request:

{'request': {'id': 0, 'jsonrpc': '2.0', 'method': 'reason.client.giveWordAtPosition', 'params': … }}

response:

{'response': {'id': 0, 'jsonrpc': '2.0', 'result': 'foo'}}

ghost avatar Nov 27 '16 00:11 ghost