diff options
Diffstat (limited to 'crates/server/src/main_loop')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 6 | ||||
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 62 |
2 files changed, 43 insertions, 25 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index 898195f6d..323d4e95e 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -141,14 +141,18 @@ pub fn handle_workspace_symbol( | |||
141 | token: JobToken, | 141 | token: JobToken, |
142 | ) -> Result<Option<Vec<SymbolInformation>>> { | 142 | ) -> Result<Option<Vec<SymbolInformation>>> { |
143 | let all_symbols = params.query.contains("#"); | 143 | let all_symbols = params.query.contains("#"); |
144 | let libs = params.query.contains("*"); | ||
144 | let query = { | 145 | let query = { |
145 | let query: String = params.query.chars() | 146 | let query: String = params.query.chars() |
146 | .filter(|&c| c != '#') | 147 | .filter(|&c| c != '#' && c != '*') |
147 | .collect(); | 148 | .collect(); |
148 | let mut q = Query::new(query); | 149 | let mut q = Query::new(query); |
149 | if !all_symbols { | 150 | if !all_symbols { |
150 | q.only_types(); | 151 | q.only_types(); |
151 | } | 152 | } |
153 | if libs { | ||
154 | q.libs(); | ||
155 | } | ||
152 | q.limit(128); | 156 | q.limit(128); |
153 | q | 157 | q |
154 | }; | 158 | }; |
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index bb1d638e0..ce61265a2 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -38,9 +38,8 @@ pub fn main_loop( | |||
38 | ) -> Result<()> { | 38 | ) -> Result<()> { |
39 | let pool = ThreadPool::new(4); | 39 | let pool = ThreadPool::new(4); |
40 | let (task_sender, task_receiver) = bounded::<Task>(16); | 40 | let (task_sender, task_receiver) = bounded::<Task>(16); |
41 | let (fs_events_receiver, watcher) = vfs::watch(vec![root.clone()]); | 41 | let (fs_sender, fs_receiver, fs_watcher) = vfs::roots_loader(); |
42 | let (ws_root_sender, ws_receiver, ws_watcher) = workspace_loader(); | 42 | let (ws_sender, ws_receiver, ws_watcher) = workspace_loader(); |
43 | ws_root_sender.send(root); | ||
44 | 43 | ||
45 | info!("server initialized, serving requests"); | 44 | info!("server initialized, serving requests"); |
46 | let mut state = ServerWorldState::new(); | 45 | let mut state = ServerWorldState::new(); |
@@ -48,13 +47,15 @@ pub fn main_loop( | |||
48 | let mut pending_requests = HashMap::new(); | 47 | let mut pending_requests = HashMap::new(); |
49 | let mut subs = Subscriptions::new(); | 48 | let mut subs = Subscriptions::new(); |
50 | let main_res = main_loop_inner( | 49 | let main_res = main_loop_inner( |
50 | root, | ||
51 | &pool, | 51 | &pool, |
52 | msg_receriver, | ||
53 | msg_sender, | 52 | msg_sender, |
54 | task_receiver.clone(), | 53 | msg_receriver, |
55 | task_sender, | 54 | task_sender, |
56 | fs_events_receiver, | 55 | task_receiver.clone(), |
57 | ws_root_sender, | 56 | fs_sender, |
57 | fs_receiver, | ||
58 | ws_sender, | ||
58 | ws_receiver, | 59 | ws_receiver, |
59 | &mut state, | 60 | &mut state, |
60 | &mut pending_requests, | 61 | &mut pending_requests, |
@@ -68,38 +69,40 @@ pub fn main_loop( | |||
68 | pool.join(); | 69 | pool.join(); |
69 | info!("...threadpool has finished"); | 70 | info!("...threadpool has finished"); |
70 | 71 | ||
71 | let vfs_res = watcher.stop(); | 72 | let fs_res = fs_watcher.stop(); |
72 | let ws_res = ws_watcher.stop(); | 73 | let ws_res = ws_watcher.stop(); |
73 | 74 | ||
74 | main_res?; | 75 | main_res?; |
75 | vfs_res?; | 76 | fs_res?; |
76 | ws_res?; | 77 | ws_res?; |
77 | 78 | ||
78 | Ok(()) | 79 | Ok(()) |
79 | } | 80 | } |
80 | 81 | ||
81 | fn main_loop_inner( | 82 | fn main_loop_inner( |
83 | ws_root: PathBuf, | ||
82 | pool: &ThreadPool, | 84 | pool: &ThreadPool, |
83 | msg_receiver: &mut Receiver<RawMessage>, | ||
84 | msg_sender: &mut Sender<RawMessage>, | 85 | msg_sender: &mut Sender<RawMessage>, |
85 | task_receiver: Receiver<Task>, | 86 | msg_receiver: &mut Receiver<RawMessage>, |
86 | task_sender: Sender<Task>, | 87 | task_sender: Sender<Task>, |
87 | fs_receiver: Receiver<Vec<FileEvent>>, | 88 | task_receiver: Receiver<Task>, |
88 | _ws_roots_sender: Sender<PathBuf>, | 89 | fs_sender: Sender<PathBuf>, |
90 | fs_receiver: Receiver<(PathBuf, Vec<FileEvent>)>, | ||
91 | ws_sender: Sender<PathBuf>, | ||
89 | ws_receiver: Receiver<Result<CargoWorkspace>>, | 92 | ws_receiver: Receiver<Result<CargoWorkspace>>, |
90 | state: &mut ServerWorldState, | 93 | state: &mut ServerWorldState, |
91 | pending_requests: &mut HashMap<u64, JobHandle>, | 94 | pending_requests: &mut HashMap<u64, JobHandle>, |
92 | subs: &mut Subscriptions, | 95 | subs: &mut Subscriptions, |
93 | ) -> Result<()> { | 96 | ) -> Result<()> { |
94 | let mut fs_receiver = Some(fs_receiver); | 97 | ws_sender.send(ws_root.clone()); |
98 | fs_sender.send(ws_root.clone()); | ||
95 | loop { | 99 | loop { |
96 | #[derive(Debug)] | 100 | #[derive(Debug)] |
97 | enum Event { | 101 | enum Event { |
98 | Msg(RawMessage), | 102 | Msg(RawMessage), |
99 | Task(Task), | 103 | Task(Task), |
100 | Fs(Vec<FileEvent>), | 104 | Fs(PathBuf, Vec<FileEvent>), |
101 | Ws(Result<CargoWorkspace>), | 105 | Ws(Result<CargoWorkspace>), |
102 | FsWatcherDead, | ||
103 | } | 106 | } |
104 | trace!("selecting"); | 107 | trace!("selecting"); |
105 | let event = select! { | 108 | let event = select! { |
@@ -109,8 +112,8 @@ fn main_loop_inner( | |||
109 | }, | 112 | }, |
110 | recv(task_receiver, task) => Event::Task(task.unwrap()), | 113 | recv(task_receiver, task) => Event::Task(task.unwrap()), |
111 | recv(fs_receiver, events) => match events { | 114 | recv(fs_receiver, events) => match events { |
112 | Some(events) => Event::Fs(events), | 115 | None => bail!("roots watcher died"), |
113 | None => Event::FsWatcherDead, | 116 | Some((pb, events)) => Event::Fs(pb, events), |
114 | } | 117 | } |
115 | recv(ws_receiver, ws) => match ws { | 118 | recv(ws_receiver, ws) => match ws { |
116 | None => bail!("workspace watcher died"), | 119 | None => bail!("workspace watcher died"), |
@@ -120,19 +123,30 @@ fn main_loop_inner( | |||
120 | trace!("selected {:?}", event); | 123 | trace!("selected {:?}", event); |
121 | let mut state_changed = false; | 124 | let mut state_changed = false; |
122 | match event { | 125 | match event { |
123 | Event::FsWatcherDead => fs_receiver = None, | ||
124 | Event::Task(task) => on_task(task, msg_sender, pending_requests), | 126 | Event::Task(task) => on_task(task, msg_sender, pending_requests), |
125 | Event::Fs(events) => { | 127 | Event::Fs(root, events) => { |
126 | trace!("fs change, {} events", events.len()); | 128 | info!("fs change, {}, {} events", root.display(), events.len()); |
127 | state.apply_fs_changes(events); | 129 | if root == ws_root { |
130 | state.apply_fs_changes(events); | ||
131 | } else { | ||
132 | state.add_library(events); | ||
133 | } | ||
128 | state_changed = true; | 134 | state_changed = true; |
129 | } | 135 | } |
130 | Event::Ws(ws) => { | 136 | Event::Ws(ws) => { |
131 | match ws { | 137 | match ws { |
132 | Ok(ws) => { | 138 | Ok(ws) => { |
133 | let not = RawNotification::new::<req::DidReloadWorkspace>(&vec![ws.clone()]); | 139 | let workspaces = vec![ws]; |
140 | let not = RawNotification::new::<req::DidReloadWorkspace>(&workspaces); | ||
134 | msg_sender.send(RawMessage::Notification(not)); | 141 | msg_sender.send(RawMessage::Notification(not)); |
135 | state.set_workspaces(vec![ws]); | 142 | for ws in workspaces.iter() { |
143 | for pkg in ws.packages().filter(|pkg| !pkg.is_member(ws)) { | ||
144 | debug!("sending root, {}", pkg.root(ws).to_path_buf().display()); | ||
145 | // deadlocky :-( | ||
146 | fs_sender.send(pkg.root(ws).to_path_buf()); | ||
147 | } | ||
148 | } | ||
149 | state.set_workspaces(workspaces); | ||
136 | state_changed = true; | 150 | state_changed = true; |
137 | } | 151 | } |
138 | Err(e) => warn!("loading workspace failed: {}", e), | 152 | Err(e) => warn!("loading workspace failed: {}", e), |