aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-08 11:49:43 +0000
committerAleksey Kladov <[email protected]>2019-02-08 11:49:43 +0000
commit12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch)
tree71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_lsp_server/src/main_loop
parent5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff)
reformat the world
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs75
-rw-r--r--crates/ra_lsp_server/src/main_loop/subscriptions.rs4
2 files changed, 17 insertions, 62 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index aa55d1255..0cdb39c32 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -46,12 +46,7 @@ pub fn handle_extend_selection(
46 .into_iter() 46 .into_iter()
47 .map_conv_with(&line_index) 47 .map_conv_with(&line_index)
48 .map(|range| FileRange { file_id, range }) 48 .map(|range| FileRange { file_id, range })
49 .map(|frange| { 49 .map(|frange| world.analysis().extend_selection(frange).map(|it| it.conv_with(&line_index)))
50 world
51 .analysis()
52 .extend_selection(frange)
53 .map(|it| it.conv_with(&line_index))
54 })
55 .collect::<Cancelable<Vec<_>>>()?; 50 .collect::<Cancelable<Vec<_>>>()?;
56 Ok(req::ExtendSelectionResult { selections }) 51 Ok(req::ExtendSelectionResult { selections })
57} 52}
@@ -67,10 +62,7 @@ pub fn handle_find_matching_brace(
67 .into_iter() 62 .into_iter()
68 .map_conv_with(&line_index) 63 .map_conv_with(&line_index)
69 .map(|offset| { 64 .map(|offset| {
70 world 65 world.analysis().matching_brace(FilePosition { file_id, offset }).unwrap_or(offset)
71 .analysis()
72 .matching_brace(FilePosition { file_id, offset })
73 .unwrap_or(offset)
74 }) 66 })
75 .map_conv_with(&line_index) 67 .map_conv_with(&line_index)
76 .collect(); 68 .collect();
@@ -171,11 +163,7 @@ pub fn handle_workspace_symbol(
171 let all_symbols = params.query.contains('#'); 163 let all_symbols = params.query.contains('#');
172 let libs = params.query.contains('*'); 164 let libs = params.query.contains('*');
173 let query = { 165 let query = {
174 let query: String = params 166 let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect();
175 .query
176 .chars()
177 .filter(|&c| c != '#' && c != '*')
178 .collect();
179 let mut q = Query::new(query); 167 let mut q = Query::new(query);
180 if !all_symbols { 168 if !all_symbols {
181 q.only_types(); 169 q.only_types();
@@ -367,10 +355,7 @@ pub fn handle_completion(
367 Some(items) => items, 355 Some(items) => items,
368 }; 356 };
369 let line_index = world.analysis().file_line_index(position.file_id); 357 let line_index = world.analysis().file_line_index(position.file_id);
370 let items = items 358 let items = items.into_iter().map(|item| item.conv_with(&line_index)).collect();
371 .into_iter()
372 .map(|item| item.conv_with(&line_index))
373 .collect();
374 359
375 Ok(Some(req::CompletionResponse::Array(items))) 360 Ok(Some(req::CompletionResponse::Array(items)))
376} 361}
@@ -496,9 +481,8 @@ pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result<Option<
496 .into()); 481 .into());
497 } 482 }
498 483
499 let optional_change = world 484 let optional_change =
500 .analysis() 485 world.analysis().rename(FilePosition { file_id, offset }, &*params.new_name)?;
501 .rename(FilePosition { file_id, offset }, &*params.new_name)?;
502 let change = match optional_change { 486 let change = match optional_change {
503 None => return Ok(None), 487 None => return Ok(None),
504 Some(it) => it, 488 Some(it) => it,
@@ -517,14 +501,10 @@ pub fn handle_references(
517 let line_index = world.analysis().file_line_index(file_id); 501 let line_index = world.analysis().file_line_index(file_id);
518 let offset = params.position.conv_with(&line_index); 502 let offset = params.position.conv_with(&line_index);
519 503
520 let refs = world 504 let refs = world.analysis().find_all_refs(FilePosition { file_id, offset })?;
521 .analysis()
522 .find_all_refs(FilePosition { file_id, offset })?;
523 505
524 Ok(Some( 506 Ok(Some(
525 refs.into_iter() 507 refs.into_iter().filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok()).collect(),
526 .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())
527 .collect(),
528 )) 508 ))
529} 509}
530 510
@@ -540,9 +520,7 @@ pub fn handle_formatting(
540 520
541 use std::process; 521 use std::process;
542 let mut rustfmt = process::Command::new("rustfmt"); 522 let mut rustfmt = process::Command::new("rustfmt");
543 rustfmt 523 rustfmt.stdin(process::Stdio::piped()).stdout(process::Stdio::piped());
544 .stdin(process::Stdio::piped())
545 .stdout(process::Stdio::piped());
546 524
547 if let Ok(path) = params.text_document.uri.to_file_path() { 525 if let Ok(path) = params.text_document.uri.to_file_path() {
548 if let Some(parent) = path.parent() { 526 if let Some(parent) = path.parent() {
@@ -582,10 +560,7 @@ pub fn handle_code_action(
582 let line_index = world.analysis().file_line_index(file_id); 560 let line_index = world.analysis().file_line_index(file_id);
583 let range = params.range.conv_with(&line_index); 561 let range = params.range.conv_with(&line_index);
584 562
585 let assists = world 563 let assists = world.analysis().assists(FileRange { file_id, range })?.into_iter();
586 .analysis()
587 .assists(FileRange { file_id, range })?
588 .into_iter();
589 let fixes = world 564 let fixes = world
590 .analysis() 565 .analysis()
591 .diagnostics(file_id)? 566 .diagnostics(file_id)?
@@ -720,18 +695,11 @@ pub fn handle_code_lens_resolve(world: ServerWorld, code_lens: CodeLens) -> Resu
720 to_value(locations).unwrap(), 695 to_value(locations).unwrap(),
721 ]), 696 ]),
722 }; 697 };
723 Ok(CodeLens { 698 Ok(CodeLens { range: code_lens.range, command: Some(cmd), data: None })
724 range: code_lens.range,
725 command: Some(cmd),
726 data: None,
727 })
728 } 699 }
729 None => Ok(CodeLens { 700 None => Ok(CodeLens {
730 range: code_lens.range, 701 range: code_lens.range,
731 command: Some(Command { 702 command: Some(Command { title: "Error".into(), ..Default::default() }),
732 title: "Error".into(),
733 ..Default::default()
734 }),
735 data: None, 703 data: None,
736 }), 704 }),
737 } 705 }
@@ -744,16 +712,11 @@ pub fn handle_document_highlight(
744 let file_id = params.text_document.try_conv_with(&world)?; 712 let file_id = params.text_document.try_conv_with(&world)?;
745 let line_index = world.analysis().file_line_index(file_id); 713 let line_index = world.analysis().file_line_index(file_id);
746 714
747 let refs = world 715 let refs = world.analysis().find_all_refs(params.try_conv_with(&world)?)?;
748 .analysis()
749 .find_all_refs(params.try_conv_with(&world)?)?;
750 716
751 Ok(Some( 717 Ok(Some(
752 refs.into_iter() 718 refs.into_iter()
753 .map(|r| DocumentHighlight { 719 .map(|r| DocumentHighlight { range: r.1.conv_with(&line_index), kind: None })
754 range: r.1.conv_with(&line_index),
755 kind: None,
756 })
757 .collect(), 720 .collect(),
758 )) 721 ))
759} 722}
@@ -785,10 +748,7 @@ pub fn publish_decorations(
785 file_id: FileId, 748 file_id: FileId,
786) -> Result<req::PublishDecorationsParams> { 749) -> Result<req::PublishDecorationsParams> {
787 let uri = world.file_id_to_uri(file_id)?; 750 let uri = world.file_id_to_uri(file_id)?;
788 Ok(req::PublishDecorationsParams { 751 Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? })
789 uri,
790 decorations: highlight(&world, file_id)?,
791 })
792} 752}
793 753
794fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> { 754fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> {
@@ -797,10 +757,7 @@ fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> {
797 .analysis() 757 .analysis()
798 .highlight(file_id)? 758 .highlight(file_id)?
799 .into_iter() 759 .into_iter()
800 .map(|h| Decoration { 760 .map(|h| Decoration { range: h.range.conv_with(&line_index), tag: h.tag })
801 range: h.range.conv_with(&line_index),
802 tag: h.tag,
803 })
804 .collect(); 761 .collect();
805 Ok(res) 762 Ok(res)
806} 763}
diff --git a/crates/ra_lsp_server/src/main_loop/subscriptions.rs b/crates/ra_lsp_server/src/main_loop/subscriptions.rs
index a83e01557..11bd952d9 100644
--- a/crates/ra_lsp_server/src/main_loop/subscriptions.rs
+++ b/crates/ra_lsp_server/src/main_loop/subscriptions.rs
@@ -7,9 +7,7 @@ pub struct Subscriptions {
7 7
8impl Subscriptions { 8impl Subscriptions {
9 pub fn new() -> Subscriptions { 9 pub fn new() -> Subscriptions {
10 Subscriptions { 10 Subscriptions { subs: FxHashSet::default() }
11 subs: FxHashSet::default(),
12 }
13 } 11 }
14 pub fn add_sub(&mut self, file_id: FileId) { 12 pub fn add_sub(&mut self, file_id: FileId) {
15 self.subs.insert(file_id); 13 self.subs.insert(file_id);