1010
1111use lsp_server:: { Connection , ExtractError , Request , RequestId } ;
1212use lsp_types:: { notification, request, InitializeParams } ;
13+ use serde_json:: Value ;
14+
1315use std:: { cell:: RefCell , rc:: Rc } ;
1416
15- use crate :: rpc_channel:: RpcChannel ;
17+ use crate :: rpc_channel:: { RpcChannel , SharedRpcChannel } ;
1618use crate :: vhdl_server:: VHDLServer ;
1719use crate :: vhdl_server:: VHDLServerSettings ;
1820
1921/// Set up the IO channel for `stdio` and start the VHDL language server.
2022pub fn start ( settings : VHDLServerSettings ) {
2123 let ( connection, io_threads) = Connection :: stdio ( ) ;
22- let connection_rpc = ConnectionRpcChannel :: new ( connection) ;
23- let mut server = VHDLServer :: new_settings ( connection_rpc. clone ( ) , settings ) ;
24-
24+ let connection_rpc = Rc :: new ( ConnectionRpcChannel :: new ( connection) ) ;
25+ let rpc = SharedRpcChannel :: new ( connection_rpc. clone ( ) ) ;
26+ let mut server = VHDLServer :: new_settings ( rpc , settings ) ;
2527 connection_rpc. handle_initialization ( & mut server) ;
2628 connection_rpc. main_event_loop ( server) ;
2729
@@ -38,29 +40,18 @@ struct ConnectionRpcChannel {
3840
3941impl RpcChannel for ConnectionRpcChannel {
4042 /// Send notification to the client.
41- fn send_notification (
42- & self ,
43- method : impl Into < String > ,
44- notification : impl serde:: ser:: Serialize ,
45- ) {
46- let notification = lsp_server:: Notification {
47- method : method. into ( ) ,
48- params : serde_json:: to_value ( notification) . unwrap ( ) ,
49- } ;
43+ fn send_notification ( & self , method : String , params : Value ) {
44+ let notification = lsp_server:: Notification { method, params } ;
5045
5146 trace ! ( "Sending notification: {:?}" , notification) ;
5247 self . connection . sender . send ( notification. into ( ) ) . unwrap ( ) ;
5348 }
5449
5550 /// Send request to the client.
56- fn send_request ( & self , method : impl Into < String > , params : impl serde :: ser :: Serialize ) {
51+ fn send_request ( & self , method : String , params : Value ) {
5752 let request_id = self . next_outgoing_request_id . replace_with ( |& mut id| id + 1 ) ;
5853
59- let request = Request :: new (
60- RequestId :: from ( request_id) ,
61- method. into ( ) ,
62- serde_json:: to_value ( params) . unwrap ( ) ,
63- ) ;
54+ let request = Request :: new ( RequestId :: from ( request_id) , method, params) ;
6455 self . connection . sender . send ( request. into ( ) ) . unwrap ( ) ;
6556 }
6657}
@@ -74,7 +65,7 @@ impl ConnectionRpcChannel {
7465 }
7566
7667 /// Wait for initialize request from the client and let the server respond to it.
77- fn handle_initialization < T : RpcChannel + Clone > ( & self , server : & mut VHDLServer < T > ) {
68+ fn handle_initialization ( & self , server : & mut VHDLServer ) {
7869 let ( initialize_id, initialize_params) = self . connection . initialize_start ( ) . unwrap ( ) ;
7970 let initialize_params =
8071 serde_json:: from_value :: < InitializeParams > ( initialize_params) . unwrap ( ) ;
@@ -90,7 +81,7 @@ impl ConnectionRpcChannel {
9081 }
9182
9283 /// Main event loop handling incoming messages from the client.
93- fn main_event_loop < T : RpcChannel + Clone > ( & self , mut server : VHDLServer < T > ) {
84+ fn main_event_loop ( & self , mut server : VHDLServer ) {
9485 info ! ( "Language server initialized, waiting for messages ..." ) ;
9586 while let Ok ( message) = self . connection . receiver . recv ( ) {
9687 trace ! ( "Received message: {:?}" , message) ;
@@ -113,11 +104,7 @@ impl ConnectionRpcChannel {
113104 }
114105
115106 /// Handle incoming requests from the client.
116- fn handle_request < T : RpcChannel + Clone > (
117- & self ,
118- server : & mut VHDLServer < T > ,
119- request : lsp_server:: Request ,
120- ) {
107+ fn handle_request ( & self , server : & mut VHDLServer , request : lsp_server:: Request ) {
121108 fn extract < R > (
122109 request : lsp_server:: Request ,
123110 ) -> Result < ( lsp_server:: RequestId , R :: Params ) , lsp_server:: Request >
@@ -185,11 +172,7 @@ impl ConnectionRpcChannel {
185172 }
186173
187174 /// Handle incoming notifications from the client.
188- fn handle_notification < T : RpcChannel + Clone > (
189- & self ,
190- server : & mut VHDLServer < T > ,
191- notification : lsp_server:: Notification ,
192- ) {
175+ fn handle_notification ( & self , server : & mut VHDLServer , notification : lsp_server:: Notification ) {
193176 fn extract < N > (
194177 notification : lsp_server:: Notification ,
195178 ) -> Result < N :: Params , lsp_server:: Notification >
@@ -233,11 +216,7 @@ impl ConnectionRpcChannel {
233216 }
234217
235218 /// Handle incoming responses (to requests sent by us) from the client.
236- fn handle_response < T : RpcChannel + Clone > (
237- & self ,
238- _server : & mut VHDLServer < T > ,
239- response : lsp_server:: Response ,
240- ) {
219+ fn handle_response ( & self , _server : & mut VHDLServer , response : lsp_server:: Response ) {
241220 trace ! ( "Handling response: {:?}" , response) ;
242221 // We currently can ignore incoming responses as the implemented
243222 // outgoing requests do not require confirmation by the client.
0 commit comments