Testing with the OCaml language server
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.
Awesome! I will try that out over this week. That seems very straightforward. Thanks for your help!
Seems like having a doc section for all list of languages would be great
I should point them to here: https://github.com/Microsoft/language-server-protocol/wiki/Protocol-Implementations
I will add this to the docs.
@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
(I can post an issue, but I'm guess I'm just not setting something up correctly)
@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"].
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.
I've gone ahead and modified the server initialization to set defaults automatically if they aren't sent by the client.
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 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.
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.
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'}}