When i installed vscode-languageclient 7.0.0 to adopt LSP 3.16, i found there was a breaking change in languageclient@7.0.0 about adopting Parameter Structures concept of jsonrpc@2.0, see language client 7.0.0 changelog.
- added support to control the parameter structure when sending requests and notifications in
vscode-jsonrpc. The parameter structure can be controlled using the additional parameterStructures argument when creating a request or notification type or when sending an untyped request or notification using the sendRequest or sendNotification function. The default is ParameterStructures.auto which does the following:
- use
byPosition for messages with zero or greater than one parameter
- for one parameter it used
byName for parameters which are object literals. Uses byPosition for all other parameters.
In summary, if the request/notification parameter is not an object parameter, jsonrpc will wrap it into an array. See JSON_RPC implementation of language client.
Here are some samples of how to handle parameters in a language client jsonrpc.
-
client.sendRequest(type, true)
jsonrpc:
{
...
Params: [ true ]
}
-
client.sendRequest(type, [true])
jsonrpc:
{
...
Params: [ [ true ] ]
}
-
client.sendRequest(type, { value: true })
jsonrpc:
{
...
Params: {
value: true
}
}
To avoid breaking in language server, jsonrpc in lsp4j should de-structure the outermost array wrapper if it‘s a single array parameter.
The code change is parseParams of MessageTypeAdapter.java. If the message parameter is an array, then flatten the array first and map each child item to the parameter type.
https://github.com/eclipse/lsp4j/blob/00447d0a44d75b03b6cebf3d2720a311411efdca/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/MessageTypeAdapter.java#L241-L251
When i installed vscode-languageclient 7.0.0 to adopt LSP 3.16, i found there was a breaking change in languageclient@7.0.0 about adopting Parameter Structures concept of jsonrpc@2.0, see language client 7.0.0 changelog.
In summary, if the request/notification parameter is not an object parameter, jsonrpc will wrap it into an array. See JSON_RPC implementation of language client.
Here are some samples of how to handle parameters in a language client jsonrpc.
client.sendRequest(type, true)
jsonrpc:
{
...
Params: [ true ]
}
client.sendRequest(type, [true])
jsonrpc:
{
...
Params: [ [ true ] ]
}
client.sendRequest(type, { value: true })
jsonrpc:
{
...
Params: {
value: true
}
}
To avoid breaking in language server, jsonrpc in lsp4j should de-structure the outermost array wrapper if it‘s a single array parameter.
The code change is parseParams of MessageTypeAdapter.java. If the message parameter is an array, then flatten the array first and map each child item to the parameter type.
https://github.com/eclipse/lsp4j/blob/00447d0a44d75b03b6cebf3d2720a311411efdca/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/adapters/MessageTypeAdapter.java#L241-L251