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 vfs;
23+
24+ pub ( crate ) type NotifyResult = ControlFlow < async_lsp:: Result < ( ) > > ;
25+
26+ fn new_router ( client : ClientSocket ) -> Router < GlobalState > {
27+ let this = GlobalState :: new ( client) ;
28+ let mut router = Router :: new ( this) ;
1529
16- mod server;
30+ // Lifecycle
31+ router
32+ . request :: < req:: Initialize , _ > ( GlobalState :: on_initialize)
33+ . notification :: < notif:: Initialized > ( GlobalState :: on_initialized)
34+ . request :: < req:: Shutdown , _ > ( |_, _| std:: future:: ready ( Ok ( ( ) ) ) )
35+ . notification :: < notif:: Exit > ( |_, _| ControlFlow :: Break ( Ok ( ( ) ) ) ) ;
36+
37+ // Notifications
38+ router
39+ . notification :: < notif:: DidOpenTextDocument > ( handlers:: did_open_text_document)
40+ . notification :: < notif:: DidCloseTextDocument > ( handlers:: did_close_text_document)
41+ . notification :: < notif:: DidChangeTextDocument > ( handlers:: did_change_text_document) ;
42+
43+ router
44+ }
1745
1846/// Start the LSP server over stdin/stdout.
1947///
@@ -35,11 +63,12 @@ pub async fn run_server_stdio() -> solar_interface::Result<()> {
3563
3664 let ( eloop, _) = async_lsp:: MainLoop :: new_server ( |client| {
3765 ServiceBuilder :: new ( )
66+ . layer ( TracingLayer :: default ( ) )
3867 . layer ( LifecycleLayer :: default ( ) )
3968 // TODO: infer concurrency
4069 . layer ( ConcurrencyLayer :: new ( 2 . try_into ( ) . unwrap ( ) ) )
4170 . layer ( ClientProcessMonitorLayer :: new ( client. clone ( ) ) )
42- . service ( Server :: new_router ( client) )
71+ . service ( new_router ( client) )
4372 } ) ;
4473
4574 eloop. run_buffered ( stdin, stdout) . await . unwrap ( ) ;
0 commit comments