From 6be50f7d5de3737464853a589673375fc0cafa97 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 31 Oct 2018 23:41:43 +0300 Subject: Reformat all --- crates/ra_lsp_server/src/caps.rs | 10 +-- crates/ra_lsp_server/src/conv.rs | 3 +- crates/ra_lsp_server/src/lib.rs | 2 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 87 ++++++++++++-------------- crates/ra_lsp_server/src/main_loop/mod.rs | 31 ++++----- crates/ra_lsp_server/src/path_map.rs | 3 +- crates/ra_lsp_server/src/req.rs | 4 +- crates/ra_lsp_server/src/server_world.rs | 8 +-- 8 files changed, 74 insertions(+), 74 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index b6436b646..ac6aacfd3 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs @@ -1,8 +1,8 @@ use languageserver_types::{ CodeActionProviderCapability, CompletionOptions, DocumentOnTypeFormattingOptions, - ExecuteCommandOptions, FoldingRangeProviderCapability, ServerCapabilities, - SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, - TextDocumentSyncOptions, RenameProviderCapability, RenameOptions + ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, + ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, + TextDocumentSyncOptions, }; pub fn server_capabilities() -> ServerCapabilities { @@ -40,8 +40,8 @@ pub fn server_capabilities() -> ServerCapabilities { more_trigger_character: None, }), folding_range_provider: Some(FoldingRangeProviderCapability::Simple(true)), - rename_provider: Some(RenameProviderCapability::Options(RenameOptions{ - prepare_provider: Some(true) + rename_provider: Some(RenameProviderCapability::Options(RenameOptions { + prepare_provider: Some(true), })), color_provider: None, execute_command_provider: Some(ExecuteCommandOptions { diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index bc0cf7c68..84ffac2da 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -192,7 +192,8 @@ impl TryConvWith for SourceChange { .map(|it| it.edits.as_slice()) .unwrap_or(&[]); let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); - let position = Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))); + let position = + Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))); Some(TextDocumentPositionParams { text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?), position, diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index ce77b2a33..f9481e04d 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs @@ -36,4 +36,4 @@ pub mod thread_watcher; mod vfs; pub type Result = ::std::result::Result; -pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError}; \ No newline at end of file +pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError}; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 20cb5f772..c853ff653 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -1,15 +1,16 @@ use std::collections::HashMap; -use rustc_hash::FxHashMap; +use gen_lsp_server::ErrorCode; use languageserver_types::{ CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic, - DiagnosticSeverity, DocumentSymbol, FoldingRange, FoldingRangeKind, FoldingRangeParams, - InsertTextFormat, Location, Position, SymbolInformation, TextDocumentIdentifier, TextEdit, - RenameParams, WorkspaceEdit, PrepareRenameResponse, Documentation, MarkupContent, MarkupKind + DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, + FoldingRangeParams, InsertTextFormat, Location, MarkupContent, MarkupKind, Position, + PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, + WorkspaceEdit, }; -use gen_lsp_server::ErrorCode; use ra_analysis::{FileId, FoldKind, Query, RunnableKind}; use ra_syntax::text_utils::contains_offset_nonstrict; +use rustc_hash::FxHashMap; use serde_json::to_value; use crate::{ @@ -17,13 +18,10 @@ use crate::{ project_model::TargetKind, req::{self, Decoration}, server_world::ServerWorld, - Result, LspError + LspError, Result, }; -pub fn handle_syntax_tree( - world: ServerWorld, - params: req::SyntaxTreeParams, -) -> Result { +pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) -> Result { let id = params.text_document.try_conv_with(&world)?; let res = world.analysis().syntax_tree(id); Ok(res) @@ -182,10 +180,7 @@ pub fn handle_workspace_symbol( return Ok(Some(res)); - fn exec_query( - world: &ServerWorld, - query: Query, - ) -> Result> { + fn exec_query(world: &ServerWorld, query: Query) -> Result> { let mut res = Vec::new(); for (file_id, symbol) in world.analysis().symbol_search(query)? { let line_index = world.analysis().file_line_index(file_id); @@ -290,7 +285,11 @@ pub fn handle_runnables( }); return Ok(res); - fn runnable_args(world: &ServerWorld, file_id: FileId, kind: &RunnableKind) -> Result> { + fn runnable_args( + world: &ServerWorld, + file_id: FileId, + kind: &RunnableKind, + ) -> Result> { let spec = CargoTargetSpec::for_file(world, file_id)?; let mut res = Vec::new(); match kind { @@ -327,18 +326,15 @@ pub fn handle_runnables( }; let file_id = world.analysis().crate_root(crate_id)?; let path = world.path_map.get_path(file_id); - let res = world - .workspaces - .iter() - .find_map(|ws| { - let tgt = ws.target_by_root(path)?; - let res = CargoTargetSpec { - package: tgt.package(ws).name(ws).to_string(), - target: tgt.name(ws).to_string(), - target_kind: tgt.kind(ws), - }; - Some(res) - }); + let res = world.workspaces.iter().find_map(|ws| { + let tgt = ws.target_by_root(path)?; + let res = CargoTargetSpec { + package: tgt.package(ws).name(ws).to_string(), + target: tgt.name(ws).to_string(), + target_kind: tgt.kind(ws), + }; + Some(res) + }); Ok(res) } @@ -367,7 +363,6 @@ pub fn handle_runnables( } TargetKind::Other => (), } - } } } @@ -453,9 +448,7 @@ pub fn handle_signature_help( let line_index = world.analysis().file_line_index(file_id); let offset = params.position.conv_with(&line_index); - if let Some((descriptor, active_param)) = - world.analysis().resolve_callable(file_id, offset)? - { + if let Some((descriptor, active_param)) = world.analysis().resolve_callable(file_id, offset)? { let parameters: Vec = descriptor .params .iter() @@ -468,7 +461,7 @@ pub fn handle_signature_help( let documentation = if let Some(doc) = descriptor.doc { Some(Documentation::MarkupContent(MarkupContent { kind: MarkupKind::Markdown, - value: doc + value: doc, })) } else { None @@ -511,16 +504,17 @@ pub fn handle_prepare_rename( Ok(Some(PrepareRenameResponse::Range(loc.range))) } -pub fn handle_rename( - world: ServerWorld, - params: RenameParams, -) -> Result> { +pub fn handle_rename(world: ServerWorld, params: RenameParams) -> Result> { let file_id = params.text_document.try_conv_with(&world)?; let line_index = world.analysis().file_line_index(file_id); let offset = params.position.conv_with(&line_index); if params.new_name.is_empty() { - return Err(LspError::new(ErrorCode::InvalidParams as i32, "New Name cannot be empty".into()).into()); + return Err(LspError::new( + ErrorCode::InvalidParams as i32, + "New Name cannot be empty".into(), + ) + .into()); } let refs = world.analysis().find_all_refs(file_id, offset)?; @@ -531,11 +525,10 @@ pub fn handle_rename( let mut changes = HashMap::new(); for r in refs { if let Ok(loc) = to_location(r.0, r.1, &world, &line_index) { - changes.entry(loc.uri).or_insert(Vec::new()).push( - TextEdit { - range: loc.range, - new_text: params.new_name.clone() - }); + changes.entry(loc.uri).or_insert(Vec::new()).push(TextEdit { + range: loc.range, + new_text: params.new_name.clone(), + }); } } @@ -543,7 +536,7 @@ pub fn handle_rename( changes: Some(changes), // TODO: return this instead if client/server support it. See #144 - document_changes : None, + document_changes: None, })) } @@ -557,9 +550,11 @@ pub fn handle_references( let refs = world.analysis().find_all_refs(file_id, offset)?; - Ok(Some(refs.into_iter() - .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok()) - .collect())) + Ok(Some( + refs.into_iter() + .filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok()) + .collect(), + )) } pub fn handle_code_action( diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 9ddc3fd0b..c568706bd 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -24,7 +24,10 @@ use crate::{ }; #[derive(Debug, Fail)] -#[fail(display = "Language Server request failed with {}. ({})", code, message)] +#[fail( + display = "Language Server request failed with {}. ({})", + code, message +)] pub struct LspError { pub code: i32, pub message: String, @@ -32,7 +35,7 @@ pub struct LspError { impl LspError { pub fn new(code: i32, message: String) -> LspError { - LspError {code, message} + LspError { code, message } } } @@ -214,11 +217,7 @@ fn main_loop_inner( } } -fn on_task( - task: Task, - msg_sender: &Sender, - pending_requests: &mut FxHashSet, -) { +fn on_task(task: Task, msg_sender: &Sender, pending_requests: &mut FxHashSet) { match task { Task::Respond(response) => { if pending_requests.remove(&response.id) { @@ -373,12 +372,16 @@ impl<'a> PoolDispatcher<'a> { self.pool.spawn(move || { let resp = match f(world, params) { Ok(resp) => RawResponse::ok::(id, &resp), - Err(e) => { - match e.downcast::() { - Ok(lsp_error) => RawResponse::err(id, lsp_error.code, lsp_error.message), - Err(e) => RawResponse::err(id, ErrorCode::InternalError as i32, format!("{}\n{}", e, e.backtrace())) + Err(e) => match e.downcast::() { + Ok(lsp_error) => { + RawResponse::err(id, lsp_error.code, lsp_error.message) } - } + Err(e) => RawResponse::err( + id, + ErrorCode::InternalError as i32, + format!("{}\n{}", e, e.backtrace()), + ), + }, }; let task = Task::Respond(resp); sender.send(task); @@ -412,7 +415,7 @@ fn update_file_notifications_on_threadpool( if !is_canceled(&e) { error!("failed to compute diagnostics: {:?}", e); } - }, + } Ok(params) => { let not = RawNotification::new::(¶ms); sender.send(Task::Notify(not)); @@ -423,7 +426,7 @@ fn update_file_notifications_on_threadpool( if !is_canceled(&e) { error!("failed to compute decorations: {:?}", e); } - }, + } Ok(params) => { let not = RawNotification::new::(¶ms); sender.send(Task::Notify(not)) diff --git a/crates/ra_lsp_server/src/path_map.rs b/crates/ra_lsp_server/src/path_map.rs index d5957d673..dd09fa10a 100644 --- a/crates/ra_lsp_server/src/path_map.rs +++ b/crates/ra_lsp_server/src/path_map.rs @@ -33,7 +33,8 @@ impl PathMap { } pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) { let mut inserted = false; - let file_id = self.path2id + let file_id = self + .path2id .get(path.as_path()) .map(|&id| id) .unwrap_or_else(|| { diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 6cd04d84c..9d911912d 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -6,8 +6,8 @@ pub use languageserver_types::{ notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, - PublishDiagnosticsParams, SignatureHelp, TextDocumentEdit, TextDocumentPositionParams, - TextEdit, WorkspaceSymbolParams, ReferenceParams, + PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, + TextDocumentPositionParams, TextEdit, WorkspaceSymbolParams, }; pub enum SyntaxTree {} diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 25986e230..3e76d2527 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -5,7 +5,9 @@ use std::{ }; use languageserver_types::Url; -use ra_analysis::{Analysis, AnalysisHost, AnalysisChange, CrateGraph, FileId, FileResolver, LibraryData}; +use ra_analysis::{ + Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData, +}; use rustc_hash::FxHashMap; use crate::{ @@ -65,9 +67,7 @@ impl ServerWorldState { Some((file_id, text)) } }) - .for_each(|(file_id, text)| { - change.add_file(file_id, text) - }); + .for_each(|(file_id, text)| change.add_file(file_id, text)); } if inserted { change.set_file_resolver(Arc::new(self.path_map.clone())) -- cgit v1.2.3