55) ]
66#![ cfg_attr( docsrs, feature( doc_cfg, doc_auto_cfg) ) ]
77
8+ use std:: ops:: ControlFlow ;
9+
810use async_lsp:: {
9- client_monitor:: ClientProcessMonitorLayer , concurrency:: ConcurrencyLayer ,
10- server:: LifecycleLayer ,
11+ ClientSocket , client_monitor:: ClientProcessMonitorLayer , concurrency:: ConcurrencyLayer ,
12+ router :: Router , server:: LifecycleLayer , tracing :: TracingLayer ,
1113} ;
14+ use lsp_types:: { notification as notif, request as req} ;
1215use tower:: ServiceBuilder ;
1316
14- use crate :: server:: Server ;
17+ use crate :: global_state:: GlobalState ;
18+
19+ mod global_state;
20+ mod handlers;
21+ mod proto;
22+ mod utils;
23+ mod vfs;
24+
25+ pub ( crate ) type NotifyResult = ControlFlow < async_lsp:: Result < ( ) > > ;
26+
27+ fn new_router ( client : ClientSocket ) -> Router < GlobalState > {
28+ let this = GlobalState :: new ( client) ;
29+ let mut router = Router :: new ( this) ;
1530
16- mod server;
31+ // Lifecycle
32+ router
33+ . request :: < req:: Initialize , _ > ( GlobalState :: on_initialize)
34+ . notification :: < notif:: Initialized > ( GlobalState :: on_initialized)
35+ . request :: < req:: Shutdown , _ > ( |_, _| std:: future:: ready ( Ok ( ( ) ) ) )
36+ . notification :: < notif:: Exit > ( |_, _| ControlFlow :: Break ( Ok ( ( ) ) ) ) ;
37+
38+ // Notifications
39+ router
40+ . notification :: < notif:: DidOpenTextDocument > ( handlers:: did_open_text_document)
41+ . notification :: < notif:: DidCloseTextDocument > ( handlers:: did_close_text_document)
42+ . notification :: < notif:: DidChangeTextDocument > ( handlers:: did_change_text_document) ;
43+
44+ router
45+ }
1746
1847/// Start the LSP server over stdin/stdout.
1948///
@@ -35,11 +64,12 @@ pub async fn run_server_stdio() -> solar_interface::Result<()> {
3564
3665 let ( eloop, _) = async_lsp:: MainLoop :: new_server ( |client| {
3766 ServiceBuilder :: new ( )
67+ . layer ( TracingLayer :: default ( ) )
3868 . layer ( LifecycleLayer :: default ( ) )
3969 // TODO: infer concurrency
4070 . layer ( ConcurrencyLayer :: new ( 2 . try_into ( ) . unwrap ( ) ) )
4171 . layer ( ClientProcessMonitorLayer :: new ( client. clone ( ) ) )
42- . service ( Server :: new_router ( client) )
72+ . service ( new_router ( client) )
4373 } ) ;
4474
4575 eloop. run_buffered ( stdin, stdout) . await . unwrap ( ) ;
0 commit comments