From 12e3b4c70b5ef23b2fdfc197296d483680e125f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:49:43 +0300 Subject: reformat the world --- crates/ra_lsp_server/src/main_loop/handlers.rs | 75 +++++----------------- .../ra_lsp_server/src/main_loop/subscriptions.rs | 4 +- 2 files changed, 17 insertions(+), 62 deletions(-) (limited to 'crates/ra_lsp_server/src/main_loop') 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( .into_iter() .map_conv_with(&line_index) .map(|range| FileRange { file_id, range }) - .map(|frange| { - world - .analysis() - .extend_selection(frange) - .map(|it| it.conv_with(&line_index)) - }) + .map(|frange| world.analysis().extend_selection(frange).map(|it| it.conv_with(&line_index))) .collect::>>()?; Ok(req::ExtendSelectionResult { selections }) } @@ -67,10 +62,7 @@ pub fn handle_find_matching_brace( .into_iter() .map_conv_with(&line_index) .map(|offset| { - world - .analysis() - .matching_brace(FilePosition { file_id, offset }) - .unwrap_or(offset) + world.analysis().matching_brace(FilePosition { file_id, offset }).unwrap_or(offset) }) .map_conv_with(&line_index) .collect(); @@ -171,11 +163,7 @@ pub fn handle_workspace_symbol( let all_symbols = params.query.contains('#'); let libs = params.query.contains('*'); let query = { - let query: String = params - .query - .chars() - .filter(|&c| c != '#' && c != '*') - .collect(); + let query: String = params.query.chars().filter(|&c| c != '#' && c != '*').collect(); let mut q = Query::new(query); if !all_symbols { q.only_types(); @@ -367,10 +355,7 @@ pub fn handle_completion( Some(items) => items, }; let line_index = world.analysis().file_line_index(position.file_id); - let items = items - .into_iter() - .map(|item| item.conv_with(&line_index)) - .collect(); + let items = items.into_iter().map(|item| item.conv_with(&line_index)).collect(); Ok(Some(req::CompletionResponse::Array(items))) } @@ -496,9 +481,8 @@ pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result return Ok(None), Some(it) => it, @@ -517,14 +501,10 @@ pub fn handle_references( let line_index = world.analysis().file_line_index(file_id); let offset = params.position.conv_with(&line_index); - let refs = world - .analysis() - .find_all_refs(FilePosition { file_id, offset })?; + let refs = world.analysis().find_all_refs(FilePosition { file_id, offset })?; Ok(Some( - refs.into_iter() - .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok()) - .collect(), + refs.into_iter().filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok()).collect(), )) } @@ -540,9 +520,7 @@ pub fn handle_formatting( use std::process; let mut rustfmt = process::Command::new("rustfmt"); - rustfmt - .stdin(process::Stdio::piped()) - .stdout(process::Stdio::piped()); + rustfmt.stdin(process::Stdio::piped()).stdout(process::Stdio::piped()); if let Ok(path) = params.text_document.uri.to_file_path() { if let Some(parent) = path.parent() { @@ -582,10 +560,7 @@ pub fn handle_code_action( let line_index = world.analysis().file_line_index(file_id); let range = params.range.conv_with(&line_index); - let assists = world - .analysis() - .assists(FileRange { file_id, range })? - .into_iter(); + let assists = world.analysis().assists(FileRange { file_id, range })?.into_iter(); let fixes = world .analysis() .diagnostics(file_id)? @@ -720,18 +695,11 @@ pub fn handle_code_lens_resolve(world: ServerWorld, code_lens: CodeLens) -> Resu to_value(locations).unwrap(), ]), }; - Ok(CodeLens { - range: code_lens.range, - command: Some(cmd), - data: None, - }) + Ok(CodeLens { range: code_lens.range, command: Some(cmd), data: None }) } None => Ok(CodeLens { range: code_lens.range, - command: Some(Command { - title: "Error".into(), - ..Default::default() - }), + command: Some(Command { title: "Error".into(), ..Default::default() }), data: None, }), } @@ -744,16 +712,11 @@ pub fn handle_document_highlight( let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); - let refs = world - .analysis() - .find_all_refs(params.try_conv_with(&world)?)?; + let refs = world.analysis().find_all_refs(params.try_conv_with(&world)?)?; Ok(Some( refs.into_iter() - .map(|r| DocumentHighlight { - range: r.1.conv_with(&line_index), - kind: None, - }) + .map(|r| DocumentHighlight { range: r.1.conv_with(&line_index), kind: None }) .collect(), )) } @@ -785,10 +748,7 @@ pub fn publish_decorations( file_id: FileId, ) -> Result { let uri = world.file_id_to_uri(file_id)?; - Ok(req::PublishDecorationsParams { - uri, - decorations: highlight(&world, file_id)?, - }) + Ok(req::PublishDecorationsParams { uri, decorations: highlight(&world, file_id)? }) } fn highlight(world: &ServerWorld, file_id: FileId) -> Result> { @@ -797,10 +757,7 @@ fn highlight(world: &ServerWorld, file_id: FileId) -> Result> { .analysis() .highlight(file_id)? .into_iter() - .map(|h| Decoration { - range: h.range.conv_with(&line_index), - tag: h.tag, - }) + .map(|h| Decoration { range: h.range.conv_with(&line_index), tag: h.tag }) .collect(); Ok(res) } 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 { impl Subscriptions { pub fn new() -> Subscriptions { - Subscriptions { - subs: FxHashSet::default(), - } + Subscriptions { subs: FxHashSet::default() } } pub fn add_sub(&mut self, file_id: FileId) { self.subs.insert(file_id); -- cgit v1.2.3