aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-01 08:46:15 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-01 08:46:15 +0100
commit35e79bf4225949d3666551246bf85f8198707e3c (patch)
tree7373b692a08a9991d04d2ffd900c18ed2ea3db73 /crates/ra_lsp_server/src
parent5023860a55328db5ef024225263ed71f46a19350 (diff)
parent4dd7faed3400c8ed204c6879258707ce6f7a90d4 (diff)
Merge #1358
1358: apply profile filter to top-level entries only r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/cargo_target_spec.rs6
-rw-r--r--crates/ra_lsp_server/src/conv.rs50
-rw-r--r--crates/ra_lsp_server/src/lib.rs2
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs26
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs66
-rw-r--r--crates/ra_lsp_server/src/world.rs (renamed from crates/ra_lsp_server/src/server_world.rs)22
6 files changed, 88 insertions, 84 deletions
diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs
index cdf2ec10b..742361155 100644
--- a/crates/ra_lsp_server/src/cargo_target_spec.rs
+++ b/crates/ra_lsp_server/src/cargo_target_spec.rs
@@ -1,13 +1,13 @@
1use crate::{ 1use crate::{
2 project_model::{self, TargetKind}, 2 project_model::{self, TargetKind},
3 server_world::ServerWorld, 3 world::WorldSnapshot,
4 Result 4 Result
5}; 5};
6 6
7use ra_ide_api::{FileId, RunnableKind}; 7use ra_ide_api::{FileId, RunnableKind};
8 8
9pub(crate) fn runnable_args( 9pub(crate) fn runnable_args(
10 world: &ServerWorld, 10 world: &WorldSnapshot,
11 file_id: FileId, 11 file_id: FileId,
12 kind: &RunnableKind, 12 kind: &RunnableKind,
13) -> Result<Vec<String>> { 13) -> Result<Vec<String>> {
@@ -58,7 +58,7 @@ pub struct CargoTargetSpec {
58} 58}
59 59
60impl CargoTargetSpec { 60impl CargoTargetSpec {
61 pub fn for_file(world: &ServerWorld, file_id: FileId) -> Result<Option<CargoTargetSpec>> { 61 pub fn for_file(world: &WorldSnapshot, file_id: FileId) -> Result<Option<CargoTargetSpec>> {
62 let &crate_id = match world.analysis().crate_for(file_id)?.first() { 62 let &crate_id = match world.analysis().crate_for(file_id)?.first() {
63 Some(crate_id) => crate_id, 63 Some(crate_id) => crate_id,
64 None => return Ok(None), 64 None => return Ok(None),
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 1b349d02a..88d29b256 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -12,7 +12,7 @@ use ra_ide_api::{
12use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 12use ra_syntax::{SyntaxKind, TextRange, TextUnit};
13use ra_text_edit::{AtomTextEdit, TextEdit}; 13use ra_text_edit::{AtomTextEdit, TextEdit};
14 14
15use crate::{req, server_world::ServerWorld, Result}; 15use crate::{req, world::WorldSnapshot, Result};
16 16
17pub trait Conv { 17pub trait Conv {
18 type Output; 18 type Output;
@@ -228,49 +228,49 @@ impl<T: ConvWith> ConvWith for Option<T> {
228} 228}
229 229
230impl<'a> TryConvWith for &'a Url { 230impl<'a> TryConvWith for &'a Url {
231 type Ctx = ServerWorld; 231 type Ctx = WorldSnapshot;
232 type Output = FileId; 232 type Output = FileId;
233 fn try_conv_with(self, world: &ServerWorld) -> Result<FileId> { 233 fn try_conv_with(self, world: &WorldSnapshot) -> Result<FileId> {
234 world.uri_to_file_id(self) 234 world.uri_to_file_id(self)
235 } 235 }
236} 236}
237 237
238impl TryConvWith for FileId { 238impl TryConvWith for FileId {
239 type Ctx = ServerWorld; 239 type Ctx = WorldSnapshot;
240 type Output = Url; 240 type Output = Url;
241 fn try_conv_with(self, world: &ServerWorld) -> Result<Url> { 241 fn try_conv_with(self, world: &WorldSnapshot) -> Result<Url> {
242 world.file_id_to_uri(self) 242 world.file_id_to_uri(self)
243 } 243 }
244} 244}
245 245
246impl<'a> TryConvWith for &'a TextDocumentItem { 246impl<'a> TryConvWith for &'a TextDocumentItem {
247 type Ctx = ServerWorld; 247 type Ctx = WorldSnapshot;
248 type Output = FileId; 248 type Output = FileId;
249 fn try_conv_with(self, world: &ServerWorld) -> Result<FileId> { 249 fn try_conv_with(self, world: &WorldSnapshot) -> Result<FileId> {
250 self.uri.try_conv_with(world) 250 self.uri.try_conv_with(world)
251 } 251 }
252} 252}
253 253
254impl<'a> TryConvWith for &'a VersionedTextDocumentIdentifier { 254impl<'a> TryConvWith for &'a VersionedTextDocumentIdentifier {
255 type Ctx = ServerWorld; 255 type Ctx = WorldSnapshot;
256 type Output = FileId; 256 type Output = FileId;
257 fn try_conv_with(self, world: &ServerWorld) -> Result<FileId> { 257 fn try_conv_with(self, world: &WorldSnapshot) -> Result<FileId> {
258 self.uri.try_conv_with(world) 258 self.uri.try_conv_with(world)
259 } 259 }
260} 260}
261 261
262impl<'a> TryConvWith for &'a TextDocumentIdentifier { 262impl<'a> TryConvWith for &'a TextDocumentIdentifier {
263 type Ctx = ServerWorld; 263 type Ctx = WorldSnapshot;
264 type Output = FileId; 264 type Output = FileId;
265 fn try_conv_with(self, world: &ServerWorld) -> Result<FileId> { 265 fn try_conv_with(self, world: &WorldSnapshot) -> Result<FileId> {
266 world.uri_to_file_id(&self.uri) 266 world.uri_to_file_id(&self.uri)
267 } 267 }
268} 268}
269 269
270impl<'a> TryConvWith for &'a TextDocumentPositionParams { 270impl<'a> TryConvWith for &'a TextDocumentPositionParams {
271 type Ctx = ServerWorld; 271 type Ctx = WorldSnapshot;
272 type Output = FilePosition; 272 type Output = FilePosition;
273 fn try_conv_with(self, world: &ServerWorld) -> Result<FilePosition> { 273 fn try_conv_with(self, world: &WorldSnapshot) -> Result<FilePosition> {
274 let file_id = self.text_document.try_conv_with(world)?; 274 let file_id = self.text_document.try_conv_with(world)?;
275 let line_index = world.analysis().file_line_index(file_id); 275 let line_index = world.analysis().file_line_index(file_id);
276 let offset = self.position.conv_with(&line_index); 276 let offset = self.position.conv_with(&line_index);
@@ -279,9 +279,9 @@ impl<'a> TryConvWith for &'a TextDocumentPositionParams {
279} 279}
280 280
281impl<'a> TryConvWith for (&'a TextDocumentIdentifier, Range) { 281impl<'a> TryConvWith for (&'a TextDocumentIdentifier, Range) {
282 type Ctx = ServerWorld; 282 type Ctx = WorldSnapshot;
283 type Output = FileRange; 283 type Output = FileRange;
284 fn try_conv_with(self, world: &ServerWorld) -> Result<FileRange> { 284 fn try_conv_with(self, world: &WorldSnapshot) -> Result<FileRange> {
285 let file_id = self.0.try_conv_with(world)?; 285 let file_id = self.0.try_conv_with(world)?;
286 let line_index = world.analysis().file_line_index(file_id); 286 let line_index = world.analysis().file_line_index(file_id);
287 let range = self.1.conv_with(&line_index); 287 let range = self.1.conv_with(&line_index);
@@ -302,9 +302,9 @@ impl<T: TryConvWith> TryConvWith for Vec<T> {
302} 302}
303 303
304impl TryConvWith for SourceChange { 304impl TryConvWith for SourceChange {
305 type Ctx = ServerWorld; 305 type Ctx = WorldSnapshot;
306 type Output = req::SourceChange; 306 type Output = req::SourceChange;
307 fn try_conv_with(self, world: &ServerWorld) -> Result<req::SourceChange> { 307 fn try_conv_with(self, world: &WorldSnapshot) -> Result<req::SourceChange> {
308 let cursor_position = match self.cursor_position { 308 let cursor_position = match self.cursor_position {
309 None => None, 309 None => None,
310 Some(pos) => { 310 Some(pos) => {
@@ -342,9 +342,9 @@ impl TryConvWith for SourceChange {
342} 342}
343 343
344impl TryConvWith for SourceFileEdit { 344impl TryConvWith for SourceFileEdit {
345 type Ctx = ServerWorld; 345 type Ctx = WorldSnapshot;
346 type Output = TextDocumentEdit; 346 type Output = TextDocumentEdit;
347 fn try_conv_with(self, world: &ServerWorld) -> Result<TextDocumentEdit> { 347 fn try_conv_with(self, world: &WorldSnapshot) -> Result<TextDocumentEdit> {
348 let text_document = VersionedTextDocumentIdentifier { 348 let text_document = VersionedTextDocumentIdentifier {
349 uri: self.file_id.try_conv_with(world)?, 349 uri: self.file_id.try_conv_with(world)?,
350 version: None, 350 version: None,
@@ -356,9 +356,9 @@ impl TryConvWith for SourceFileEdit {
356} 356}
357 357
358impl TryConvWith for FileSystemEdit { 358impl TryConvWith for FileSystemEdit {
359 type Ctx = ServerWorld; 359 type Ctx = WorldSnapshot;
360 type Output = ResourceOp; 360 type Output = ResourceOp;
361 fn try_conv_with(self, world: &ServerWorld) -> Result<ResourceOp> { 361 fn try_conv_with(self, world: &WorldSnapshot) -> Result<ResourceOp> {
362 let res = match self { 362 let res = match self {
363 FileSystemEdit::CreateFile { source_root, path } => { 363 FileSystemEdit::CreateFile { source_root, path } => {
364 let uri = world.path_to_uri(source_root, &path)?; 364 let uri = world.path_to_uri(source_root, &path)?;
@@ -375,9 +375,9 @@ impl TryConvWith for FileSystemEdit {
375} 375}
376 376
377impl TryConvWith for &NavigationTarget { 377impl TryConvWith for &NavigationTarget {
378 type Ctx = ServerWorld; 378 type Ctx = WorldSnapshot;
379 type Output = Location; 379 type Output = Location;
380 fn try_conv_with(self, world: &ServerWorld) -> Result<Location> { 380 fn try_conv_with(self, world: &WorldSnapshot) -> Result<Location> {
381 let line_index = world.analysis().file_line_index(self.file_id()); 381 let line_index = world.analysis().file_line_index(self.file_id());
382 let range = self.range(); 382 let range = self.range();
383 to_location(self.file_id(), range, &world, &line_index) 383 to_location(self.file_id(), range, &world, &line_index)
@@ -386,7 +386,7 @@ impl TryConvWith for &NavigationTarget {
386 386
387pub fn to_location_link( 387pub fn to_location_link(
388 target: &RangeInfo<NavigationTarget>, 388 target: &RangeInfo<NavigationTarget>,
389 world: &ServerWorld, 389 world: &WorldSnapshot,
390 // line index for original range file 390 // line index for original range file
391 line_index: &LineIndex, 391 line_index: &LineIndex,
392) -> Result<LocationLink> { 392) -> Result<LocationLink> {
@@ -410,7 +410,7 @@ pub fn to_location_link(
410pub fn to_location( 410pub fn to_location(
411 file_id: FileId, 411 file_id: FileId,
412 range: TextRange, 412 range: TextRange,
413 world: &ServerWorld, 413 world: &WorldSnapshot,
414 line_index: &LineIndex, 414 line_index: &LineIndex,
415) -> Result<Location> { 415) -> Result<Location> {
416 let url = file_id.try_conv_with(world)?; 416 let url = file_id.try_conv_with(world)?;
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs
index 113883bdd..aabde420b 100644
--- a/crates/ra_lsp_server/src/lib.rs
+++ b/crates/ra_lsp_server/src/lib.rs
@@ -7,7 +7,7 @@ mod project_model;
7mod vfs_filter; 7mod vfs_filter;
8pub mod req; 8pub mod req;
9pub mod init; 9pub mod init;
10mod server_world; 10mod world;
11 11
12pub type Result<T> = ::std::result::Result<T, ::failure::Error>; 12pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
13pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions}; 13pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions};
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 452499497..6080a3a4e 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -24,7 +24,7 @@ use crate::{
24 }, 24 },
25 project_model::workspace_loader, 25 project_model::workspace_loader,
26 req, 26 req,
27 server_world::{ServerWorld, ServerWorldState}, 27 world::{WorldSnapshot, WorldState},
28 Result, 28 Result,
29 InitializationOptions, 29 InitializationOptions,
30}; 30};
@@ -73,12 +73,11 @@ pub fn main_loop(
73 loaded_workspaces 73 loaded_workspaces
74 }; 74 };
75 75
76 let mut state = ServerWorldState::new(ws_roots, workspaces); 76 let mut state = WorldState::new(ws_roots, workspaces);
77 77
78 let pool = ThreadPool::new(THREADPOOL_SIZE); 78 let pool = ThreadPool::new(THREADPOOL_SIZE);
79 let (task_sender, task_receiver) = unbounded::<Task>(); 79 let (task_sender, task_receiver) = unbounded::<Task>();
80 let mut pending_requests = PendingRequests::default(); 80 let mut pending_requests = PendingRequests::default();
81 let mut subs = Subscriptions::default();
82 81
83 log::info!("server initialized, serving requests"); 82 log::info!("server initialized, serving requests");
84 let main_res = main_loop_inner( 83 let main_res = main_loop_inner(
@@ -90,7 +89,6 @@ pub fn main_loop(
90 task_receiver.clone(), 89 task_receiver.clone(),
91 &mut state, 90 &mut state,
92 &mut pending_requests, 91 &mut pending_requests,
93 &mut subs,
94 ); 92 );
95 93
96 log::info!("waiting for tasks to finish..."); 94 log::info!("waiting for tasks to finish...");
@@ -163,10 +161,10 @@ fn main_loop_inner(
163 msg_receiver: &Receiver<RawMessage>, 161 msg_receiver: &Receiver<RawMessage>,
164 task_sender: Sender<Task>, 162 task_sender: Sender<Task>,
165 task_receiver: Receiver<Task>, 163 task_receiver: Receiver<Task>,
166 state: &mut ServerWorldState, 164 state: &mut WorldState,
167 pending_requests: &mut PendingRequests, 165 pending_requests: &mut PendingRequests,
168 subs: &mut Subscriptions,
169) -> Result<()> { 166) -> Result<()> {
167 let mut subs = Subscriptions::default();
170 // We try not to index more than MAX_IN_FLIGHT_LIBS libraries at the same 168 // We try not to index more than MAX_IN_FLIGHT_LIBS libraries at the same
171 // time to always have a thread ready to react to input. 169 // time to always have a thread ready to react to input.
172 let mut in_flight_libraries = 0; 170 let mut in_flight_libraries = 0;
@@ -230,7 +228,7 @@ fn main_loop_inner(
230 )? 228 )?
231 } 229 }
232 RawMessage::Notification(not) => { 230 RawMessage::Notification(not) => {
233 on_notification(msg_sender, state, pending_requests, subs, not)?; 231 on_notification(msg_sender, state, pending_requests, &mut subs, not)?;
234 state_changed = true; 232 state_changed = true;
235 } 233 }
236 RawMessage::Response(resp) => log::error!("unexpected response: {:?}", resp), 234 RawMessage::Response(resp) => log::error!("unexpected response: {:?}", resp),
@@ -280,7 +278,7 @@ fn on_task(
280 task: Task, 278 task: Task,
281 msg_sender: &Sender<RawMessage>, 279 msg_sender: &Sender<RawMessage>,
282 pending_requests: &mut PendingRequests, 280 pending_requests: &mut PendingRequests,
283 state: &mut ServerWorldState, 281 state: &mut WorldState,
284) { 282) {
285 match task { 283 match task {
286 Task::Respond(response) => { 284 Task::Respond(response) => {
@@ -297,7 +295,7 @@ fn on_task(
297} 295}
298 296
299fn on_request( 297fn on_request(
300 world: &mut ServerWorldState, 298 world: &mut WorldState,
301 pending_requests: &mut PendingRequests, 299 pending_requests: &mut PendingRequests,
302 pool: &ThreadPool, 300 pool: &ThreadPool,
303 sender: &Sender<Task>, 301 sender: &Sender<Task>,
@@ -354,7 +352,7 @@ fn on_request(
354 352
355fn on_notification( 353fn on_notification(
356 msg_sender: &Sender<RawMessage>, 354 msg_sender: &Sender<RawMessage>,
357 state: &mut ServerWorldState, 355 state: &mut WorldState,
358 pending_requests: &mut PendingRequests, 356 pending_requests: &mut PendingRequests,
359 subs: &mut Subscriptions, 357 subs: &mut Subscriptions,
360 not: RawNotification, 358 not: RawNotification,
@@ -424,7 +422,7 @@ fn on_notification(
424struct PoolDispatcher<'a> { 422struct PoolDispatcher<'a> {
425 req: Option<RawRequest>, 423 req: Option<RawRequest>,
426 pool: &'a ThreadPool, 424 pool: &'a ThreadPool,
427 world: &'a mut ServerWorldState, 425 world: &'a mut WorldState,
428 pending_requests: &'a mut PendingRequests, 426 pending_requests: &'a mut PendingRequests,
429 msg_sender: &'a Sender<RawMessage>, 427 msg_sender: &'a Sender<RawMessage>,
430 sender: &'a Sender<Task>, 428 sender: &'a Sender<Task>,
@@ -435,7 +433,7 @@ impl<'a> PoolDispatcher<'a> {
435 /// Dispatches the request onto the current thread 433 /// Dispatches the request onto the current thread
436 fn on_sync<R>( 434 fn on_sync<R>(
437 &mut self, 435 &mut self,
438 f: fn(&mut ServerWorldState, R::Params) -> Result<R::Result>, 436 f: fn(&mut WorldState, R::Params) -> Result<R::Result>,
439 ) -> Result<&mut Self> 437 ) -> Result<&mut Self>
440 where 438 where
441 R: req::Request + 'static, 439 R: req::Request + 'static,
@@ -455,7 +453,7 @@ impl<'a> PoolDispatcher<'a> {
455 } 453 }
456 454
457 /// Dispatches the request onto thread pool 455 /// Dispatches the request onto thread pool
458 fn on<R>(&mut self, f: fn(ServerWorld, R::Params) -> Result<R::Result>) -> Result<&mut Self> 456 fn on<R>(&mut self, f: fn(WorldSnapshot, R::Params) -> Result<R::Result>) -> Result<&mut Self>
459 where 457 where
460 R: req::Request + 'static, 458 R: req::Request + 'static,
461 R::Params: DeserializeOwned + Send + 'static, 459 R::Params: DeserializeOwned + Send + 'static,
@@ -559,7 +557,7 @@ where
559 557
560fn update_file_notifications_on_threadpool( 558fn update_file_notifications_on_threadpool(
561 pool: &ThreadPool, 559 pool: &ThreadPool,
562 world: ServerWorld, 560 world: WorldSnapshot,
563 publish_decorations: bool, 561 publish_decorations: bool,
564 sender: Sender<Task>, 562 sender: Sender<Task>,
565 subscriptions: Vec<FileId>, 563 subscriptions: Vec<FileId>,
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 8cfb6a192..6373240d5 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -24,11 +24,11 @@ use crate::{
24 cargo_target_spec::{runnable_args, CargoTargetSpec}, 24 cargo_target_spec::{runnable_args, CargoTargetSpec},
25 conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith}, 25 conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith},
26 req::{self, Decoration}, 26 req::{self, Decoration},
27 server_world::ServerWorld, 27 world::WorldSnapshot,
28 LspError, Result, 28 LspError, Result,
29}; 29};
30 30
31pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result<String> { 31pub fn handle_analyzer_status(world: WorldSnapshot, _: ()) -> Result<String> {
32 let mut buf = world.status(); 32 let mut buf = world.status();
33 writeln!(buf, "\n\nrequests:").unwrap(); 33 writeln!(buf, "\n\nrequests:").unwrap();
34 let requests = world.latest_requests.read(); 34 let requests = world.latest_requests.read();
@@ -39,7 +39,7 @@ pub fn handle_analyzer_status(world: ServerWorld, _: ()) -> Result<String> {
39 Ok(buf) 39 Ok(buf)
40} 40}
41 41
42pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result<String> { 42pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) -> Result<String> {
43 let id = params.text_document.try_conv_with(&world)?; 43 let id = params.text_document.try_conv_with(&world)?;
44 let line_index = world.analysis().file_line_index(id); 44 let line_index = world.analysis().file_line_index(id);
45 let text_range = params.range.map(|p| p.conv_with(&line_index)); 45 let text_range = params.range.map(|p| p.conv_with(&line_index));
@@ -49,7 +49,7 @@ pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) ->
49 49
50// FIXME: drop this API 50// FIXME: drop this API
51pub fn handle_extend_selection( 51pub fn handle_extend_selection(
52 world: ServerWorld, 52 world: WorldSnapshot,
53 params: req::ExtendSelectionParams, 53 params: req::ExtendSelectionParams,
54) -> Result<req::ExtendSelectionResult> { 54) -> Result<req::ExtendSelectionResult> {
55 log::error!( 55 log::error!(
@@ -69,7 +69,7 @@ pub fn handle_extend_selection(
69} 69}
70 70
71pub fn handle_selection_range( 71pub fn handle_selection_range(
72 world: ServerWorld, 72 world: WorldSnapshot,
73 params: req::SelectionRangeParams, 73 params: req::SelectionRangeParams,
74) -> Result<Vec<req::SelectionRange>> { 74) -> Result<Vec<req::SelectionRange>> {
75 let _p = profile("handle_selection_range"); 75 let _p = profile("handle_selection_range");
@@ -110,7 +110,7 @@ pub fn handle_selection_range(
110} 110}
111 111
112pub fn handle_find_matching_brace( 112pub fn handle_find_matching_brace(
113 world: ServerWorld, 113 world: WorldSnapshot,
114 params: req::FindMatchingBraceParams, 114 params: req::FindMatchingBraceParams,
115) -> Result<Vec<Position>> { 115) -> Result<Vec<Position>> {
116 let _p = profile("handle_find_matching_brace"); 116 let _p = profile("handle_find_matching_brace");
@@ -129,7 +129,7 @@ pub fn handle_find_matching_brace(
129} 129}
130 130
131pub fn handle_join_lines( 131pub fn handle_join_lines(
132 world: ServerWorld, 132 world: WorldSnapshot,
133 params: req::JoinLinesParams, 133 params: req::JoinLinesParams,
134) -> Result<req::SourceChange> { 134) -> Result<req::SourceChange> {
135 let _p = profile("handle_join_lines"); 135 let _p = profile("handle_join_lines");
@@ -138,7 +138,7 @@ pub fn handle_join_lines(
138} 138}
139 139
140pub fn handle_on_enter( 140pub fn handle_on_enter(
141 world: ServerWorld, 141 world: WorldSnapshot,
142 params: req::TextDocumentPositionParams, 142 params: req::TextDocumentPositionParams,
143) -> Result<Option<req::SourceChange>> { 143) -> Result<Option<req::SourceChange>> {
144 let _p = profile("handle_on_enter"); 144 let _p = profile("handle_on_enter");
@@ -150,7 +150,7 @@ pub fn handle_on_enter(
150} 150}
151 151
152pub fn handle_on_type_formatting( 152pub fn handle_on_type_formatting(
153 world: ServerWorld, 153 world: WorldSnapshot,
154 params: req::DocumentOnTypeFormattingParams, 154 params: req::DocumentOnTypeFormattingParams,
155) -> Result<Option<Vec<TextEdit>>> { 155) -> Result<Option<Vec<TextEdit>>> {
156 let _p = profile("handle_on_type_formatting"); 156 let _p = profile("handle_on_type_formatting");
@@ -181,7 +181,7 @@ pub fn handle_on_type_formatting(
181} 181}
182 182
183pub fn handle_document_symbol( 183pub fn handle_document_symbol(
184 world: ServerWorld, 184 world: WorldSnapshot,
185 params: req::DocumentSymbolParams, 185 params: req::DocumentSymbolParams,
186) -> Result<Option<req::DocumentSymbolResponse>> { 186) -> Result<Option<req::DocumentSymbolResponse>> {
187 let file_id = params.text_document.try_conv_with(&world)?; 187 let file_id = params.text_document.try_conv_with(&world)?;
@@ -219,7 +219,7 @@ pub fn handle_document_symbol(
219} 219}
220 220
221pub fn handle_workspace_symbol( 221pub fn handle_workspace_symbol(
222 world: ServerWorld, 222 world: WorldSnapshot,
223 params: req::WorkspaceSymbolParams, 223 params: req::WorkspaceSymbolParams,
224) -> Result<Option<Vec<SymbolInformation>>> { 224) -> Result<Option<Vec<SymbolInformation>>> {
225 let all_symbols = params.query.contains('#'); 225 let all_symbols = params.query.contains('#');
@@ -245,7 +245,7 @@ pub fn handle_workspace_symbol(
245 245
246 return Ok(Some(res)); 246 return Ok(Some(res));
247 247
248 fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> { 248 fn exec_query(world: &WorldSnapshot, query: Query) -> Result<Vec<SymbolInformation>> {
249 let mut res = Vec::new(); 249 let mut res = Vec::new();
250 for nav in world.analysis().symbol_search(query)? { 250 for nav in world.analysis().symbol_search(query)? {
251 let info = SymbolInformation { 251 let info = SymbolInformation {
@@ -262,7 +262,7 @@ pub fn handle_workspace_symbol(
262} 262}
263 263
264pub fn handle_goto_definition( 264pub fn handle_goto_definition(
265 world: ServerWorld, 265 world: WorldSnapshot,
266 params: req::TextDocumentPositionParams, 266 params: req::TextDocumentPositionParams,
267) -> Result<Option<req::GotoDefinitionResponse>> { 267) -> Result<Option<req::GotoDefinitionResponse>> {
268 let position = params.try_conv_with(&world)?; 268 let position = params.try_conv_with(&world)?;
@@ -282,7 +282,7 @@ pub fn handle_goto_definition(
282} 282}
283 283
284pub fn handle_goto_implementation( 284pub fn handle_goto_implementation(
285 world: ServerWorld, 285 world: WorldSnapshot,
286 params: req::TextDocumentPositionParams, 286 params: req::TextDocumentPositionParams,
287) -> Result<Option<req::GotoImplementationResponse>> { 287) -> Result<Option<req::GotoImplementationResponse>> {
288 let position = params.try_conv_with(&world)?; 288 let position = params.try_conv_with(&world)?;
@@ -302,7 +302,7 @@ pub fn handle_goto_implementation(
302} 302}
303 303
304pub fn handle_goto_type_definition( 304pub fn handle_goto_type_definition(
305 world: ServerWorld, 305 world: WorldSnapshot,
306 params: req::TextDocumentPositionParams, 306 params: req::TextDocumentPositionParams,
307) -> Result<Option<req::GotoTypeDefinitionResponse>> { 307) -> Result<Option<req::GotoTypeDefinitionResponse>> {
308 let position = params.try_conv_with(&world)?; 308 let position = params.try_conv_with(&world)?;
@@ -322,7 +322,7 @@ pub fn handle_goto_type_definition(
322} 322}
323 323
324pub fn handle_parent_module( 324pub fn handle_parent_module(
325 world: ServerWorld, 325 world: WorldSnapshot,
326 params: req::TextDocumentPositionParams, 326 params: req::TextDocumentPositionParams,
327) -> Result<Vec<Location>> { 327) -> Result<Vec<Location>> {
328 let position = params.try_conv_with(&world)?; 328 let position = params.try_conv_with(&world)?;
@@ -335,7 +335,7 @@ pub fn handle_parent_module(
335} 335}
336 336
337pub fn handle_runnables( 337pub fn handle_runnables(
338 world: ServerWorld, 338 world: WorldSnapshot,
339 params: req::RunnablesParams, 339 params: req::RunnablesParams,
340) -> Result<Vec<req::Runnable>> { 340) -> Result<Vec<req::Runnable>> {
341 let file_id = params.text_document.try_conv_with(&world)?; 341 let file_id = params.text_document.try_conv_with(&world)?;
@@ -396,7 +396,7 @@ pub fn handle_runnables(
396} 396}
397 397
398pub fn handle_decorations( 398pub fn handle_decorations(
399 world: ServerWorld, 399 world: WorldSnapshot,
400 params: TextDocumentIdentifier, 400 params: TextDocumentIdentifier,
401) -> Result<Vec<Decoration>> { 401) -> Result<Vec<Decoration>> {
402 let file_id = params.try_conv_with(&world)?; 402 let file_id = params.try_conv_with(&world)?;
@@ -404,7 +404,7 @@ pub fn handle_decorations(
404} 404}
405 405
406pub fn handle_completion( 406pub fn handle_completion(
407 world: ServerWorld, 407 world: WorldSnapshot,
408 params: req::CompletionParams, 408 params: req::CompletionParams,
409) -> Result<Option<req::CompletionResponse>> { 409) -> Result<Option<req::CompletionResponse>> {
410 let _p = profile("handle_completion"); 410 let _p = profile("handle_completion");
@@ -447,7 +447,7 @@ pub fn handle_completion(
447} 447}
448 448
449pub fn handle_folding_range( 449pub fn handle_folding_range(
450 world: ServerWorld, 450 world: WorldSnapshot,
451 params: FoldingRangeParams, 451 params: FoldingRangeParams,
452) -> Result<Option<Vec<FoldingRange>>> { 452) -> Result<Option<Vec<FoldingRange>>> {
453 let file_id = params.text_document.try_conv_with(&world)?; 453 let file_id = params.text_document.try_conv_with(&world)?;
@@ -481,7 +481,7 @@ pub fn handle_folding_range(
481} 481}
482 482
483pub fn handle_signature_help( 483pub fn handle_signature_help(
484 world: ServerWorld, 484 world: WorldSnapshot,
485 params: req::TextDocumentPositionParams, 485 params: req::TextDocumentPositionParams,
486) -> Result<Option<req::SignatureHelp>> { 486) -> Result<Option<req::SignatureHelp>> {
487 let position = params.try_conv_with(&world)?; 487 let position = params.try_conv_with(&world)?;
@@ -500,7 +500,7 @@ pub fn handle_signature_help(
500} 500}
501 501
502pub fn handle_hover( 502pub fn handle_hover(
503 world: ServerWorld, 503 world: WorldSnapshot,
504 params: req::TextDocumentPositionParams, 504 params: req::TextDocumentPositionParams,
505) -> Result<Option<Hover>> { 505) -> Result<Option<Hover>> {
506 let position = params.try_conv_with(&world)?; 506 let position = params.try_conv_with(&world)?;
@@ -522,7 +522,7 @@ pub fn handle_hover(
522 522
523/// Test doc comment 523/// Test doc comment
524pub fn handle_prepare_rename( 524pub fn handle_prepare_rename(
525 world: ServerWorld, 525 world: WorldSnapshot,
526 params: req::TextDocumentPositionParams, 526 params: req::TextDocumentPositionParams,
527) -> Result<Option<PrepareRenameResponse>> { 527) -> Result<Option<PrepareRenameResponse>> {
528 let position = params.try_conv_with(&world)?; 528 let position = params.try_conv_with(&world)?;
@@ -543,7 +543,7 @@ pub fn handle_prepare_rename(
543 Ok(Some(PrepareRenameResponse::Range(loc.range))) 543 Ok(Some(PrepareRenameResponse::Range(loc.range)))
544} 544}
545 545
546pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result<Option<WorkspaceEdit>> { 546pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Option<WorkspaceEdit>> {
547 let file_id = params.text_document.try_conv_with(&world)?; 547 let file_id = params.text_document.try_conv_with(&world)?;
548 let line_index = world.analysis().file_line_index(file_id); 548 let line_index = world.analysis().file_line_index(file_id);
549 let offset = params.position.conv_with(&line_index); 549 let offset = params.position.conv_with(&line_index);
@@ -569,7 +569,7 @@ pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result<Option<
569} 569}
570 570
571pub fn handle_references( 571pub fn handle_references(
572 world: ServerWorld, 572 world: WorldSnapshot,
573 params: req::ReferenceParams, 573 params: req::ReferenceParams,
574) -> Result<Option<Vec<Location>>> { 574) -> Result<Option<Vec<Location>>> {
575 let file_id = params.text_document.try_conv_with(&world)?; 575 let file_id = params.text_document.try_conv_with(&world)?;
@@ -597,7 +597,7 @@ pub fn handle_references(
597} 597}
598 598
599pub fn handle_formatting( 599pub fn handle_formatting(
600 world: ServerWorld, 600 world: WorldSnapshot,
601 params: DocumentFormattingParams, 601 params: DocumentFormattingParams,
602) -> Result<Option<Vec<TextEdit>>> { 602) -> Result<Option<Vec<TextEdit>>> {
603 let file_id = params.text_document.try_conv_with(&world)?; 603 let file_id = params.text_document.try_conv_with(&world)?;
@@ -641,7 +641,7 @@ pub fn handle_formatting(
641} 641}
642 642
643pub fn handle_code_action( 643pub fn handle_code_action(
644 world: ServerWorld, 644 world: WorldSnapshot,
645 params: req::CodeActionParams, 645 params: req::CodeActionParams,
646) -> Result<Option<CodeActionResponse>> { 646) -> Result<Option<CodeActionResponse>> {
647 let _p = profile("handle_code_action"); 647 let _p = profile("handle_code_action");
@@ -704,7 +704,7 @@ pub fn handle_code_action(
704} 704}
705 705
706pub fn handle_code_lens( 706pub fn handle_code_lens(
707 world: ServerWorld, 707 world: WorldSnapshot,
708 params: req::CodeLensParams, 708 params: req::CodeLensParams,
709) -> Result<Option<Vec<CodeLens>>> { 709) -> Result<Option<Vec<CodeLens>>> {
710 let file_id = params.text_document.try_conv_with(&world)?; 710 let file_id = params.text_document.try_conv_with(&world)?;
@@ -781,7 +781,7 @@ enum CodeLensResolveData {
781 Impls(req::TextDocumentPositionParams), 781 Impls(req::TextDocumentPositionParams),
782} 782}
783 783
784pub fn handle_code_lens_resolve(world: ServerWorld, code_lens: CodeLens) -> Result<CodeLens> { 784pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> {
785 let data = code_lens.data.unwrap(); 785 let data = code_lens.data.unwrap();
786 let resolve = serde_json::from_value(data)?; 786 let resolve = serde_json::from_value(data)?;
787 match resolve { 787 match resolve {
@@ -826,7 +826,7 @@ pub fn handle_code_lens_resolve(world: ServerWorld, code_lens: CodeLens) -> Resu
826} 826}
827 827
828pub fn handle_document_highlight( 828pub fn handle_document_highlight(
829 world: ServerWorld, 829 world: WorldSnapshot,
830 params: req::TextDocumentPositionParams, 830 params: req::TextDocumentPositionParams,
831) -> Result<Option<Vec<DocumentHighlight>>> { 831) -> Result<Option<Vec<DocumentHighlight>>> {
832 let file_id = params.text_document.try_conv_with(&world)?; 832 let file_id = params.text_document.try_conv_with(&world)?;
@@ -845,7 +845,7 @@ pub fn handle_document_highlight(
845} 845}
846 846
847pub fn publish_diagnostics( 847pub fn publish_diagnostics(
848 world: &ServerWorld, 848 world: &WorldSnapshot,
849 file_id: FileId, 849 file_id: FileId,
850) -> Result<req::PublishDiagnosticsParams> { 850) -> Result<req::PublishDiagnosticsParams> {
851 let uri = world.file_id_to_uri(file_id)?; 851 let uri = world.file_id_to_uri(file_id)?;
@@ -867,14 +867,14 @@ pub fn publish_diagnostics(
867} 867}
868 868
869pub fn publish_decorations( 869pub fn publish_decorations(
870 world: &ServerWorld, 870 world: &WorldSnapshot,
871 file_id: FileId, 871 file_id: FileId,
872) -> Result<req::PublishDecorationsParams> { 872) -> Result<req::PublishDecorationsParams> {
873 let uri = world.file_id_to_uri(file_id)?; 873 let uri = world.file_id_to_uri(file_id)?;
874 Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? }) 874 Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? })
875} 875}
876 876
877fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> { 877fn highlight(world: &WorldSnapshot, file_id: FileId) -> Result<Vec<Decoration>> {
878 let line_index = world.analysis().file_line_index(file_id); 878 let line_index = world.analysis().file_line_index(file_id);
879 let res = world 879 let res = world
880 .analysis() 880 .analysis()
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/world.rs
index 6076a6cd6..e0d2f6306 100644
--- a/crates/ra_lsp_server/src/server_world.rs
+++ b/crates/ra_lsp_server/src/world.rs
@@ -22,8 +22,13 @@ use crate::{
22 LspError, 22 LspError,
23}; 23};
24 24
25/// `WorldState` is the primary mutable state of the language server
26///
27/// The most interesting components are `vfs`, which stores a consistent
28/// snapshot of the file systems, and `analysis_host`, which stores our
29/// incremental salsa database.
25#[derive(Debug)] 30#[derive(Debug)]
26pub struct ServerWorldState { 31pub struct WorldState {
27 pub roots_to_scan: usize, 32 pub roots_to_scan: usize,
28 pub roots: Vec<PathBuf>, 33 pub roots: Vec<PathBuf>,
29 pub workspaces: Arc<Vec<ProjectWorkspace>>, 34 pub workspaces: Arc<Vec<ProjectWorkspace>>,
@@ -32,15 +37,16 @@ pub struct ServerWorldState {
32 pub latest_requests: Arc<RwLock<LatestRequests>>, 37 pub latest_requests: Arc<RwLock<LatestRequests>>,
33} 38}
34 39
35pub struct ServerWorld { 40/// An immutable snapshot of the world's state at a point in time.
41pub struct WorldSnapshot {
36 pub workspaces: Arc<Vec<ProjectWorkspace>>, 42 pub workspaces: Arc<Vec<ProjectWorkspace>>,
37 pub analysis: Analysis, 43 pub analysis: Analysis,
38 pub vfs: Arc<RwLock<Vfs>>, 44 pub vfs: Arc<RwLock<Vfs>>,
39 pub latest_requests: Arc<RwLock<LatestRequests>>, 45 pub latest_requests: Arc<RwLock<LatestRequests>>,
40} 46}
41 47
42impl ServerWorldState { 48impl WorldState {
43 pub fn new(folder_roots: Vec<PathBuf>, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState { 49 pub fn new(folder_roots: Vec<PathBuf>, workspaces: Vec<ProjectWorkspace>) -> WorldState {
44 let mut change = AnalysisChange::new(); 50 let mut change = AnalysisChange::new();
45 51
46 let mut roots = Vec::new(); 52 let mut roots = Vec::new();
@@ -70,7 +76,7 @@ impl ServerWorldState {
70 76
71 let mut analysis_host = AnalysisHost::default(); 77 let mut analysis_host = AnalysisHost::default();
72 analysis_host.apply_change(change); 78 analysis_host.apply_change(change);
73 ServerWorldState { 79 WorldState {
74 roots_to_scan, 80 roots_to_scan,
75 roots: folder_roots, 81 roots: folder_roots,
76 workspaces: Arc::new(workspaces), 82 workspaces: Arc::new(workspaces),
@@ -136,8 +142,8 @@ impl ServerWorldState {
136 self.analysis_host.apply_change(change); 142 self.analysis_host.apply_change(change);
137 } 143 }
138 144
139 pub fn snapshot(&self) -> ServerWorld { 145 pub fn snapshot(&self) -> WorldSnapshot {
140 ServerWorld { 146 WorldSnapshot {
141 workspaces: Arc::clone(&self.workspaces), 147 workspaces: Arc::clone(&self.workspaces),
142 analysis: self.analysis_host.analysis(), 148 analysis: self.analysis_host.analysis(),
143 vfs: Arc::clone(&self.vfs), 149 vfs: Arc::clone(&self.vfs),
@@ -158,7 +164,7 @@ impl ServerWorldState {
158 } 164 }
159} 165}
160 166
161impl ServerWorld { 167impl WorldSnapshot {
162 pub fn analysis(&self) -> &Analysis { 168 pub fn analysis(&self) -> &Analysis {
163 &self.analysis 169 &self.analysis
164 } 170 }