lsp-types
lsp-types copied to clipboard
Error when deserializing notification
I have a didSave
notification from the SublimeText LSP plugin which looks like this:
{
"jsonrpc": "2.0",
"method": "textDocument/didSave",
"params": {
"textDocument": {
"uri": "file:///Users/spencerkohan/Projects/patina/examples/foo.pt"
},
"text": "func foo(x: Int) -> Bool {\n\treturn x == 0\n}"
}
}
I am trying to get a DidSaveTextDocument
notification out of it using this method:
fn cast_notification<N>(not: lsp_server::Notification) -> Result<(RequestId, N::Params), lsp_server::Notification>
where
N: lsp_types::notification::Notification,
N::Params: serde::de::DeserializeOwned,
{
not.extract(N::METHOD)
}
impl Notification {
pub fn extract<P: DeserializeOwned>(self, method: &str) -> Result<P, Notification> {
eprintln!("Notificatin params: {:?}", self.params);
if self.method == method {
let params = serde_json::from_value(self.params).unwrap_or_else(|err| {
panic!("Invalid notification\nMethod: {}\n error: {}", method, err)
});
Ok(params)
} else {
Err(self)
}
}
}
And I get this error:
invalid type: map, expected a tuple of size 2
So it looks like it's expecting textDocument
or params
to be a tuple rather than a dictionary. Is this a mal-formed notification JSON, or is there something else I'm doing incorrectly?
Your function extracts a tuple, which doesn't seem right fn cast_notification<N>(not: lsp_server::Notification) -> Result<(RequestId, N::Params), lsp_server::Notification>
?
Can't see any other tuples so that must be it