aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop.rs')
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs56
1 files changed, 48 insertions, 8 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index afe0fec89..565ec92af 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -2,6 +2,7 @@ mod handlers;
2mod subscriptions; 2mod subscriptions;
3 3
4use std::{ 4use std::{
5 fmt,
5 path::PathBuf, 6 path::PathBuf,
6 sync::Arc, 7 sync::Arc,
7}; 8};
@@ -109,6 +110,50 @@ pub fn main_loop(
109 Ok(()) 110 Ok(())
110} 111}
111 112
113enum Event {
114 Msg(RawMessage),
115 Task(Task),
116 Vfs(VfsTask),
117 Lib(LibraryData),
118}
119
120impl fmt::Debug for Event {
121 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
122 let debug_verbose_not = |not: &RawNotification, f: &mut fmt::Formatter| {
123 f.debug_struct("RawNotification")
124 .field("method", &not.method)
125 .finish()
126 };
127
128 match self {
129 Event::Msg(RawMessage::Notification(not)) => {
130 if not.is::<req::DidOpenTextDocument>() || not.is::<req::DidChangeTextDocument>() {
131 return debug_verbose_not(not, f);
132 }
133 }
134 Event::Task(Task::Notify(not)) => {
135 if not.is::<req::PublishDecorations>() || not.is::<req::PublishDiagnostics>() {
136 return debug_verbose_not(not, f);
137 }
138 }
139 Event::Task(Task::Respond(resp)) => {
140 return f
141 .debug_struct("RawResponse")
142 .field("id", &resp.id)
143 .field("error", &resp.error)
144 .finish();
145 }
146 _ => (),
147 }
148 match self {
149 Event::Msg(it) => fmt::Debug::fmt(it, f),
150 Event::Task(it) => fmt::Debug::fmt(it, f),
151 Event::Vfs(it) => fmt::Debug::fmt(it, f),
152 Event::Lib(it) => fmt::Debug::fmt(it, f),
153 }
154 }
155}
156
112fn main_loop_inner( 157fn main_loop_inner(
113 internal_mode: bool, 158 internal_mode: bool,
114 publish_decorations: bool, 159 publish_decorations: bool,
@@ -123,13 +168,6 @@ fn main_loop_inner(
123) -> Result<()> { 168) -> Result<()> {
124 let (libdata_sender, libdata_receiver) = unbounded(); 169 let (libdata_sender, libdata_receiver) = unbounded();
125 loop { 170 loop {
126 #[derive(Debug)]
127 enum Event {
128 Msg(RawMessage),
129 Task(Task),
130 Vfs(VfsTask),
131 Lib(LibraryData),
132 }
133 log::trace!("selecting"); 171 log::trace!("selecting");
134 let event = select! { 172 let event = select! {
135 recv(msg_receiver, msg) => match msg { 173 recv(msg_receiver, msg) => match msg {
@@ -143,7 +181,8 @@ fn main_loop_inner(
143 } 181 }
144 recv(libdata_receiver, data) => Event::Lib(data.unwrap()) 182 recv(libdata_receiver, data) => Event::Lib(data.unwrap())
145 }; 183 };
146 log::info!("{:?}", event); 184 log::info!("loop_turn = {:?}", event);
185 let start = std::time::Instant::now();
147 let mut state_changed = false; 186 let mut state_changed = false;
148 match event { 187 match event {
149 Event::Task(task) => on_task(task, msg_sender, pending_requests), 188 Event::Task(task) => on_task(task, msg_sender, pending_requests),
@@ -206,6 +245,7 @@ fn main_loop_inner(
206 subs.subscriptions(), 245 subs.subscriptions(),
207 ) 246 )
208 } 247 }
248 log::info!("loop_turn = {:?}", start.elapsed());
209 } 249 }
210} 250}
211 251