@@ -17,6 +17,7 @@ use jsonrpc_core::{self as jsonrpc, Id};
17
17
use vfs:: Vfs ;
18
18
use serde;
19
19
use serde:: ser:: { Serialize , Serializer , SerializeStruct } ;
20
+ use serde:: Deserialize ;
20
21
use serde_json;
21
22
22
23
use version;
@@ -517,10 +518,10 @@ struct RawMessage {
517
518
}
518
519
519
520
impl RawMessage {
520
- fn parse_as_request < ' de , R , P > ( & ' de self ) -> Result < Request < R > , jsonrpc:: Error >
521
+ fn parse_as_request < ' de , R > ( & ' de self ) -> Result < Request < R > , jsonrpc:: Error >
521
522
where
522
- R : LSPRequest < Params = P > ,
523
- P : serde:: Deserialize < ' de > ,
523
+ R : LSPRequest ,
524
+ < R as LSPRequest > :: Params : serde:: Deserialize < ' de > ,
524
525
{
525
526
// FIXME: We only support numeric responses, ideally we should switch from using parsed usize
526
527
// to using jsonrpc_core::Id
@@ -530,9 +531,9 @@ impl RawMessage {
530
531
_ => None ,
531
532
} ;
532
533
533
- let params = P :: deserialize ( & self . params ) . map_err ( |e| {
534
+ let params = R :: Params :: deserialize ( & self . params ) . map_err ( |e| {
534
535
debug ! ( "error when parsing as request: {}" , e) ;
535
- jsonrpc:: Error :: invalid_request ( )
536
+ jsonrpc:: Error :: invalid_params ( format ! ( "{}" , e ) )
536
537
} ) ?;
537
538
538
539
match parsed_numeric_id {
@@ -546,14 +547,14 @@ impl RawMessage {
546
547
}
547
548
}
548
549
549
- fn parse_as_notification < ' de , T , P > ( & ' de self ) -> Result < Notification < T > , jsonrpc:: Error >
550
+ fn parse_as_notification < ' de , T > ( & ' de self ) -> Result < Notification < T > , jsonrpc:: Error >
550
551
where
551
- T : LSPNotification < Params = P > ,
552
- P : serde:: Deserialize < ' de > ,
552
+ T : LSPNotification ,
553
+ < T as LSPNotification > :: Params : serde:: Deserialize < ' de > ,
553
554
{
554
555
let params = T :: Params :: deserialize ( & self . params ) . map_err ( |e| {
555
556
debug ! ( "error when parsing as notification: {}" , e) ;
556
- jsonrpc:: Error :: invalid_request ( )
557
+ jsonrpc:: Error :: invalid_params ( format ! ( "{}" , e ) )
557
558
} ) ?;
558
559
559
560
Ok ( Notification {
@@ -680,12 +681,12 @@ mod test {
680
681
let raw = RawMessage {
681
682
method : "initialize" . to_owned ( ) ,
682
683
id : None ,
683
- params : serde_json:: Value :: Null ,
684
+ params : serde_json:: Value :: Object ( serde_json :: Map :: new ( ) ) ,
684
685
} ;
685
686
let notification: Notification < notifications:: Initialized > =
686
687
raw. parse_as_notification ( ) . unwrap ( ) ;
687
688
688
- let expected = Notification :: < notifications:: Initialized > :: new ( ( ) ) ;
689
+ let expected = Notification :: < notifications:: Initialized > :: new ( InitializedParams { } ) ;
689
690
690
691
assert_eq ! ( notification. params, expected. params) ;
691
692
assert_eq ! ( notification. _action, expected. _action) ;
@@ -752,4 +753,11 @@ mod test {
752
753
753
754
assert_eq ! ( * deser. get( "params" ) . unwrap( ) , json!( { } ) ) ;
754
755
}
756
+
757
+ #[ test]
758
+ fn deserialize_message_empty_params ( ) {
759
+ let msg = r#"{"jsonrpc":"2.0","method":"initialized","params":{}}"# ;
760
+ let parsed = RawMessage :: try_parse ( msg) . unwrap ( ) . unwrap ( ) ;
761
+ parsed. parse_as_notification :: < notifications:: Initialized > ( ) . unwrap ( ) ;
762
+ }
755
763
}
0 commit comments