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_analysis/src/descriptors/function/imp.rs | 12 +++---- crates/ra_analysis/src/descriptors/function/mod.rs | 29 ++++++++-------- .../ra_analysis/src/descriptors/function/scope.rs | 7 ++-- crates/ra_analysis/src/descriptors/mod.rs | 39 ++++++++++------------ crates/ra_analysis/src/descriptors/module/imp.rs | 33 ++++++++++-------- crates/ra_analysis/src/descriptors/module/mod.rs | 30 ++++++++--------- crates/ra_analysis/src/descriptors/module/scope.rs | 5 ++- 7 files changed, 72 insertions(+), 83 deletions(-) (limited to 'crates/ra_analysis/src/descriptors') diff --git a/crates/ra_analysis/src/descriptors/function/imp.rs b/crates/ra_analysis/src/descriptors/function/imp.rs index 0a006f733..11fffeefc 100644 --- a/crates/ra_analysis/src/descriptors/function/imp.rs +++ b/crates/ra_analysis/src/descriptors/function/imp.rs @@ -1,14 +1,10 @@ use std::sync::Arc; -use ra_syntax::{ - ast::{AstNode, FnDef, FnDefNode}, -}; +use ra_syntax::ast::{AstNode, FnDef, FnDefNode}; -use crate::{ - descriptors::{ - DescriptorDatabase, - function::{FnId, FnScopes}, - }, +use crate::descriptors::{ + function::{FnId, FnScopes}, + DescriptorDatabase, }; /// Resolve `FnId` to the corresponding `SyntaxNode` diff --git a/crates/ra_analysis/src/descriptors/function/mod.rs b/crates/ra_analysis/src/descriptors/function/mod.rs index ae40f3e8f..d5db28a64 100644 --- a/crates/ra_analysis/src/descriptors/function/mod.rs +++ b/crates/ra_analysis/src/descriptors/function/mod.rs @@ -1,20 +1,16 @@ pub(super) mod imp; mod scope; -use std::cmp::{min, max}; +use std::cmp::{max, min}; use ra_syntax::{ ast::{self, AstNode, DocCommentsOwner, NameOwner}, - TextRange, TextUnit + TextRange, TextUnit, }; -use crate::{ - FileId, - syntax_ptr::SyntaxPtr -}; - -pub(crate) use self::scope::{FnScopes, resolve_local_name}; +use crate::{syntax_ptr::SyntaxPtr, FileId}; +pub(crate) use self::scope::{resolve_local_name, FnScopes}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub(crate) struct FnId(SyntaxPtr); @@ -26,14 +22,13 @@ impl FnId { } } - #[derive(Debug, Clone)] pub struct FnDescriptor { pub name: String, pub label: String, pub ret_type: Option, pub params: Vec, - pub doc: Option + pub doc: Option, } impl FnDescriptor { @@ -57,7 +52,9 @@ impl FnDescriptor { }; if let Some((comment_range, docs)) = FnDescriptor::extract_doc_comments(node) { - let comment_range = comment_range.checked_sub(node.syntax().range().start()).unwrap(); + let comment_range = comment_range + .checked_sub(node.syntax().range().start()) + .unwrap(); let start = comment_range.start().to_usize(); let end = comment_range.end().to_usize(); @@ -94,7 +91,7 @@ impl FnDescriptor { ret_type, params, label: label.trim().to_owned(), - doc + doc, }) } @@ -105,10 +102,13 @@ impl FnDescriptor { let comment_text = node.doc_comment_text(); - let (begin, end) = node.doc_comments() + let (begin, end) = node + .doc_comments() .map(|comment| comment.syntax().range()) .map(|range| (range.start().to_usize(), range.end().to_usize())) - .fold((std::usize::MAX, std::usize::MIN), |acc, range| (min(acc.0, range.0), max(acc.1, range.1))); + .fold((std::usize::MAX, std::usize::MIN), |acc, range| { + (min(acc.0, range.0), max(acc.1, range.1)) + }); let range = TextRange::from_to(TextUnit::from_usize(begin), TextUnit::from_usize(end)); @@ -134,4 +134,3 @@ impl FnDescriptor { res } } - diff --git a/crates/ra_analysis/src/descriptors/function/scope.rs b/crates/ra_analysis/src/descriptors/function/scope.rs index d9929414c..62b46ffba 100644 --- a/crates/ra_analysis/src/descriptors/function/scope.rs +++ b/crates/ra_analysis/src/descriptors/function/scope.rs @@ -51,9 +51,7 @@ impl FnScopes { &self.get(scope).entries } pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator + 'a { - generate(self.scope_for(node), move |&scope| { - self.get(scope).parent - }) + generate(self.scope_for(node), move |&scope| self.get(scope).parent) } fn root_scope(&mut self) -> ScopeId { let res = ScopeId(self.scopes.len() as u32); @@ -273,13 +271,12 @@ pub fn resolve_local_name<'a>( #[cfg(test)] mod tests { + use ra_editor::find_node_at_offset; use ra_syntax::File; use test_utils::extract_offset; - use ra_editor::{find_node_at_offset}; use super::*; - fn do_check(code: &str, expected: &[&str]) { let (off, code) = extract_offset(code); let code = { diff --git a/crates/ra_analysis/src/descriptors/mod.rs b/crates/ra_analysis/src/descriptors/mod.rs index e27f8314a..c28764336 100644 --- a/crates/ra_analysis/src/descriptors/mod.rs +++ b/crates/ra_analysis/src/descriptors/mod.rs @@ -1,24 +1,22 @@ -pub(crate) mod module; pub(crate) mod function; +pub(crate) mod module; use std::sync::Arc; use ra_syntax::{ - SmolStr, ast::{self, AstNode, FnDefNode}, - TextRange + SmolStr, TextRange, }; use crate::{ - FileId, Cancelable, db::SyntaxDatabase, - descriptors::module::{ModuleTree, ModuleId, ModuleScope}, - descriptors::function::{FnId, FnScopes, resolve_local_name}, + descriptors::function::{resolve_local_name, FnId, FnScopes}, + descriptors::module::{ModuleId, ModuleScope, ModuleTree}, input::SourceRootId, - syntax_ptr::{SyntaxPtrDatabase, LocalSyntaxPtr}, + syntax_ptr::{LocalSyntaxPtr, SyntaxPtrDatabase}, + Cancelable, FileId, }; - salsa::query_group! { pub(crate) trait DescriptorDatabase: SyntaxDatabase + SyntaxPtrDatabase { fn module_tree(source_root_id: SourceRootId) -> Cancelable> { @@ -49,23 +47,20 @@ salsa::query_group! { #[derive(Debug)] pub struct ReferenceDescriptor { pub range: TextRange, - pub name: String + pub name: String, } #[derive(Debug)] pub struct DeclarationDescriptor<'a> { pat: ast::BindPat<'a>, - pub range: TextRange + pub range: TextRange, } impl<'a> DeclarationDescriptor<'a> { pub fn new(pat: ast::BindPat) -> DeclarationDescriptor { let range = pat.syntax().range(); - DeclarationDescriptor { - pat, - range - } + DeclarationDescriptor { pat, range } } pub fn find_all_refs(&self) -> Vec { @@ -73,22 +68,22 @@ impl<'a> DeclarationDescriptor<'a> { let fn_def = match self.pat.syntax().ancestors().find_map(ast::FnDef::cast) { Some(def) => def, - None => return Default::default() + None => return Default::default(), }; let fn_scopes = FnScopes::new(fn_def); - let refs : Vec<_> = fn_def.syntax().descendants() + let refs: Vec<_> = fn_def + .syntax() + .descendants() .filter_map(ast::NameRef::cast) - .filter(|name_ref| { - match resolve_local_name(*name_ref, &fn_scopes) { - None => false, - Some(entry) => entry.ptr() == name_ptr, - } + .filter(|name_ref| match resolve_local_name(*name_ref, &fn_scopes) { + None => false, + Some(entry) => entry.ptr() == name_ptr, }) .map(|name_ref| ReferenceDescriptor { name: name_ref.syntax().text().to_string(), - range : name_ref.syntax().range(), + range: name_ref.syntax().range(), }) .collect(); diff --git a/crates/ra_analysis/src/descriptors/module/imp.rs b/crates/ra_analysis/src/descriptors/module/imp.rs index dae3a356d..1c102f4e5 100644 --- a/crates/ra_analysis/src/descriptors/module/imp.rs +++ b/crates/ra_analysis/src/descriptors/module/imp.rs @@ -1,24 +1,25 @@ use std::sync::Arc; -use relative_path::RelativePathBuf; -use rustc_hash::{FxHashMap, FxHashSet}; use ra_syntax::{ - SmolStr, ast::{self, NameOwner}, + SmolStr, }; +use relative_path::RelativePathBuf; +use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ - FileId, Cancelable, FileResolverImp, db, - input::{SourceRoot, SourceRootId}, + db, descriptors::DescriptorDatabase, + input::{SourceRoot, SourceRootId}, + Cancelable, FileId, FileResolverImp, }; -use super::{ - ModuleData, ModuleTree, ModuleId, LinkId, LinkData, Problem, ModuleScope -}; - +use super::{LinkData, LinkId, ModuleData, ModuleId, ModuleScope, ModuleTree, Problem}; -pub(crate) fn submodules(db: &impl DescriptorDatabase, file_id: FileId) -> Cancelable>> { +pub(crate) fn submodules( + db: &impl DescriptorDatabase, + file_id: FileId, +) -> Cancelable>> { db::check_canceled(db)?; let file = db.file_syntax(file_id); let root = file.ast(); @@ -57,13 +58,11 @@ pub(crate) fn module_tree( Ok(Arc::new(res)) } - #[derive(Clone, Hash, PartialEq, Eq, Debug)] pub struct Submodule { pub name: SmolStr, } - fn create_module_tree<'a>( db: &impl DescriptorDatabase, source_root: SourceRootId, @@ -82,7 +81,15 @@ fn create_module_tree<'a>( continue; // TODO: use explicit crate_roots here } assert!(!roots.contains_key(&file_id)); - let module_id = build_subtree(db, &source_root, &mut tree, &mut visited, &mut roots, None, file_id)?; + let module_id = build_subtree( + db, + &source_root, + &mut tree, + &mut visited, + &mut roots, + None, + file_id, + )?; roots.insert(file_id, module_id); } Ok(tree) diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 667553f74..302e3e81c 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs @@ -1,8 +1,11 @@ pub(super) mod imp; pub(crate) mod scope; +use ra_syntax::{ + ast::{self, AstNode, NameOwner}, + SmolStr, SyntaxNode, +}; use relative_path::RelativePathBuf; -use ra_syntax::{ast::{self, NameOwner, AstNode}, SmolStr, SyntaxNode}; use crate::FileId; @@ -16,9 +19,11 @@ pub(crate) struct ModuleTree { impl ModuleTree { pub(crate) fn modules_for_file(&self, file_id: FileId) -> Vec { - self.mods.iter() + self.mods + .iter() .enumerate() - .filter(|(_idx, it)| it.file_id == file_id).map(|(idx, _)| ModuleId(idx as u32)) + .filter(|(_idx, it)| it.file_id == file_id) + .map(|(idx, _)| ModuleId(idx as u32)) .collect() } @@ -50,7 +55,7 @@ impl ModuleId { } pub(crate) fn parent_link(self, tree: &ModuleTree) -> Option { tree.module(self).parent - } + } pub(crate) fn parent(self, tree: &ModuleTree) -> Option { let link = self.parent_link(tree)?; Some(tree.link(link).owner) @@ -69,18 +74,15 @@ impl ModuleId { curr } pub(crate) fn child(self, tree: &ModuleTree, name: &str) -> Option { - let link = tree.module(self) + let link = tree + .module(self) .children .iter() .map(|&it| tree.link(it)) .find(|it| it.name == name)?; Some(*link.points_to.first()?) } - pub(crate) fn problems( - self, - tree: &ModuleTree, - root: ast::Root, - ) -> Vec<(SyntaxNode, Problem)> { + pub(crate) fn problems(self, tree: &ModuleTree, root: ast::Root) -> Vec<(SyntaxNode, Problem)> { tree.module(self) .children .iter() @@ -98,11 +100,7 @@ impl LinkId { pub(crate) fn owner(self, tree: &ModuleTree) -> ModuleId { tree.link(self).owner } - pub(crate) fn bind_source<'a>( - self, - tree: &ModuleTree, - root: ast::Root<'a>, - ) -> ast::Module<'a> { + pub(crate) fn bind_source<'a>(self, tree: &ModuleTree, root: ast::Root<'a>) -> ast::Module<'a> { imp::modules(root) .find(|(name, _)| name == &tree.link(self).name) .unwrap() @@ -125,7 +123,6 @@ struct LinkData { problem: Option, } - impl ModuleTree { fn module(&self, id: ModuleId) -> &ModuleData { &self.mods[id.0 as usize] @@ -152,4 +149,3 @@ impl ModuleTree { id } } - diff --git a/crates/ra_analysis/src/descriptors/module/scope.rs b/crates/ra_analysis/src/descriptors/module/scope.rs index 846b8b44f..681e272c2 100644 --- a/crates/ra_analysis/src/descriptors/module/scope.rs +++ b/crates/ra_analysis/src/descriptors/module/scope.rs @@ -1,9 +1,8 @@ //! Backend for module-level scope resolution & completion - use ra_syntax::{ ast::{self, ModuleItemOwner}, - File, AstNode, SmolStr, + AstNode, File, SmolStr, }; use crate::syntax_ptr::LocalSyntaxPtr; @@ -103,7 +102,7 @@ fn collect_imports(tree: ast::UseTree, acc: &mut Vec) { #[cfg(test)] mod tests { use super::*; - use ra_syntax::{File}; + use ra_syntax::File; fn do_check(code: &str, expected: &[&str]) { let file = File::parse(&code); -- cgit v1.2.3