@@ -88,7 +88,7 @@ pub struct State {
8888 #[ serde( skip_serializing) ]
8989 pub writers : HashMap < String , Box < SyncWrite > > ,
9090 pub capabilities : HashMap < String , Value > ,
91- pub method_registrations : MethodRegistrations ,
91+ pub registrations : Vec < Registration > ,
9292 pub roots : HashMap < String , String > ,
9393 pub text_documents : HashMap < String , TextDocumentItem > ,
9494 pub text_documents_metadata : HashMap < String , TextDocumentItemMetadata > ,
@@ -102,7 +102,7 @@ pub struct State {
102102 #[ serde( skip_serializing) ]
103103 pub watcher_rx : Receiver < notify:: DebouncedEvent > ,
104104 #[ serde( skip_serializing) ]
105- pub watcher : Watcher ,
105+ pub watcher : Option < notify :: RecommendedWatcher > ,
106106
107107 pub is_nvim : bool ,
108108 pub last_cursor_line : u64 ,
@@ -130,21 +130,20 @@ pub struct State {
130130
131131impl State {
132132 pub fn new ( ) -> Result < State > {
133- // TODO: move this into LanguageClientStart.
133+ let logger = logger:: init ( ) ?;
134+
135+ let ( tx, rx) = channel ( ) ;
136+
134137 let ( watcher_tx, watcher_rx) = channel ( ) ;
135138 // TODO: duration configurable.
136139 let watcher = match notify:: watcher ( watcher_tx, std:: time:: Duration :: from_secs ( 2 ) ) {
137- Ok ( watcher) => Watcher :: Some ( watcher) ,
140+ Ok ( watcher) => Some ( watcher) ,
138141 Err ( err) => {
139- error ! ( "{:?}" , err) ;
140- Watcher :: None
142+ warn ! ( "{:?}" , err) ;
143+ None
141144 }
142145 } ;
143146
144- let ( tx, rx) = channel ( ) ;
145-
146- let logger = logger:: init ( ) ?;
147-
148147 Ok ( State {
149148 id : 0 ,
150149 tx,
@@ -155,7 +154,7 @@ impl State {
155154 child_ids : HashMap :: new ( ) ,
156155 writers : HashMap :: new ( ) ,
157156 capabilities : HashMap :: new ( ) ,
158- method_registrations : MethodRegistrations :: default ( ) ,
157+ registrations : vec ! [ ] ,
159158 roots : HashMap :: new ( ) ,
160159 text_documents : HashMap :: new ( ) ,
161160 text_documents_metadata : HashMap :: new ( ) ,
@@ -862,74 +861,3 @@ impl<T: Deref> OptionDeref<T> for Option<T> {
862861 self . as_ref ( ) . map ( Deref :: deref)
863862 }
864863}
865-
866- #[ derive( Debug , Serialize , Default ) ]
867- pub struct MethodRegistrations {
868- // (languageId, Id) => Options.
869- pub didChangeWatchedFiles :
870- HashMap < ( String , String ) , Vec < DidChangeWatchedFilesRegistrationOptions > > ,
871- }
872-
873- impl MethodRegistrations {
874- pub fn register ( & mut self , languageId : & str , r : & Registration ) -> Result < ( ) > {
875- match r. method . as_str ( ) {
876- lsp:: notification:: DidChangeWatchedFiles :: METHOD => {
877- let opt: DidChangeWatchedFilesRegistrationOptions =
878- serde_json:: from_value ( r. register_options . clone ( ) . unwrap_or_default ( ) ) ?;
879- self . didChangeWatchedFiles
880- . entry ( ( languageId. into ( ) , r. id . clone ( ) ) )
881- . or_insert_with ( || vec ! [ ] )
882- . push ( opt) ;
883- }
884- _ => {
885- warn ! ( "Unknown registration: {:?}" , r) ;
886- }
887- }
888-
889- Ok ( ( ) )
890- }
891-
892- pub fn unregister ( & mut self , languageId : & str , r : & Unregistration ) -> Result < ( ) > {
893- match r. method . as_str ( ) {
894- lsp:: notification:: DidChangeWatchedFiles :: METHOD => {
895- self . didChangeWatchedFiles
896- . remove ( & ( languageId. into ( ) , r. id . clone ( ) ) ) ;
897- }
898- _ => {
899- warn ! ( "Unknown unregistration: {:?}" , r) ;
900- }
901- }
902- Ok ( ( ) )
903- }
904-
905- pub fn get_didChangeWatchedFiles_languageIds ( & self , path : & str ) -> Result < Vec < String > > {
906- let mut lang_ids = vec ! [ ] ;
907- // TODO: optimize the structure.
908- for ( & ( ref lang_id, _) , opts) in & self . didChangeWatchedFiles {
909- for opt in opts {
910- for watch in & opt. watchers {
911- // TODO: match event.
912- if glob:: Pattern :: new ( watch. glob_pattern . as_str ( ) ) ?. matches ( path) {
913- lang_ids. push ( lang_id. clone ( ) ) ;
914- }
915- }
916- }
917- }
918- Ok ( lang_ids)
919- }
920- }
921-
922- pub enum Watcher {
923- None ,
924- Some ( notify:: RecommendedWatcher ) ,
925- }
926-
927- impl std:: fmt:: Debug for Watcher {
928- fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
929- let msg = match * self {
930- Watcher :: None => "None" ,
931- Watcher :: Some ( _) => "Some Watcher" ,
932- } ;
933- write ! ( f, "{}" , msg)
934- }
935- }
0 commit comments