diff --git a/crates/gen_lsp_server/examples/01_gen_lsp_server.rs b/crates/gen_lsp_server/examples/01_gen_lsp_server.rs index bc497f74a1e..f4996506497 100644 --- a/crates/gen_lsp_server/examples/01_gen_lsp_server.rs +++ b/crates/gen_lsp_server/examples/01_gen_lsp_server.rs @@ -1,11 +1,11 @@ use std::error::Error; -use crossbeam_channel::{Sender, Receiver}; +use crossbeam_channel::{Receiver, Sender}; +use gen_lsp_server::{handle_shutdown, run_server, stdio_transport, RawMessage, RawResponse}; use lsp_types::{ - ServerCapabilities, InitializeParams, request::{GotoDefinition, GotoDefinitionResponse}, + InitializeParams, ServerCapabilities, }; -use gen_lsp_server::{run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse}; fn main() -> Result<(), Box> { let (receiver, sender, io_threads) = stdio_transport(); diff --git a/crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs b/crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs index 1a6174462cf..3c48106c5f6 100644 --- a/crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs +++ b/crates/gen_lsp_server/examples/02_gen_lsp_server_with_logging.rs @@ -44,14 +44,14 @@ use std::error::Error; -use crossbeam_channel::{Sender, Receiver}; -use lsp_types::{ - ServerCapabilities, InitializeParams, - request::{GotoDefinition, GotoDefinitionResponse}, +use crossbeam_channel::{Receiver, Sender}; +use gen_lsp_server::{ + handle_shutdown, run_server, stdio_transport, RawMessage, RawRequest, RawResponse, }; use log::info; -use gen_lsp_server::{ - run_server, stdio_transport, handle_shutdown, RawMessage, RawResponse, RawRequest, +use lsp_types::{ + request::{GotoDefinition, GotoDefinitionResponse}, + InitializeParams, ServerCapabilities, }; fn main() -> Result<(), Box> { diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs index 26641e69035..3b7cb77b181 100644 --- a/crates/ra_arena/src/lib.rs +++ b/crates/ra_arena/src/lib.rs @@ -2,9 +2,9 @@ use std::{ fmt, + iter::FromIterator, marker::PhantomData, ops::{Index, IndexMut}, - iter::FromIterator, }; pub mod map; diff --git a/crates/ra_assists/src/add_derive.rs b/crates/ra_assists/src/add_derive.rs index 0c4cf261507..bf7d55d6d11 100644 --- a/crates/ra_assists/src/add_derive.rs +++ b/crates/ra_assists/src/add_derive.rs @@ -1,11 +1,11 @@ use hir::db::HirDatabase; use ra_syntax::{ ast::{self, AstNode, AttrsOwner}, - SyntaxKind::{WHITESPACE, COMMENT}, + SyntaxKind::{COMMENT, WHITESPACE}, TextUnit, }; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; pub(crate) fn add_derive(mut ctx: AssistCtx) -> Option { let nominal = ctx.node_at_offset::()?; diff --git a/crates/ra_assists/src/add_explicit_type.rs b/crates/ra_assists/src/add_explicit_type.rs index f3ed74b7fb2..bb47a32f0a0 100644 --- a/crates/ra_assists/src/add_explicit_type.rs +++ b/crates/ra_assists/src/add_explicit_type.rs @@ -1,13 +1,10 @@ -use hir::{ - HirDisplay, Ty, - db::HirDatabase, -}; +use hir::{db::HirDatabase, HirDisplay, Ty}; use ra_syntax::{ + ast::{AstNode, LetStmt, NameOwner, PatKind}, T, - ast::{LetStmt, PatKind, NameOwner, AstNode} }; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; /// Add explicit type assist. pub(crate) fn add_explicit_type(mut ctx: AssistCtx) -> Option { @@ -56,7 +53,7 @@ fn is_unknown(ty: &Ty) -> bool { mod tests { use super::*; - use crate::helpers::{ check_assist, check_assist_target, check_assist_not_applicable }; + use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; #[test] fn add_explicit_type_target() { diff --git a/crates/ra_assists/src/add_impl.rs b/crates/ra_assists/src/add_impl.rs index fa1c8589064..b81922c1d29 100644 --- a/crates/ra_assists/src/add_impl.rs +++ b/crates/ra_assists/src/add_impl.rs @@ -1,11 +1,11 @@ -use join_to_string::join; use hir::db::HirDatabase; +use join_to_string::join; use ra_syntax::{ ast::{self, AstNode, NameOwner, TypeParamsOwner}, TextUnit, }; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; pub(crate) fn add_impl(mut ctx: AssistCtx) -> Option { let nominal = ctx.node_at_offset::()?; diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs index 0c903a56325..7fc8f63b3ef 100644 --- a/crates/ra_assists/src/add_missing_impl_members.rs +++ b/crates/ra_assists/src/add_missing_impl_members.rs @@ -1,9 +1,12 @@ -use crate::{Assist, AssistId, AssistCtx, ast_editor::{AstEditor, AstBuilder}}; +use crate::{ + ast_editor::{AstBuilder, AstEditor}, + Assist, AssistCtx, AssistId, +}; -use hir::{HasSource, db::HirDatabase}; -use ra_syntax::{SmolStr, TreeArc}; -use ra_syntax::ast::{self, AstNode, ImplItem, ImplItemKind, NameOwner}; +use hir::{db::HirDatabase, HasSource}; use ra_db::FilePosition; +use ra_syntax::ast::{self, AstNode, ImplItem, ImplItemKind, NameOwner}; +use ra_syntax::{SmolStr, TreeArc}; #[derive(PartialEq)] enum AddMissingImplMembersMode { diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 1d58d9e7104..0ba5f3ae671 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs @@ -1,13 +1,13 @@ use hir::db::HirDatabase; -use ra_text_edit::TextEditBuilder; use ra_db::FileRange; -use ra_syntax::{ - SourceFile, TextRange, AstNode, TextUnit, SyntaxNode, SyntaxElement, SyntaxToken, - algo::{find_token_at_offset, find_node_at_offset, find_covering_element, TokenAtOffset}, -}; use ra_fmt::{leading_indent, reindent}; +use ra_syntax::{ + algo::{find_covering_element, find_node_at_offset, find_token_at_offset, TokenAtOffset}, + AstNode, SourceFile, SyntaxElement, SyntaxNode, SyntaxToken, TextRange, TextUnit, +}; +use ra_text_edit::TextEditBuilder; -use crate::{AssistLabel, AssistAction, AssistId}; +use crate::{AssistAction, AssistId, AssistLabel}; #[derive(Clone, Debug)] pub(crate) enum Assist { diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index 5f8ba3df666..c9a5cf8d944 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs @@ -1,10 +1,12 @@ use std::{iter, ops::RangeInclusive}; use arrayvec::ArrayVec; -use ra_text_edit::TextEditBuilder; -use ra_syntax::{AstNode, TreeArc, ast, SyntaxKind::*, SyntaxElement, SourceFile, InsertPosition, Direction, T}; -use ra_fmt::leading_indent; use hir::Name; +use ra_fmt::leading_indent; +use ra_syntax::{ + ast, AstNode, Direction, InsertPosition, SourceFile, SyntaxElement, SyntaxKind::*, TreeArc, T, +}; +use ra_text_edit::TextEditBuilder; pub struct AstEditor { original_ast: TreeArc, @@ -283,7 +285,7 @@ fn ast_node_from_file_text(text: &str) -> TreeArc { mod tokens { use once_cell::sync::Lazy; - use ra_syntax::{AstNode, SourceFile, TreeArc, SyntaxToken, SyntaxKind::*, T}; + use ra_syntax::{AstNode, SourceFile, SyntaxKind::*, SyntaxToken, TreeArc, T}; static SOURCE_FILE: Lazy> = Lazy::new(|| SourceFile::parse(",\n; ;").tree); diff --git a/crates/ra_assists/src/auto_import.rs b/crates/ra_assists/src/auto_import.rs index 9617beb5c55..75ab8fa0f81 100644 --- a/crates/ra_assists/src/auto_import.rs +++ b/crates/ra_assists/src/auto_import.rs @@ -1,14 +1,15 @@ +use hir::{self, db::HirDatabase}; use ra_text_edit::TextEditBuilder; -use hir::{ self, db::HirDatabase}; -use ra_syntax::{ - T, - ast::{ self, NameOwner }, AstNode, SyntaxNode, Direction, TextRange, SmolStr, - SyntaxKind::{ PATH, PATH_SEGMENT } -}; use crate::{ + assist_ctx::{Assist, AssistCtx}, AssistId, - assist_ctx::{AssistCtx, Assist}, +}; +use ra_syntax::{ + ast::{self, NameOwner}, + AstNode, Direction, SmolStr, + SyntaxKind::{PATH, PATH_SEGMENT}, + SyntaxNode, TextRange, T, }; fn collect_path_segments_raw<'a>( @@ -577,7 +578,7 @@ pub(crate) fn auto_import(mut ctx: AssistCtx) -> Option) -> Option { if let Some(vis) = ctx.node_at_offset::() { diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index 71b101b4033..d51010b8464 100644 --- a/crates/ra_assists/src/fill_match_arms.rs +++ b/crates/ra_assists/src/fill_match_arms.rs @@ -1,13 +1,10 @@ -use std::fmt::Write; use itertools::Itertools; +use std::fmt::Write; -use hir::{ - AdtDef, FieldSource, HasSource, - db::HirDatabase, -}; +use hir::{db::HirDatabase, AdtDef, FieldSource, HasSource}; use ra_syntax::ast::{self, AstNode}; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; fn is_trivial_arm(arm: &ast::MatchArm) -> bool { fn single_pattern(arm: &ast::MatchArm) -> Option { diff --git a/crates/ra_assists/src/flip_binexpr.rs b/crates/ra_assists/src/flip_binexpr.rs index 02d27f66d19..5e41f93461c 100644 --- a/crates/ra_assists/src/flip_binexpr.rs +++ b/crates/ra_assists/src/flip_binexpr.rs @@ -1,7 +1,7 @@ use hir::db::HirDatabase; use ra_syntax::ast::{AstNode, BinExpr, BinOp}; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; /// Flip binary expression assist. pub(crate) fn flip_binexpr(mut ctx: AssistCtx) -> Option { @@ -68,7 +68,7 @@ impl From for FlipAction { mod tests { use super::*; - use crate::helpers::{ check_assist, check_assist_target, check_assist_not_applicable }; + use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; #[test] fn flip_binexpr_target_is_the_op() { diff --git a/crates/ra_assists/src/flip_comma.rs b/crates/ra_assists/src/flip_comma.rs index 7626ffad323..d8dba779f67 100644 --- a/crates/ra_assists/src/flip_comma.rs +++ b/crates/ra_assists/src/flip_comma.rs @@ -1,11 +1,7 @@ use hir::db::HirDatabase; -use ra_syntax::{ - T, - Direction, - algo::non_trivia_sibling, -}; +use ra_syntax::{algo::non_trivia_sibling, Direction, T}; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; pub(crate) fn flip_comma(mut ctx: AssistCtx) -> Option { let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == T![,])?; diff --git a/crates/ra_assists/src/inline_local_variable.rs b/crates/ra_assists/src/inline_local_variable.rs index e0479ef1307..554de8b4677 100644 --- a/crates/ra_assists/src/inline_local_variable.rs +++ b/crates/ra_assists/src/inline_local_variable.rs @@ -1,11 +1,11 @@ use hir::db::HirDatabase; use ra_syntax::{ - ast::{self, AstNode, AstToken, PatKind, ExprKind}, + ast::{self, AstNode, AstToken, ExprKind, PatKind}, TextRange, }; -use crate::{Assist, AssistCtx, AssistId}; use crate::assist_ctx::AssistBuilder; +use crate::{Assist, AssistCtx, AssistId}; pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx) -> Option { let let_stmt = ctx.node_at_offset::()?; diff --git a/crates/ra_assists/src/introduce_variable.rs b/crates/ra_assists/src/introduce_variable.rs index 28467d3413b..f7f5ccafa59 100644 --- a/crates/ra_assists/src/introduce_variable.rs +++ b/crates/ra_assists/src/introduce_variable.rs @@ -1,12 +1,14 @@ -use test_utils::tested_by; use hir::db::HirDatabase; use ra_syntax::{ ast::{self, AstNode}, + SyntaxKind::{ + BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR, WHITESPACE, + }, SyntaxNode, TextUnit, - SyntaxKind::{WHITESPACE, MATCH_ARM, LAMBDA_EXPR, PATH_EXPR, BREAK_EXPR, LOOP_EXPR, RETURN_EXPR, COMMENT}, }; +use test_utils::tested_by; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; pub(crate) fn introduce_variable(mut ctx: AssistCtx) -> Option { if ctx.frange.range.is_empty() { @@ -121,7 +123,9 @@ fn anchor_stmt(expr: &ast::Expr) -> Option<(&SyntaxNode, bool)> { mod tests { use test_utils::covers; - use crate::helpers::{check_assist_range_not_applicable, check_assist_range, check_assist_range_target}; + use crate::helpers::{ + check_assist_range, check_assist_range_not_applicable, check_assist_range_target, + }; use super::*; diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 28eb0226b78..0d848629d93 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -11,12 +11,12 @@ pub mod ast_editor; use itertools::Itertools; -use ra_text_edit::TextEdit; -use ra_syntax::{TextRange, TextUnit}; -use ra_db::FileRange; use hir::db::HirDatabase; +use ra_db::FileRange; +use ra_syntax::{TextRange, TextUnit}; +use ra_text_edit::TextEdit; -pub(crate) use crate::assist_ctx::{AssistCtx, Assist}; +pub(crate) use crate::assist_ctx::{Assist, AssistCtx}; /// Unique identifier of the assist, should not be shown to the user /// directly. @@ -127,11 +127,11 @@ fn all_assists() -> &'static [fn(AssistCtx) -> Option) -> Option, @@ -289,8 +289,8 @@ mod helpers { #[cfg(test)] mod tests { use hir::mock::MockDatabase; - use ra_syntax::TextRange; use ra_db::FileRange; + use ra_syntax::TextRange; use test_utils::{extract_offset, extract_range}; #[test] diff --git a/crates/ra_assists/src/move_guard.rs b/crates/ra_assists/src/move_guard.rs index 22ba91fb771..e1ce86a33ef 100644 --- a/crates/ra_assists/src/move_guard.rs +++ b/crates/ra_assists/src/move_guard.rs @@ -1,12 +1,11 @@ use hir::db::HirDatabase; use ra_syntax::{ - TextUnit, - SyntaxElement, - ast::{MatchArm, AstNode, AstToken, IfExpr}, ast, + ast::{AstNode, AstToken, IfExpr, MatchArm}, + SyntaxElement, TextUnit, }; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx) -> Option { let match_arm = ctx.node_at_offset::()?; @@ -84,7 +83,7 @@ pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx) mod tests { use super::*; - use crate::helpers::{ check_assist, check_assist_target, check_assist_not_applicable }; + use crate::helpers::{check_assist, check_assist_not_applicable, check_assist_target}; #[test] fn move_guard_to_arm_body_target() { diff --git a/crates/ra_assists/src/remove_dbg.rs b/crates/ra_assists/src/remove_dbg.rs index 6e900f8ef03..5680f76ca51 100644 --- a/crates/ra_assists/src/remove_dbg.rs +++ b/crates/ra_assists/src/remove_dbg.rs @@ -1,10 +1,9 @@ +use crate::{Assist, AssistCtx, AssistId}; use hir::db::HirDatabase; use ra_syntax::{ ast::{self, AstNode}, - TextUnit, - T + TextUnit, T, }; -use crate::{AssistCtx, Assist, AssistId}; pub(crate) fn remove_dbg(mut ctx: AssistCtx) -> Option { let macro_call = ctx.node_at_offset::()?; diff --git a/crates/ra_assists/src/replace_if_let_with_match.rs b/crates/ra_assists/src/replace_if_let_with_match.rs index 2b451f08d6d..c2c7cf70b85 100644 --- a/crates/ra_assists/src/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/replace_if_let_with_match.rs @@ -1,8 +1,8 @@ -use ra_syntax::{AstNode, ast}; -use ra_fmt::extract_trivial_expression; use hir::db::HirDatabase; +use ra_fmt::extract_trivial_expression; +use ra_syntax::{ast, AstNode}; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx) -> Option { let if_expr: &ast::IfExpr = ctx.node_at_offset()?; diff --git a/crates/ra_assists/src/split_import.rs b/crates/ra_assists/src/split_import.rs index 881c5ecdc10..a8feb67c8c9 100644 --- a/crates/ra_assists/src/split_import.rs +++ b/crates/ra_assists/src/split_import.rs @@ -1,13 +1,9 @@ use std::iter::successors; use hir::db::HirDatabase; -use ra_syntax::{ - T, - TextUnit, AstNode, - ast, -}; +use ra_syntax::{ast, AstNode, TextUnit, T}; -use crate::{AssistCtx, Assist, AssistId}; +use crate::{Assist, AssistCtx, AssistId}; pub(crate) fn split_import(mut ctx: AssistCtx) -> Option { let colon_colon = ctx.token_at_offset().find(|leaf| leaf.kind() == T![::])?; diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index 43d3fb7e3af..c25737aaa8e 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs @@ -1,14 +1,12 @@ mod vfs_filter; -use std::{path::Path, collections::HashSet, error::Error}; +use std::{collections::HashSet, error::Error, path::Path}; use rustc_hash::FxHashMap; -use ra_db::{ - CrateGraph, FileId, SourceRootId, -}; -use ra_ide_api::{AnalysisHost, AnalysisChange}; -use ra_project_model::{ProjectWorkspace, ProjectRoot}; +use ra_db::{CrateGraph, FileId, SourceRootId}; +use ra_ide_api::{AnalysisChange, AnalysisHost}; +use ra_project_model::{ProjectRoot, ProjectWorkspace}; use ra_vfs::{Vfs, VfsChange}; use vfs_filter::IncludeRustFiles; @@ -106,8 +104,8 @@ pub fn load( #[cfg(test)] mod tests { - use ra_hir::Crate; use super::*; + use ra_hir::Crate; #[test] fn test_loading_rust_analyzer() { diff --git a/crates/ra_batch/src/vfs_filter.rs b/crates/ra_batch/src/vfs_filter.rs index 8552ac999ca..2f0d8cb8b71 100644 --- a/crates/ra_batch/src/vfs_filter.rs +++ b/crates/ra_batch/src/vfs_filter.rs @@ -1,6 +1,6 @@ -use std::path::PathBuf; use ra_project_model::ProjectRoot; -use ra_vfs::{RootEntry, Filter, RelativePath}; +use ra_vfs::{Filter, RelativePath, RootEntry}; +use std::path::PathBuf; /// `IncludeRustFiles` is used to convert /// from `ProjectRoot` to `RootEntry` for VFS diff --git a/crates/ra_cli/src/analysis_bench.rs b/crates/ra_cli/src/analysis_bench.rs index 33d47283877..639ac763eef 100644 --- a/crates/ra_cli/src/analysis_bench.rs +++ b/crates/ra_cli/src/analysis_bench.rs @@ -1,10 +1,10 @@ use std::{ - path::{PathBuf, Path}, + path::{Path, PathBuf}, time::Instant, }; -use ra_db::{SourceDatabase, salsa::Database}; -use ra_ide_api::{AnalysisHost, Analysis, LineCol, FilePosition}; +use ra_db::{salsa::Database, SourceDatabase}; +use ra_ide_api::{Analysis, AnalysisHost, FilePosition, LineCol}; use crate::Result; diff --git a/crates/ra_cli/src/analysis_stats.rs b/crates/ra_cli/src/analysis_stats.rs index a01c07c3fc8..b8ad6aebcb1 100644 --- a/crates/ra_cli/src/analysis_stats.rs +++ b/crates/ra_cli/src/analysis_stats.rs @@ -1,7 +1,7 @@ -use std::{collections::HashSet, time::Instant, fmt::Write, path::Path}; +use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; use ra_db::SourceDatabase; -use ra_hir::{Crate, ModuleDef, Ty, ImplItem, HasSource}; +use ra_hir::{Crate, HasSource, ImplItem, ModuleDef, Ty}; use ra_syntax::AstNode; use crate::Result; diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index d2f6544f8d4..25edbd5f735 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -1,13 +1,13 @@ mod analysis_stats; mod analysis_bench; -use std::{io::Read, error::Error}; +use std::{error::Error, io::Read}; use clap::{App, Arg, SubCommand}; -use ra_ide_api::{file_structure, Analysis}; -use ra_syntax::{SourceFile, TreeArc, AstNode}; use flexi_logger::Logger; +use ra_ide_api::{file_structure, Analysis}; use ra_prof::profile; +use ra_syntax::{AstNode, SourceFile, TreeArc}; type Result = std::result::Result>; diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index c103503bd55..5d3a6b3c989 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -197,7 +197,7 @@ impl CrateGraph { #[cfg(test)] mod tests { - use super::{CrateGraph, FileId, SmolStr, Edition::Edition2018}; + use super::{CrateGraph, Edition::Edition2018, FileId, SmolStr}; #[test] fn it_should_panic_because_of_cycle_dependencies() { diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index f08616100d9..11e18a03d32 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -4,17 +4,15 @@ mod input; use std::{panic, sync::Arc}; -use ra_syntax::{TextUnit, TextRange, SourceFile, Parse}; -use relative_path::RelativePathBuf; use ra_prof::profile; +use ra_syntax::{Parse, SourceFile, TextRange, TextUnit}; +use relative_path::RelativePathBuf; -pub use ::salsa as salsa; pub use crate::{ cancellation::Canceled, - input::{ - FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency, Edition, - }, + input::{CrateGraph, CrateId, Dependency, Edition, FileId, SourceRoot, SourceRootId}, }; +pub use ::salsa; pub trait CheckCanceled { /// Aborts current query if there are pending changes. diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs index aac5a1d235c..1c2c04ad2f0 100644 --- a/crates/ra_fmt/src/lib.rs +++ b/crates/ra_fmt/src/lib.rs @@ -1,11 +1,13 @@ //! This crate provides some utilities for indenting rust code. //! -use std::iter::successors; use itertools::Itertools; use ra_syntax::{ - SyntaxNode, SyntaxKind::*, SyntaxToken, SyntaxKind, T, ast::{self, AstNode, AstToken}, + SyntaxKind, + SyntaxKind::*, + SyntaxNode, SyntaxToken, T, }; +use std::iter::successors; pub fn reindent(text: &str, indent: &str) -> String { let indent = format!("\n{}", indent); diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index b3843b35c2a..9c0c8fdd0a4 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -3,16 +3,15 @@ use std::sync::Arc; -use ra_arena::{RawId, Arena, impl_arena_id}; +use ra_arena::{impl_arena_id, Arena, RawId}; use ra_syntax::{ + ast::{self, NameOwner, StructKind, TypeAscriptionOwner}, TreeArc, - ast::{self, NameOwner, StructKind, TypeAscriptionOwner} }; use crate::{ - Name, AsName, Struct, Union, Enum, EnumVariant, Crate, AstDatabase, - HirDatabase, StructField, FieldSource, Source, HasSource, - type_ref::TypeRef, DefDatabase, + type_ref::TypeRef, AsName, AstDatabase, Crate, DefDatabase, Enum, EnumVariant, FieldSource, + HasSource, HirDatabase, Name, Source, Struct, StructField, Union, }; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 75914ccb07e..ed640d7fce8 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -3,24 +3,32 @@ pub(crate) mod docs; use std::sync::Arc; -use ra_db::{CrateId, SourceRootId, Edition, FileId}; -use ra_syntax::{ast::{self, NameOwner, TypeAscriptionOwner}, TreeArc}; +use ra_db::{CrateId, Edition, FileId, SourceRootId}; +use ra_syntax::{ + ast::{self, NameOwner, TypeAscriptionOwner}, + TreeArc, +}; use crate::{ - Name, AsName, AstId, Ty, Either, KnownName, HasSource, - HirDatabase, DefDatabase, AstDatabase, - type_ref::TypeRef, - nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, - expr::{Body, BodySourceMap, validation::ExprValidator}, - ty::{TraitRef, InferenceResult, primitive::{IntTy, FloatTy, Signedness, IntBitness, FloatBitness}}, adt::{EnumVariantId, StructFieldId, VariantDef}, + diagnostics::DiagnosticSink, + expr::{validation::ExprValidator, Body, BodySourceMap}, generics::HasGenericParams, - ids::{FunctionId, StructId, EnumId, AstItemDef, ConstId, StaticId, TraitId, TypeAliasId, MacroDefId}, + ids::{ + AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, + TypeAliasId, + }, impl_block::ImplBlock, + nameres::{CrateModuleId, ImportId, ModuleScope, Namespace}, resolve::Resolver, - diagnostics::{DiagnosticSink}, - traits::{TraitItem, TraitData}, + traits::{TraitData, TraitItem}, + ty::{ + primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, + InferenceResult, TraitRef, + }, type_ref::Mutability, + type_ref::TypeRef, + AsName, AstDatabase, AstId, DefDatabase, Either, HasSource, HirDatabase, KnownName, Name, Ty, }; /// hir::Crate describes a single crate. It's the main interface with which diff --git a/crates/ra_hir/src/code_model/docs.rs b/crates/ra_hir/src/code_model/docs.rs index da2b9b85479..f696307a7c0 100644 --- a/crates/ra_hir/src/code_model/docs.rs +++ b/crates/ra_hir/src/code_model/docs.rs @@ -3,8 +3,8 @@ use std::sync::Arc; use ra_syntax::ast; use crate::{ - HirDatabase, DefDatabase, AstDatabase, HasSource, - Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource, MacroDef, + AstDatabase, Const, DefDatabase, Enum, EnumVariant, FieldSource, Function, HasSource, + HirDatabase, MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, Union, }; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 5785d3b266f..72451e0e70a 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -1,9 +1,9 @@ -use ra_syntax::{TreeArc, ast}; +use ra_syntax::{ast, TreeArc}; use crate::{ - HirFileId, DefDatabase, AstDatabase, Module, ModuleSource, - StructField, Struct, Enum, Union, EnumVariant, Function, Static, Trait, Const, TypeAlias, - FieldSource, MacroDef, ids::AstItemDef, + ids::AstItemDef, AstDatabase, Const, DefDatabase, Enum, EnumVariant, FieldSource, Function, + HirFileId, MacroDef, Module, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, + Union, }; pub struct Source { diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index eda22c0b09e..a9c6c52d9d8 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -1,23 +1,25 @@ use std::sync::Arc; use parking_lot::Mutex; -use ra_syntax::{SyntaxNode, TreeArc, SmolStr, ast}; -use ra_db::{SourceDatabase, salsa}; +use ra_db::{salsa, SourceDatabase}; +use ra_syntax::{ast, SmolStr, SyntaxNode, TreeArc}; use crate::{ - HirFileId, MacroDefId, AstIdMap, ErasedFileAstId, Crate, Module, MacroCallLoc, - Function, FnData, ExprScopes, TypeAlias, - Struct, Enum, StructField, - Const, ConstData, Static, - DefWithBody, Trait, + adt::{EnumData, StructData}, + generics::{GenericDef, GenericParams}, ids, - nameres::{Namespace, ImportSourceMap, RawItems, CrateDefMap}, - ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks, TypableDef, CallableDef, FnSig, TypeCtor, GenericPredicate, Substs}, - adt::{StructData, EnumData}, - impl_block::{ModuleImplBlocks, ImplSourceMap, ImplBlock}, - generics::{GenericParams, GenericDef}, + impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks}, + lang_item::{LangItemTarget, LangItems}, + nameres::{CrateDefMap, ImportSourceMap, Namespace, RawItems}, traits::TraitData, - lang_item::{LangItems, LangItemTarget}, type_alias::TypeAliasData, + ty::{ + method_resolution::CrateImplBlocks, CallableDef, FnSig, GenericPredicate, InferenceResult, + Substs, Ty, TypableDef, TypeCtor, + }, + type_alias::TypeAliasData, + AstIdMap, Const, ConstData, Crate, DefWithBody, Enum, ErasedFileAstId, ExprScopes, FnData, + Function, HirFileId, MacroCallLoc, MacroDefId, Module, Static, Struct, StructField, Trait, + TypeAlias, }; /// We store all interned things in the single QueryGroup. diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index 2557ef18e36..f5f2e65f39b 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs @@ -1,9 +1,9 @@ -use std::{fmt, any::Any}; +use std::{any::Any, fmt}; -use ra_syntax::{SyntaxNodePtr, TreeArc, AstPtr, TextRange, ast, SyntaxNode}; +use ra_syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr, TextRange, TreeArc}; use relative_path::RelativePathBuf; -use crate::{HirFileId, HirDatabase, Name}; +use crate::{HirDatabase, HirFileId, Name}; /// Diagnostic defines hir API for errors and warnings. /// diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index b1973d19d4d..d5b4ba6b6f1 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -3,19 +3,25 @@ use std::sync::Arc; use rustc_hash::FxHashMap; -use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; +use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_syntax::{ - SyntaxNodePtr, AstPtr, AstNode, - ast::{self, TryBlockBodyOwner, LoopBodyOwner, ArgListOwner, NameOwner, LiteralKind,ArrayExprKind, TypeAscriptionOwner}, + ast::{ + self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, + TryBlockBodyOwner, TypeAscriptionOwner, + }, + AstNode, AstPtr, SyntaxNodePtr, }; use crate::{ - Path, Name, HirDatabase, Resolver,DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, - HasSource, name::AsName, type_ref::{Mutability, TypeRef}, + DefWithBody, Either, HasSource, HirDatabase, HirFileId, MacroCallLoc, MacroFileKind, Name, + Path, Resolver, +}; +use crate::{ + path::GenericArgs, + ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, }; -use crate::{path::GenericArgs, ty::primitive::{IntTy, UncertainIntTy, FloatTy, UncertainFloatTy}}; pub use self::scope::ExprScopes; @@ -249,8 +255,8 @@ pub enum Expr { Literal(Literal), } -pub use ra_syntax::ast::PrefixOp as UnaryOp; pub use ra_syntax::ast::BinOp as BinaryOp; +pub use ra_syntax::ast::PrefixOp as UnaryOp; #[derive(Debug, Clone, Eq, PartialEq)] pub enum Array { ElementList(Vec), diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 83d226fc15e..f27cc6e8d24 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -1,12 +1,11 @@ use std::sync::Arc; +use ra_arena::{impl_arena_id, Arena, RawId}; use rustc_hash::FxHashMap; -use ra_arena::{Arena, RawId, impl_arena_id}; use crate::{ - Name, DefWithBody, - expr::{PatId, ExprId, Pat, Expr, Body, Statement}, - HirDatabase, + expr::{Body, Expr, ExprId, Pat, PatId, Statement}, + DefWithBody, HirDatabase, Name, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -173,10 +172,10 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope #[cfg(test)] mod tests { use ra_db::SourceDatabase; - use ra_syntax::{algo::find_node_at_offset, AstNode, SyntaxNodePtr, ast}; - use test_utils::{extract_offset, assert_eq_text}; + use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNodePtr}; + use test_utils::{assert_eq_text, extract_offset}; - use crate::{source_binder::SourceAnalyzer, mock::MockDatabase}; + use crate::{mock::MockDatabase, source_binder::SourceAnalyzer}; fn do_check(code: &str, expected: &[&str]) { let (off, code) = extract_offset(code); diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index 534fd482b4b..8206dae2e1e 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs @@ -1,17 +1,16 @@ -use std::sync::Arc; use rustc_hash::FxHashSet; +use std::sync::Arc; use ra_syntax::ast::{AstNode, StructLit}; +use super::{Expr, ExprId, StructLitField}; use crate::{ - expr::AstPtr, - HirDatabase, Function, Name, HasSource, - diagnostics::{DiagnosticSink, MissingFields}, adt::AdtDef, - Path, + diagnostics::{DiagnosticSink, MissingFields}, + expr::AstPtr, ty::InferenceResult, + Function, HasSource, HirDatabase, Name, Path, }; -use super::{Expr, StructLitField, ExprId}; pub(crate) struct ExprValidator<'a, 'b: 'a> { func: Function, diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs index 462b136b7fe..9929331d332 100644 --- a/crates/ra_hir/src/generics.rs +++ b/crates/ra_hir/src/generics.rs @@ -5,13 +5,14 @@ use std::sync::Arc; -use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner}; +use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; use crate::{ - HasSource, - Name, AsName, Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, Container, AdtDef, - db::{HirDatabase, DefDatabase, AstDatabase}, - path::Path, type_ref::TypeRef, + db::{AstDatabase, DefDatabase, HirDatabase}, + path::Path, + type_ref::TypeRef, + AdtDef, AsName, Container, Enum, Function, HasSource, ImplBlock, Name, Struct, Trait, + TypeAlias, Union, }; /// Data about a generic parameter (to a function, struct, impl, ...). diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index b7215ac0349..bd1e2f2e61c 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -3,14 +3,12 @@ use std::{ sync::Arc, }; -use ra_db::{FileId, salsa}; -use ra_syntax::{TreeArc, AstNode, ast, SyntaxNode}; -use ra_prof::profile; use mbe::MacroRules; +use ra_db::{salsa, FileId}; +use ra_prof::profile; +use ra_syntax::{ast, AstNode, SyntaxNode, TreeArc}; -use crate::{ - Module, DefDatabase, AstId, FileAstId, AstDatabase, Source, InternDatabase, -}; +use crate::{AstDatabase, AstId, DefDatabase, FileAstId, InternDatabase, Module, Source}; /// hir makes heavy use of ids: integer (u32) handlers to various things. You /// can think of id as a pointer (but without a lifetime) or a file descriptor diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index fb9daf1bf97..ce134b27a4a 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -1,21 +1,21 @@ -use std::sync::Arc; use rustc_hash::FxHashMap; +use std::sync::Arc; -use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; +use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_syntax::{ + ast::{self, AstNode}, AstPtr, SourceFile, TreeArc, - ast::{self, AstNode} }; use crate::{ - Const, TypeAlias, Function, HirFileId, AstDatabase, HasSource, Source, - HirDatabase, DefDatabase, TraitRef, - type_ref::TypeRef, + code_model::{Module, ModuleSource}, + generics::HasGenericParams, ids::LocationCtx, resolve::Resolver, ty::Ty, - generics::HasGenericParams, - code_model::{Module, ModuleSource} + type_ref::TypeRef, + AstDatabase, Const, DefDatabase, Function, HasSource, HirDatabase, HirFileId, Source, TraitRef, + TypeAlias, }; #[derive(Debug, Default, PartialEq, Eq)] diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index 48b60f2dde0..f9fe47b0f68 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs @@ -1,11 +1,11 @@ -use std::sync::Arc; use rustc_hash::FxHashMap; +use std::sync::Arc; -use ra_syntax::{SmolStr, TreeArc, ast::AttrsOwner}; +use ra_syntax::{ast::AttrsOwner, SmolStr, TreeArc}; use crate::{ - Crate, DefDatabase, Enum, Function, HirDatabase, ImplBlock, Module, - Static, Struct, Trait, ModuleDef, AstDatabase, HasSource + AstDatabase, Crate, DefDatabase, Enum, Function, HasSource, HirDatabase, ImplBlock, Module, + ModuleDef, Static, Struct, Trait, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 5afd846f522..ec0676783fc 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -47,39 +47,33 @@ mod code_model; mod marks; use crate::{ - db::{InternDatabase, AstDatabase, DefDatabase, HirDatabase}, - name::{AsName, KnownName}, - source_id::{FileAstId, AstId}, - resolve::Resolver, + db::{AstDatabase, DefDatabase, HirDatabase, InternDatabase}, ids::MacroFileKind, + name::{AsName, KnownName}, + resolve::Resolver, + source_id::{AstId, FileAstId}, }; pub use self::{ - either::Either, - path::{Path, PathKind}, - name::Name, - source_id::{AstIdMap, ErasedFileAstId}, - ids::{HirFileId, MacroDefId, MacroCallId, MacroCallLoc, MacroFile}, - nameres::{PerNs, Namespace, ImportId}, - ty::{Ty, ApplicationTy, TypeCtor, TraitRef, Substs, display::HirDisplay, CallableDef}, - impl_block::{ImplBlock, ImplItem}, adt::AdtDef, + either::Either, expr::ExprScopes, + generics::{GenericParam, GenericParams, HasGenericParams}, + ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, + impl_block::{ImplBlock, ImplItem}, + name::Name, + nameres::{ImportId, Namespace, PerNs}, + path::{Path, PathKind}, resolve::Resolution, - generics::{GenericParams, GenericParam, HasGenericParams}, - source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax}, + source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, + source_id::{AstIdMap, ErasedFileAstId}, + ty::{display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor}, }; pub use self::code_model::{ - Crate, CrateDependency, - DefWithBody, - Module, ModuleDef, ModuleSource, - Struct, Union, Enum, EnumVariant, - Function, FnData, - StructField, FieldSource, - Static, Const, ConstData, - Trait, TypeAlias, MacroDef, Container, - BuiltinType, - src::{Source, HasSource}, - docs::{Docs, Documentation, DocDef}, + docs::{DocDef, Docs, Documentation}, + src::{HasSource, Source}, + BuiltinType, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, + EnumVariant, FieldSource, FnData, Function, MacroDef, Module, ModuleDef, ModuleSource, Static, + Struct, StructField, Trait, TypeAlias, Union, }; diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs index c57dfbf0190..b26ea58c996 100644 --- a/crates/ra_hir/src/mock.rs +++ b/crates/ra_hir/src/mock.rs @@ -1,13 +1,12 @@ -use std::{sync::Arc, panic}; +use std::{panic, sync::Arc}; use parking_lot::Mutex; use ra_db::{ - FilePosition, FileId, CrateGraph, SourceRoot, SourceRootId, SourceDatabase, salsa, - Edition, + salsa, CrateGraph, Edition, FileId, FilePosition, SourceDatabase, SourceRoot, SourceRootId, }; use relative_path::RelativePathBuf; -use test_utils::{parse_fixture, CURSOR_MARKER, extract_offset}; use rustc_hash::FxHashMap; +use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; use crate::{db, diagnostics::DiagnosticSink}; diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index f4ca454e4e4..53ef8d58acc 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -55,28 +55,24 @@ mod tests; use std::sync::Arc; -use rustc_hash::{FxHashMap, FxHashSet}; -use ra_arena::{Arena, RawId, impl_arena_id}; -use ra_db::{FileId, Edition}; -use test_utils::tested_by; -use ra_syntax::ast; -use ra_prof::profile; use once_cell::sync::Lazy; +use ra_arena::{impl_arena_id, Arena, RawId}; +use ra_db::{Edition, FileId}; +use ra_prof::profile; +use ra_syntax::ast; +use rustc_hash::{FxHashMap, FxHashSet}; +use test_utils::tested_by; use crate::{ - ModuleDef, Name, Crate, Module, MacroDef, AsName, BuiltinType, AstDatabase, - DefDatabase, Path, PathKind, HirFileId, Trait, - ids::MacroDefId, - diagnostics::DiagnosticSink, - nameres::diagnostics::DefDiagnostic, - either::Either, - AstId, + diagnostics::DiagnosticSink, either::Either, ids::MacroDefId, + nameres::diagnostics::DefDiagnostic, AsName, AstDatabase, AstId, BuiltinType, Crate, + DefDatabase, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, }; -pub(crate) use self::raw::{RawItems, ImportSourceMap}; +pub(crate) use self::raw::{ImportSourceMap, RawItems}; pub use self::{ - per_ns::{PerNs, Namespace}, + per_ns::{Namespace, PerNs}, raw::ImportId, }; @@ -512,14 +508,14 @@ impl CrateDefMap { } mod diagnostics { + use ra_syntax::{ast, AstPtr}; use relative_path::RelativePathBuf; - use ra_syntax::{AstPtr, ast}; use crate::{ - AstId, DefDatabase, AstDatabase, + diagnostics::{DiagnosticSink, UnresolvedModule}, nameres::CrateModuleId, - diagnostics::{DiagnosticSink, UnresolvedModule} -}; + AstDatabase, AstId, DefDatabase, + }; #[derive(Debug, PartialEq, Eq)] pub(super) enum DefDiagnostic { diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs index ef4d1ed70f1..2b07ebf4a58 100644 --- a/crates/ra_hir/src/nameres/collector.rs +++ b/crates/ra_hir/src/nameres/collector.rs @@ -1,22 +1,19 @@ use arrayvec::ArrayVec; -use rustc_hash::FxHashMap; -use relative_path::RelativePathBuf; -use test_utils::tested_by; use ra_db::FileId; use ra_syntax::ast; +use relative_path::RelativePathBuf; +use rustc_hash::FxHashMap; +use test_utils::tested_by; use crate::{ - Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, MacroDef, - DefDatabase, HirFileId, Name, Path, - KnownName, AstId, - nameres::{ - Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, - CrateDefMap, CrateModuleId, ModuleData, ItemOrMacro, - diagnostics::DefDiagnostic, - raw, - }, - ids::{AstItemDef, LocationCtx, MacroCallLoc, MacroCallId, MacroDefId, MacroFileKind}, either::Either, + ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, + nameres::{ + diagnostics::DefDiagnostic, raw, CrateDefMap, CrateModuleId, ItemOrMacro, ModuleData, + ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, + }, + AstId, Const, DefDatabase, Enum, Function, HirFileId, KnownName, MacroDef, Module, Name, Path, + Static, Struct, Trait, TypeAlias, Union, }; pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { @@ -666,9 +663,9 @@ fn resolve_submodule( mod tests { use ra_db::SourceDatabase; - use crate::{Crate, mock::MockDatabase, DefDatabase}; - use ra_arena::{Arena}; use super::*; + use crate::{mock::MockDatabase, Crate, DefDatabase}; + use ra_arena::Arena; use rustc_hash::FxHashSet; fn do_collect_defs( diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index a0afe282c15..7ea59cb7591 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -1,13 +1,16 @@ -use std::{sync::Arc, ops::Index}; +use std::{ops::Index, sync::Arc}; -use test_utils::tested_by; -use ra_arena::{Arena, impl_arena_id, RawId, map::ArenaMap}; +use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_syntax::{ - AstNode, SourceFile, AstPtr, TreeArc, - ast::{self, NameOwner, AttrsOwner}, + ast::{self, AttrsOwner, NameOwner}, + AstNode, AstPtr, SourceFile, TreeArc, }; +use test_utils::tested_by; -use crate::{DefDatabase, Name, AsName, Path, HirFileId, ModuleSource, AstIdMap, FileAstId, Either, AstDatabase}; +use crate::{ + AsName, AstDatabase, AstIdMap, DefDatabase, Either, FileAstId, HirFileId, ModuleSource, Name, + Path, +}; /// `RawItems` is a set of top-level items in a file (except for impls). /// diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index adac814d913..953610b370e 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -5,14 +5,14 @@ mod primitives; use std::sync::Arc; +use insta::assert_snapshot_matches; use ra_db::SourceDatabase; use test_utils::covers; -use insta::assert_snapshot_matches; use crate::{ - Crate, Either, - mock::{MockDatabase, CrateGraphFixture}, + mock::{CrateGraphFixture, MockDatabase}, nameres::Resolution, + Crate, Either, }; use super::*; diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index 67afd5027a9..bce9d2d4bcb 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs @@ -1,8 +1,11 @@ use std::sync::Arc; -use ra_syntax::{ast::{self, NameOwner}, AstNode}; +use ra_syntax::{ + ast::{self, NameOwner}, + AstNode, +}; -use crate::{Name, AsName, type_ref::TypeRef}; +use crate::{type_ref::TypeRef, AsName, Name}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Path { diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 7f8b3812c35..fc981e9b3d6 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -4,16 +4,19 @@ use std::sync::Arc; use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ - ModuleDef, Trait, MacroDef, code_model::Crate, db::HirDatabase, - name::{Name, KnownName}, - nameres::{PerNs, CrateDefMap, CrateModuleId}, - generics::GenericParams, - expr::{scope::{ExprScopes, ScopeId}, PatId}, - impl_block::ImplBlock, - path::Path, either::Either, + expr::{ + scope::{ExprScopes, ScopeId}, + PatId, + }, + generics::GenericParams, + impl_block::ImplBlock, + name::{KnownName, Name}, + nameres::{CrateDefMap, CrateModuleId, PerNs}, + path::Path, + MacroDef, ModuleDef, Trait, }; #[derive(Debug, Clone, Default)] diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 08e86844de1..429575feef2 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -7,21 +7,25 @@ /// purely for "IDE needs". use std::sync::Arc; -use rustc_hash::{FxHashSet, FxHashMap}; use ra_db::{FileId, FilePosition}; use ra_syntax::{ - SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange, - ast::{self, AstNode, NameOwner}, algo::find_node_at_offset, + ast::{self, AstNode, NameOwner}, + AstPtr, SyntaxKind::*, + SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, }; +use rustc_hash::{FxHashMap, FxHashSet}; use crate::{ - HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name, - AsName, Module, HirFileId, Crate, Trait, Resolver, Ty, Path, MacroDef, - expr::{BodySourceMap, scope::{ScopeId, ExprScopes}}, + expr, + expr::{ + scope::{ExprScopes, ScopeId}, + BodySourceMap, + }, ids::LocationCtx, - expr, AstId, + AsName, AstId, Const, Crate, DefWithBody, Either, Enum, Function, HirDatabase, HirFileId, + MacroDef, Module, Name, Path, PerNs, Resolver, Static, Struct, Trait, Ty, }; /// Locates the module by `FileId`. Picks topmost module in the file. diff --git a/crates/ra_hir/src/source_id.rs b/crates/ra_hir/src/source_id.rs index 986269e0016..324b79824ee 100644 --- a/crates/ra_hir/src/source_id.rs +++ b/crates/ra_hir/src/source_id.rs @@ -1,9 +1,13 @@ -use std::{marker::PhantomData, sync::Arc, hash::{Hash, Hasher}}; +use std::{ + hash::{Hash, Hasher}, + marker::PhantomData, + sync::Arc, +}; -use ra_arena::{Arena, RawId, impl_arena_id}; -use ra_syntax::{SyntaxNodePtr, TreeArc, SyntaxNode, AstNode, ast}; +use ra_arena::{impl_arena_id, Arena, RawId}; +use ra_syntax::{ast, AstNode, SyntaxNode, SyntaxNodePtr, TreeArc}; -use crate::{HirFileId, AstDatabase}; +use crate::{AstDatabase, HirFileId}; /// `AstId` points to an AST node in any file. /// diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs index f2950e1b290..fc036830309 100644 --- a/crates/ra_hir/src/traits.rs +++ b/crates/ra_hir/src/traits.rs @@ -1,13 +1,13 @@ //! HIR for trait definitions. -use std::sync::Arc; use rustc_hash::FxHashMap; +use std::sync::Arc; use ra_syntax::ast::{self, NameOwner}; use crate::{ - Function, Const, TypeAlias, Name, DefDatabase, Trait, AstDatabase, Module, HasSource, - ids::LocationCtx, name::AsName, + ids::LocationCtx, name::AsName, AstDatabase, Const, DefDatabase, Function, HasSource, Module, + Name, Trait, TypeAlias, }; #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 842d49e1fd4..11afdc0f349 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -12,17 +12,20 @@ mod lower; mod infer; pub(crate) mod display; -use std::sync::Arc; use std::ops::Deref; +use std::sync::Arc; use std::{fmt, mem}; -use crate::{Name, AdtDef, type_ref::Mutability, db::HirDatabase, Trait, GenericParams, TypeAlias}; +use crate::{db::HirDatabase, type_ref::Mutability, AdtDef, GenericParams, Name, Trait, TypeAlias}; use display::{HirDisplay, HirFormatter}; -pub(crate) use lower::{TypableDef, type_for_def, type_for_field, callable_item_sig, generic_predicates, generic_defaults}; -pub(crate) use infer::{infer_query, InferenceResult, InferTy}; -pub use lower::CallableDef; pub(crate) use autoderef::autoderef; +pub(crate) use infer::{infer_query, InferTy, InferenceResult}; +pub use lower::CallableDef; +pub(crate) use lower::{ + callable_item_sig, generic_defaults, generic_predicates, type_for_def, type_for_field, + TypableDef, +}; pub(crate) use traits::ProjectionPredicate; /// A type constructor or type name: this might be something like the primitive diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 1f443d49b68..90c1ae630eb 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs @@ -7,8 +7,8 @@ use std::iter::successors; use log::{info, warn}; -use crate::{HirDatabase, Name, Resolver, HasGenericParams}; -use super::{traits::Solution, Ty, Canonical}; +use super::{traits::Solution, Canonical, Ty}; +use crate::{HasGenericParams, HirDatabase, Name, Resolver}; const AUTODEREF_RECURSION_LIMIT: usize = 10; diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 2c05ca734cf..a2dc9237046 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -15,38 +15,37 @@ use std::borrow::Cow; use std::iter::repeat; +use std::mem; use std::ops::Index; use std::sync::Arc; -use std::mem; -use ena::unify::{InPlaceUnificationTable, UnifyKey, UnifyValue, NoError}; +use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use rustc_hash::FxHashMap; use ra_arena::map::ArenaMap; use ra_prof::profile; use test_utils::tested_by; +use super::{ + autoderef, method_resolution, op, primitive, + traits::{Guidance, Obligation, Solution}, + ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypableDef, TypeCtor, +}; use crate::{ - Function, StructField, Path, Name, FnData, AdtDef, ConstData, HirDatabase, - DefWithBody, ImplItem, - type_ref::{TypeRef, Mutability}, + adt::VariantDef, + diagnostics::DiagnosticSink, expr::{ - Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, - FieldPat, Array, self, + self, Array, BinaryOp, BindingAnnotation, Body, Expr, ExprId, FieldPat, Literal, Pat, + PatId, Statement, UnaryOp, }, generics::{GenericParams, HasGenericParams}, - path::{GenericArgs, GenericArg}, - ModuleDef, - adt::VariantDef, - resolve::{Resolver, Resolution}, nameres::Namespace, + path::{GenericArg, GenericArgs}, + resolve::{Resolution, Resolver}, ty::infer::diagnostics::InferenceDiagnostic, - diagnostics::DiagnosticSink, -}; -use super::{ - Ty, TypableDef, Substs, primitive, op, ApplicationTy, TypeCtor, CallableDef, TraitRef, - traits::{Solution, Obligation, Guidance}, - method_resolution, autoderef, + type_ref::{Mutability, TypeRef}, + AdtDef, ConstData, DefWithBody, FnData, Function, HirDatabase, ImplItem, ModuleDef, Name, Path, + StructField, }; mod unify; @@ -1415,10 +1414,10 @@ impl Expectation { mod diagnostics { use crate::{ - expr::ExprId, diagnostics::{DiagnosticSink, NoSuchField}, - HirDatabase, Function, HasSource, -}; + expr::ExprId, + Function, HasSource, HirDatabase, + }; #[derive(Debug, PartialEq, Eq, Clone)] pub(super) enum InferenceDiagnostic { diff --git a/crates/ra_hir/src/ty/infer/unify.rs b/crates/ra_hir/src/ty/infer/unify.rs index bc971972584..04633bdb23f 100644 --- a/crates/ra_hir/src/ty/infer/unify.rs +++ b/crates/ra_hir/src/ty/infer/unify.rs @@ -1,8 +1,8 @@ //! Unification and canonicalization logic. -use crate::db::HirDatabase; -use crate::ty::{Ty, Canonical, TraitRef, InferTy}; use super::InferenceContext; +use crate::db::HirDatabase; +use crate::ty::{Canonical, InferTy, TraitRef, Ty}; impl<'a, D: HirDatabase> InferenceContext<'a, D> { pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D> diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index cb494baf48f..8b1b2a7f9d7 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -5,23 +5,22 @@ //! - Building the type for an item: This happens through the `type_for_def` query. //! //! This usually involves resolving names, collecting generic arguments etc. -use std::sync::Arc; use std::iter; +use std::sync::Arc; +use super::{FnSig, GenericPredicate, Substs, TraitRef, Ty, TypeCtor}; use crate::{ - Function, Struct, Union, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static, - HirDatabase, BuiltinType, - type_ref::TypeRef, - nameres::Namespace, - resolve::{Resolver, Resolution}, - path::{PathSegment, GenericArg}, - generics::{HasGenericParams}, adt::VariantDef, - Trait, - generics::{WherePredicate, GenericDef}, + generics::HasGenericParams, + generics::{GenericDef, WherePredicate}, + nameres::Namespace, + path::{GenericArg, PathSegment}, + resolve::{Resolution, Resolver}, ty::AdtDef, + type_ref::TypeRef, + BuiltinType, Const, Enum, EnumVariant, Function, HirDatabase, ModuleDef, Path, Static, Struct, + StructField, Trait, TypeAlias, Union, }; -use super::{Ty, FnSig, Substs, TypeCtor, TraitRef, GenericPredicate}; impl Ty { pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self { diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index e023ff25a2d..bc890fe7982 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -7,17 +7,17 @@ use std::sync::Arc; use arrayvec::ArrayVec; use rustc_hash::FxHashMap; +use super::{autoderef, Canonical, TraitRef}; use crate::{ - HirDatabase, Module, Crate, Name, Function, Trait, - impl_block::{ImplId, ImplBlock, ImplItem}, - ty::{Ty, TypeCtor}, + generics::HasGenericParams, + impl_block::{ImplBlock, ImplId, ImplItem}, nameres::CrateModuleId, resolve::Resolver, traits::TraitItem, - generics::HasGenericParams, - ty::primitive::{UncertainIntTy, UncertainFloatTy} + ty::primitive::{UncertainFloatTy, UncertainIntTy}, + ty::{Ty, TypeCtor}, + Crate, Function, HirDatabase, Module, Name, Trait, }; -use super::{TraitRef, Canonical, autoderef}; /// This is used as a key for indexing impls. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir/src/ty/op.rs b/crates/ra_hir/src/ty/op.rs index 235661a5d81..9ba8682980c 100644 --- a/crates/ra_hir/src/ty/op.rs +++ b/crates/ra_hir/src/ty/op.rs @@ -1,5 +1,5 @@ -use crate::{ ty::ApplicationTy, expr::BinaryOp}; -use super::{Ty, TypeCtor, InferTy}; +use super::{InferTy, Ty, TypeCtor}; +use crate::{expr::BinaryOp, ty::ApplicationTy}; pub(super) fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { match op { diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 0fe7805e24a..20fa74fb435 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -1,17 +1,18 @@ -use std::sync::Arc; use std::fmt::Write; +use std::sync::Arc; use insta::assert_snapshot_matches; -use ra_db::{SourceDatabase, salsa::Database, FilePosition}; -use ra_syntax::{algo, ast::{self, AstNode}, SyntaxKind::*}; +use ra_db::{salsa::Database, FilePosition, SourceDatabase}; +use ra_syntax::{ + algo, + ast::{self, AstNode}, + SyntaxKind::*, +}; use test_utils::covers; use crate::{ - mock::MockDatabase, - ty::display::HirDisplay, - ty::InferenceResult, - expr::BodySourceMap, + expr::BodySourceMap, mock::MockDatabase, ty::display::HirDisplay, ty::InferenceResult, SourceAnalyzer, }; diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 69c03a36cdd..3c902451bf0 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs @@ -1,16 +1,16 @@ //! Trait solving using Chalk. use std::sync::Arc; -use parking_lot::Mutex; -use rustc_hash::FxHashSet; -use log::debug; use chalk_ir::cast::Cast; +use log::debug; +use parking_lot::Mutex; use ra_prof::profile; +use rustc_hash::FxHashSet; -use crate::{Crate, Trait, db::HirDatabase, ImplBlock}; -use super::{TraitRef, Ty, Canonical, ProjectionTy}; +use super::{Canonical, ProjectionTy, TraitRef, Ty}; +use crate::{db::HirDatabase, Crate, ImplBlock, Trait}; -use self::chalk::{ToChalk, from_chalk}; +use self::chalk::{from_chalk, ToChalk}; pub(crate) mod chalk; diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 4ceb8b70bcb..2a0537bc333 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -3,20 +3,25 @@ use std::sync::Arc; use log::debug; -use chalk_ir::{TypeId, ImplId, TypeKindId, Parameter, Identifier, cast::Cast, PlaceholderIndex, UniverseIndex, TypeName}; -use chalk_rust_ir::{AssociatedTyDatum, TraitDatum, StructDatum, ImplDatum}; - -use test_utils::tested_by; -use ra_db::salsa::{InternId, InternKey}; - -use crate::{ - Trait, HasGenericParams, ImplBlock, Crate, - db::HirDatabase, - ty::{TraitRef, Ty, ApplicationTy, TypeCtor, Substs, GenericPredicate, CallableDef, ProjectionTy}, - ty::display::HirDisplay, - generics::GenericDef, TypeAlias, ImplItem, +use chalk_ir::{ + cast::Cast, Identifier, ImplId, Parameter, PlaceholderIndex, TypeId, TypeKindId, TypeName, + UniverseIndex, }; +use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; + +use ra_db::salsa::{InternId, InternKey}; +use test_utils::tested_by; + use super::ChalkContext; +use crate::{ + db::HirDatabase, + generics::GenericDef, + ty::display::HirDisplay, + ty::{ + ApplicationTy, CallableDef, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, + }, + Crate, HasGenericParams, ImplBlock, ImplItem, Trait, TypeAlias, +}; /// This represents a trait whose name we could not resolve. const UNKNOWN_TRAIT: chalk_ir::TraitId = diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs index eada3727413..3b38c4740a7 100644 --- a/crates/ra_hir/src/type_alias.rs +++ b/crates/ra_hir/src/type_alias.rs @@ -4,7 +4,12 @@ use std::sync::Arc; use ra_syntax::ast::NameOwner; -use crate::{TypeAlias, db::{DefDatabase, AstDatabase}, type_ref::TypeRef, name::{Name, AsName}, HasSource}; +use crate::{ + db::{AstDatabase, DefDatabase}, + name::{AsName, Name}, + type_ref::TypeRef, + HasSource, TypeAlias, +}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct TypeAliasData { diff --git a/crates/ra_ide_api/src/assists.rs b/crates/ra_ide_api/src/assists.rs index 355c0a42aa2..e3d1ac5298a 100644 --- a/crates/ra_ide_api/src/assists.rs +++ b/crates/ra_ide_api/src/assists.rs @@ -1,6 +1,6 @@ -use ra_db::{FileRange, FilePosition}; +use ra_db::{FilePosition, FileRange}; -use crate::{SourceFileEdit, SourceChange, db::RootDatabase}; +use crate::{db::RootDatabase, SourceChange, SourceFileEdit}; pub use ra_assists::AssistId; diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 2948c646bb9..368fdcaa1ef 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -1,12 +1,12 @@ -use test_utils::tested_by; use ra_db::SourceDatabase; use ra_syntax::{ - AstNode, SyntaxNode, TextUnit, - ast::{self, ArgListOwner}, algo::find_node_at_offset, + ast::{self, ArgListOwner}, + AstNode, SyntaxNode, TextUnit, }; +use test_utils::tested_by; -use crate::{FilePosition, CallInfo, FunctionSignature, db::RootDatabase}; +use crate::{db::RootDatabase, CallInfo, FilePosition, FunctionSignature}; /// Computes parameter information for the given call expression. pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option { diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index c0c289335eb..2a1af0a0a34 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs @@ -1,22 +1,19 @@ -use std::{ - fmt, time, - sync::Arc, -}; +use std::{fmt, sync::Arc, time}; -use rustc_hash::FxHashMap; use ra_db::{ - SourceRootId, FileId, CrateGraph, SourceDatabase, SourceRoot, salsa::{Database, SweepStrategy}, + CrateGraph, FileId, SourceDatabase, SourceRoot, SourceRootId, }; +use ra_prof::{memory_usage, profile, Bytes}; use ra_syntax::SourceFile; -use ra_prof::{profile, Bytes, memory_usage}; -use relative_path::RelativePathBuf; use rayon::prelude::*; +use relative_path::RelativePathBuf; +use rustc_hash::FxHashMap; use crate::{ db::RootDatabase, - symbol_index::{SymbolIndex, SymbolsDatabase}, status::syntax_tree_stats, + symbol_index::{SymbolIndex, SymbolsDatabase}, }; #[derive(Default)] diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs index 3a75bbf9218..c23b5da59be 100644 --- a/crates/ra_ide_api/src/completion.rs +++ b/crates/ra_ide_api/src/completion.rs @@ -14,19 +14,19 @@ mod complete_postfix; use ra_db::SourceDatabase; -use crate::{ - db, - FilePosition, - completion::{ - completion_item::{Completions, CompletionKind}, - completion_context::CompletionContext, - }, - -}; #[cfg(test)] -use crate::completion::completion_item::{do_completion, check_completion}; +use crate::completion::completion_item::{check_completion, do_completion}; +use crate::{ + completion::{ + completion_context::CompletionContext, + completion_item::{CompletionKind, Completions}, + }, + db, FilePosition, +}; -pub use crate::completion::completion_item::{CompletionItem, CompletionItemKind, InsertTextFormat}; +pub use crate::completion::completion_item::{ + CompletionItem, CompletionItemKind, InsertTextFormat, +}; /// Main entry point for completion. We run completion as a two-phase process. /// diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index a97e876e957..a5f071442b1 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -1,4 +1,4 @@ -use hir::{Ty, AdtDef, TypeCtor}; +use hir::{AdtDef, Ty, TypeCtor}; use crate::completion::{CompletionContext, Completions}; use rustc_hash::FxHashSet; @@ -49,7 +49,7 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty #[cfg(test)] mod tests { - use crate::completion::{do_completion, CompletionKind, CompletionItem}; + use crate::completion::{do_completion, CompletionItem, CompletionKind}; use insta::assert_debug_snapshot_matches; fn do_ref_completion(code: &str) -> Vec { diff --git a/crates/ra_ide_api/src/completion/complete_fn_param.rs b/crates/ra_ide_api/src/completion/complete_fn_param.rs index d738ffc136b..5a117c48509 100644 --- a/crates/ra_ide_api/src/completion/complete_fn_param.rs +++ b/crates/ra_ide_api/src/completion/complete_fn_param.rs @@ -1,11 +1,10 @@ use ra_syntax::{ algo::visit::{visitor_ctx, VisitorCtx}, - ast, - AstNode, + ast, AstNode, }; use rustc_hash::FxHashMap; -use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem}; +use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; /// Complete repeated parameters, both name and type. For example, if all /// functions in a file have a `spam: &mut Spam` parameter, a completion with diff --git a/crates/ra_ide_api/src/completion/complete_keyword.rs b/crates/ra_ide_api/src/completion/complete_keyword.rs index cfb9fd6e8c9..034ed934dfb 100644 --- a/crates/ra_ide_api/src/completion/complete_keyword.rs +++ b/crates/ra_ide_api/src/completion/complete_keyword.rs @@ -1,11 +1,14 @@ use ra_syntax::{ algo::visit::{visitor, Visitor}, - AstNode, ast::{self, LoopBodyOwner}, - SyntaxKind::*, SyntaxToken, + AstNode, + SyntaxKind::*, + SyntaxToken, }; -use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; +use crate::completion::{ + CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, +}; pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) { // complete keyword "crate" in use stmt diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index da8fb9d8e9e..29586cd1f13 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -1,8 +1,8 @@ -use hir::{Resolution, Either}; +use hir::{Either, Resolution}; use ra_syntax::AstNode; use test_utils::tested_by; -use crate::completion::{Completions, CompletionContext}; +use crate::completion::{CompletionContext, Completions}; pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { let path = match &ctx.path_prefix { @@ -78,7 +78,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { mod tests { use test_utils::covers; - use crate::completion::{CompletionKind, do_completion, CompletionItem}; + use crate::completion::{do_completion, CompletionItem, CompletionKind}; use insta::assert_debug_snapshot_matches; fn do_reference_completion(code: &str) -> Vec { diff --git a/crates/ra_ide_api/src/completion/complete_pattern.rs b/crates/ra_ide_api/src/completion/complete_pattern.rs index 6655a05a7c8..f12dfcc17f7 100644 --- a/crates/ra_ide_api/src/completion/complete_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_pattern.rs @@ -27,8 +27,8 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { #[cfg(test)] mod tests { + use crate::completion::{do_completion, CompletionItem, CompletionKind}; use insta::assert_debug_snapshot_matches; - use crate::completion::{CompletionItem, CompletionKind, do_completion}; fn complete(code: &str) -> Vec { do_completion(code, CompletionKind::Reference) diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs index e20a12e2ac1..7042d8bff01 100644 --- a/crates/ra_ide_api/src/completion/complete_postfix.rs +++ b/crates/ra_ide_api/src/completion/complete_postfix.rs @@ -1,18 +1,11 @@ use crate::{ completion::{ - completion_item::{ - Completions, - Builder, - CompletionKind, - }, completion_context::CompletionContext, + completion_item::{Builder, CompletionKind, Completions}, }, - CompletionItem -}; -use ra_syntax::{ - ast::AstNode, - TextRange + CompletionItem, }; +use ra_syntax::{ast::AstNode, TextRange}; use ra_text_edit::TextEditBuilder; fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: &str) -> Builder { @@ -58,7 +51,7 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { #[cfg(test)] mod tests { - use crate::completion::{CompletionKind, check_completion}; + use crate::completion::{check_completion, CompletionKind}; fn check_snippet_completion(test_name: &str, code: &str) { check_completion(test_name, code, CompletionKind::Postfix); diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 0f8cfaae80c..1ba8712572d 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -1,9 +1,9 @@ -use rustc_hash::FxHashMap; -use ra_text_edit::TextEditBuilder; -use ra_syntax::{SmolStr, ast, AstNode}; use ra_assists::auto_import; +use ra_syntax::{ast, AstNode, SmolStr}; +use ra_text_edit::TextEditBuilder; +use rustc_hash::FxHashMap; -use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext}; +use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { if ctx.is_trivial_path { @@ -121,7 +121,7 @@ impl ImportResolver { #[cfg(test)] mod tests { - use crate::completion::{CompletionKind, check_completion}; + use crate::completion::{check_completion, CompletionKind}; fn check_reference_completion(name: &str, code: &str) { check_completion(name, code, CompletionKind::Reference); diff --git a/crates/ra_ide_api/src/completion/complete_snippet.rs b/crates/ra_ide_api/src/completion/complete_snippet.rs index e1df9e62512..d2d364b57b1 100644 --- a/crates/ra_ide_api/src/completion/complete_snippet.rs +++ b/crates/ra_ide_api/src/completion/complete_snippet.rs @@ -1,4 +1,7 @@ -use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder}; +use crate::completion::{ + completion_item::Builder, CompletionContext, CompletionItem, CompletionItemKind, + CompletionKind, Completions, +}; fn snippet(ctx: &CompletionContext, label: &str, snippet: &str) -> Builder { CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), label) @@ -36,7 +39,7 @@ fn ${1:feature}() { #[cfg(test)] mod tests { - use crate::completion::{CompletionKind, check_completion}; + use crate::completion::{check_completion, CompletionKind}; fn check_snippet_completion(name: &str, code: &str) { check_completion(name, code, CompletionKind::Snippet); diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs index 1eeea58f640..35fb2111336 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs @@ -27,8 +27,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon #[cfg(test)] mod tests { + use crate::completion::{do_completion, CompletionItem, CompletionKind}; use insta::assert_debug_snapshot_matches; - use crate::completion::{CompletionItem, CompletionKind, do_completion}; fn complete(code: &str) -> Vec { do_completion(code, CompletionKind::Reference) diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index bda7d9bb24c..55fdba50d6c 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -1,11 +1,11 @@ -use ra_text_edit::AtomTextEdit; -use ra_syntax::{ - AstNode, SyntaxNode, SourceFile, TextUnit, TextRange, SyntaxToken, Parse, - ast, - algo::{find_token_at_offset, find_covering_element, find_node_at_offset}, - SyntaxKind::*, -}; use hir::source_binder; +use ra_syntax::{ + algo::{find_covering_element, find_node_at_offset, find_token_at_offset}, + ast, AstNode, Parse, SourceFile, + SyntaxKind::*, + SyntaxNode, SyntaxToken, TextRange, TextUnit, +}; +use ra_text_edit::AtomTextEdit; use crate::{db, FilePosition}; diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 6f2a60640eb..f78c4c8772f 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -2,7 +2,7 @@ use std::fmt; use hir::Documentation; use ra_syntax::TextRange; -use ra_text_edit::{TextEditBuilder, TextEdit}; +use ra_text_edit::{TextEdit, TextEditBuilder}; /// `CompletionItem` describes a single completion variant in the editor pop-up. /// It is basically a POD with various properties. To construct a @@ -285,8 +285,8 @@ impl Into> for Completions { #[cfg(test)] pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec { - use crate::mock_analysis::{single_file_with_position, analysis_and_position}; use crate::completion::completions; + use crate::mock_analysis::{analysis_and_position, single_file_with_position}; let (analysis, position) = if code.contains("//-") { analysis_and_position(code) } else { diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 97393673655..98060947a32 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -1,16 +1,14 @@ //! This modules takes care of rendering various defenitions as completion items. +use hir::{Docs, HasSource, HirDisplay, PerNs, Resolution}; use join_to_string::join; -use test_utils::tested_by; -use hir::{Docs, PerNs, Resolution, HirDisplay, HasSource}; use ra_syntax::ast::NameOwner; +use test_utils::tested_by; use crate::completion::{ - Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem, + CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, }; -use crate::display::{ - function_label, const_label, type_label, -}; +use crate::display::{const_label, function_label, type_label}; impl Completions { pub(crate) fn add_field( @@ -178,7 +176,7 @@ impl Completions { mod tests { use test_utils::covers; - use crate::completion::{CompletionKind, check_completion}; + use crate::completion::{check_completion, CompletionKind}; fn check_reference_completion(code: &str, expected_completions: &str) { check_completion(code, expected_completions, CompletionKind::Reference); diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 94977764cf7..fc5b06ca87b 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -1,14 +1,14 @@ -use std::{ - sync::Arc, - time, -}; +use std::{sync::Arc, time}; use ra_db::{ - CheckCanceled, FileId, Canceled, SourceDatabase, salsa::{self, Database}, + Canceled, CheckCanceled, FileId, SourceDatabase, }; -use crate::{LineIndex, symbol_index::{self, SymbolsDatabase}}; +use crate::{ + symbol_index::{self, SymbolsDatabase}, + LineIndex, +}; #[salsa::database( ra_db::SourceDatabaseStorage, diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 35b3d77df31..9ab455b0e41 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -1,17 +1,20 @@ use std::cell::RefCell; -use itertools::Itertools; -use hir::{source_binder, diagnostics::{Diagnostic as _, DiagnosticSink}}; -use ra_db::SourceDatabase; -use ra_syntax::{ - T, Location, TextRange, SyntaxNode, - ast::{self, AstNode, NamedFieldList, NamedField}, +use hir::{ + diagnostics::{Diagnostic as _, DiagnosticSink}, + source_binder, }; -use ra_assists::ast_editor::{AstEditor, AstBuilder}; -use ra_text_edit::{TextEdit, TextEditBuilder}; +use itertools::Itertools; +use ra_assists::ast_editor::{AstBuilder, AstEditor}; +use ra_db::SourceDatabase; use ra_prof::profile; +use ra_syntax::{ + ast::{self, AstNode, NamedField, NamedFieldList}, + Location, SyntaxNode, TextRange, T, +}; +use ra_text_edit::{TextEdit, TextEditBuilder}; -use crate::{Diagnostic, FileId, FileSystemEdit, SourceChange, SourceFileEdit, db::RootDatabase}; +use crate::{db::RootDatabase, Diagnostic, FileId, FileSystemEdit, SourceChange, SourceFileEdit}; #[derive(Debug, Copy, Clone)] pub enum Severity { @@ -170,9 +173,9 @@ fn check_struct_shorthand_initialization( #[cfg(test)] mod tests { - use test_utils::assert_eq_text; use insta::assert_debug_snapshot_matches; use ra_syntax::SourceFile; + use test_utils::assert_eq_text; use crate::mock_analysis::single_file; diff --git a/crates/ra_ide_api/src/display.rs b/crates/ra_ide_api/src/display.rs index 8825188382d..cc59e99d881 100644 --- a/crates/ra_ide_api/src/display.rs +++ b/crates/ra_ide_api/src/display.rs @@ -6,14 +6,17 @@ mod navigation_target; mod structure; mod short_label; -use ra_syntax::{ast::{self, AstNode, TypeParamsOwner}, SyntaxKind::{ATTR, COMMENT}}; +use ra_syntax::{ + ast::{self, AstNode, TypeParamsOwner}, + SyntaxKind::{ATTR, COMMENT}, +}; -pub use navigation_target::NavigationTarget; -pub use structure::{StructureNode, file_structure}; pub use function_signature::FunctionSignature; +pub use navigation_target::NavigationTarget; +pub use structure::{file_structure, StructureNode}; +pub(crate) use navigation_target::{description_from_symbol, docs_from_symbol}; pub(crate) use short_label::ShortLabel; -pub(crate) use navigation_target::{docs_from_symbol, description_from_symbol}; pub(crate) fn function_label(node: &ast::FnDef) -> String { FunctionSignature::from(node).to_string() diff --git a/crates/ra_ide_api/src/display/function_signature.rs b/crates/ra_ide_api/src/display/function_signature.rs index b0b0c71227f..e7ad5a0d19c 100644 --- a/crates/ra_ide_api/src/display/function_signature.rs +++ b/crates/ra_ide_api/src/display/function_signature.rs @@ -1,11 +1,14 @@ use std::fmt::{self, Display}; +use hir::{Docs, Documentation, HasSource}; use join_to_string::join; use ra_syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; use std::convert::From; -use hir::{Docs, Documentation, HasSource}; -use crate::{db, display::{where_predicates, generic_parameters}}; +use crate::{ + db, + display::{generic_parameters, where_predicates}, +}; /// Contains information about a function signature #[derive(Debug)] diff --git a/crates/ra_ide_api/src/display/navigation_target.rs b/crates/ra_ide_api/src/display/navigation_target.rs index 823cdaaf3cb..1edb64e3de0 100644 --- a/crates/ra_ide_api/src/display/navigation_target.rs +++ b/crates/ra_ide_api/src/display/navigation_target.rs @@ -1,14 +1,15 @@ +use hir::{FieldSource, HasSource, ImplItem, ModuleSource}; use ra_db::{FileId, SourceDatabase}; use ra_syntax::{ - SyntaxNode, AstNode, SmolStr, TextRange, AstPtr, TreeArc, - SyntaxKind::{self, NAME}, - ast::{self, DocCommentsOwner}, algo::visit::{visitor, Visitor}, + ast::{self, DocCommentsOwner}, + AstNode, AstPtr, SmolStr, + SyntaxKind::{self, NAME}, + SyntaxNode, TextRange, TreeArc, }; -use hir::{ModuleSource, FieldSource, ImplItem, HasSource}; -use crate::{FileSymbol, db::RootDatabase}; use super::short_label::ShortLabel; +use crate::{db::RootDatabase, FileSymbol}; /// `NavigationTarget` represents and element in the editor's UI which you can /// click on to navigate to a particular piece of code. diff --git a/crates/ra_ide_api/src/display/short_label.rs b/crates/ra_ide_api/src/display/short_label.rs index dc8245c341f..f926f631fc5 100644 --- a/crates/ra_ide_api/src/display/short_label.rs +++ b/crates/ra_ide_api/src/display/short_label.rs @@ -1,6 +1,4 @@ -use ra_syntax::{ - ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner, AstNode}, -}; +use ra_syntax::ast::{self, AstNode, NameOwner, TypeAscriptionOwner, VisibilityOwner}; pub(crate) trait ShortLabel { fn short_label(&self) -> Option; diff --git a/crates/ra_ide_api/src/display/structure.rs b/crates/ra_ide_api/src/display/structure.rs index e5057e833fd..e5b257b9bdb 100644 --- a/crates/ra_ide_api/src/display/structure.rs +++ b/crates/ra_ide_api/src/display/structure.rs @@ -2,7 +2,7 @@ use crate::TextRange; use ra_syntax::{ algo::visit::{visitor, Visitor}, - ast::{self, AttrsOwner, NameOwner, TypeParamsOwner, TypeAscriptionOwner}, + ast::{self, AttrsOwner, NameOwner, TypeAscriptionOwner, TypeParamsOwner}, AstNode, SourceFile, SyntaxKind, SyntaxNode, WalkEvent, }; diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index a713b762cf5..655852514a3 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -1,13 +1,13 @@ use ra_db::SourceDatabase; use ra_syntax::{ - Direction, SyntaxNode, TextRange, TextUnit, SyntaxElement, algo::{find_covering_element, find_token_at_offset, TokenAtOffset}, - SyntaxKind::*, SyntaxToken, ast::{self, AstNode, AstToken}, - T + Direction, SyntaxElement, + SyntaxKind::*, + SyntaxNode, SyntaxToken, TextRange, TextUnit, T, }; -use crate::{FileRange, db::RootDatabase}; +use crate::{db::RootDatabase, FileRange}; // FIXME: restore macro support pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange { @@ -205,7 +205,7 @@ fn adj_comments(comment: ast::Comment, dir: Direction) -> ast::Comment { #[cfg(test)] mod tests { - use ra_syntax::{SourceFile, AstNode}; + use ra_syntax::{AstNode, SourceFile}; use test_utils::extract_offset; use super::*; diff --git a/crates/ra_ide_api/src/folding_ranges.rs b/crates/ra_ide_api/src/folding_ranges.rs index 4400ff2323e..a1e6f94e08e 100644 --- a/crates/ra_ide_api/src/folding_ranges.rs +++ b/crates/ra_ide_api/src/folding_ranges.rs @@ -1,9 +1,10 @@ use rustc_hash::FxHashSet; use ra_syntax::{ - SourceFile, SyntaxNode, TextRange, Direction, SyntaxElement, - SyntaxKind::{self, *}, ast::{self, AstNode, AstToken, VisibilityOwner}, + Direction, SourceFile, SyntaxElement, + SyntaxKind::{self, *}, + SyntaxNode, TextRange, }; #[derive(Debug, PartialEq, Eq)] diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 63ba6cf9d36..08feed7dc96 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -1,19 +1,18 @@ use ra_db::{FileId, SourceDatabase}; use ra_syntax::{ - AstNode, ast::{self, DocCommentsOwner}, algo::{ find_node_at_offset, visit::{visitor, Visitor}, }, - SyntaxNode, + ast::{self, DocCommentsOwner}, + AstNode, SyntaxNode, }; use crate::{ - FilePosition, NavigationTarget, db::RootDatabase, - RangeInfo, - name_ref_kind::{NameRefKind::*, classify_name_ref}, display::ShortLabel, + name_ref_kind::{classify_name_ref, NameRefKind::*}, + FilePosition, NavigationTarget, RangeInfo, }; pub(crate) fn goto_definition( diff --git a/crates/ra_ide_api/src/goto_type_definition.rs b/crates/ra_ide_api/src/goto_type_definition.rs index 6f5164e0bab..d2d5eae9a10 100644 --- a/crates/ra_ide_api/src/goto_type_definition.rs +++ b/crates/ra_ide_api/src/goto_type_definition.rs @@ -1,10 +1,7 @@ use ra_db::SourceDatabase; -use ra_syntax::{ - AstNode, ast, - algo::find_token_at_offset -}; +use ra_syntax::{algo::find_token_at_offset, ast, AstNode}; -use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; +use crate::{db::RootDatabase, FilePosition, NavigationTarget, RangeInfo}; pub(crate) fn goto_type_definition( db: &RootDatabase, diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index df877c324c5..1edeb757935 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -1,16 +1,22 @@ +use hir::{HasSource, HirDisplay}; use ra_db::SourceDatabase; use ra_syntax::{ - AstNode, TreeArc, + algo::{ + ancestors_at_offset, find_covering_element, find_node_at_offset, + visit::{visitor, Visitor}, + }, ast::{self, DocCommentsOwner}, - algo::{find_covering_element, find_node_at_offset, ancestors_at_offset, visit::{visitor, Visitor}}, + AstNode, TreeArc, }; -use hir::{HirDisplay, HasSource}; use crate::{ db::RootDatabase, - RangeInfo, FilePosition, FileRange, - display::{rust_code_markup, rust_code_markup_with_doc, ShortLabel, docs_from_symbol, description_from_symbol}, - name_ref_kind::{NameRefKind::*, classify_name_ref}, + display::{ + description_from_symbol, docs_from_symbol, rust_code_markup, rust_code_markup_with_doc, + ShortLabel, + }, + name_ref_kind::{classify_name_ref, NameRefKind::*}, + FilePosition, FileRange, RangeInfo, }; /// Contains the results when hovering over an item @@ -256,8 +262,10 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option { #[cfg(test)] mod tests { + use crate::mock_analysis::{ + analysis_and_position, single_file_with_position, single_file_with_range, + }; use ra_syntax::TextRange; - use crate::mock_analysis::{single_file_with_position, single_file_with_range, analysis_and_position}; fn trim_markup(s: &str) -> &str { s.trim_start_matches("```rust\n").trim_end_matches("\n```") diff --git a/crates/ra_ide_api/src/impls.rs b/crates/ra_ide_api/src/impls.rs index b80238d9e04..f8a62bd7104 100644 --- a/crates/ra_ide_api/src/impls.rs +++ b/crates/ra_ide_api/src/impls.rs @@ -1,11 +1,8 @@ -use ra_db::SourceDatabase; -use ra_syntax::{ - AstNode, ast, - algo::find_node_at_offset, -}; use hir::{db::HirDatabase, source_binder}; +use ra_db::SourceDatabase; +use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; -use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; +use crate::{db::RootDatabase, FilePosition, NavigationTarget, RangeInfo}; pub(crate) fn goto_implementation( db: &RootDatabase, diff --git a/crates/ra_ide_api/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs index 3978e963585..8ab485adbe0 100644 --- a/crates/ra_ide_api/src/join_lines.rs +++ b/crates/ra_ide_api/src/join_lines.rs @@ -1,14 +1,11 @@ use itertools::Itertools; +use ra_fmt::{compute_ws, extract_trivial_expression}; use ra_syntax::{ - T, - SourceFile, TextRange, TextUnit, SyntaxNode, SyntaxElement, SyntaxToken, - SyntaxKind::{self, WHITESPACE}, algo::{find_covering_element, non_trivia_sibling}, ast::{self, AstNode, AstToken}, - Direction, -}; -use ra_fmt::{ - compute_ws, extract_trivial_expression + Direction, SourceFile, SyntaxElement, + SyntaxKind::{self, WHITESPACE}, + SyntaxNode, SyntaxToken, TextRange, TextUnit, T, }; use ra_text_edit::{TextEdit, TextEditBuilder}; diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 817e65df0f9..95de9bcb846 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -46,33 +46,35 @@ mod test_utils; use std::sync::Arc; -use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit}; -use ra_text_edit::TextEdit; use ra_db::{ - SourceDatabase, CheckCanceled, salsa::{self, ParallelDatabase}, + CheckCanceled, SourceDatabase, }; +use ra_syntax::{SourceFile, TextRange, TextUnit, TreeArc}; +use ra_text_edit::TextEdit; use relative_path::RelativePathBuf; -use crate::{symbol_index::FileSymbol, db::LineIndexDatabase}; +use crate::{db::LineIndexDatabase, symbol_index::FileSymbol}; pub use crate::{ + assists::{Assist, AssistId}, change::{AnalysisChange, LibraryData}, completion::{CompletionItem, CompletionItemKind, InsertTextFormat}, - runnables::{Runnable, RunnableKind}, - references::ReferenceSearchResult, - assists::{Assist, AssistId}, - hover::{HoverResult}, - line_index::{LineIndex, LineCol}, - line_index_utils::translate_offset_with_edit, - folding_ranges::{Fold, FoldKind}, - syntax_highlighting::HighlightedRange, diagnostics::Severity, - display::{FunctionSignature, NavigationTarget, StructureNode, file_structure}, + display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, + folding_ranges::{Fold, FoldKind}, + hover::HoverResult, + line_index::{LineCol, LineIndex}, + line_index_utils::translate_offset_with_edit, + references::ReferenceSearchResult, + runnables::{Runnable, RunnableKind}, + syntax_highlighting::HighlightedRange, }; -pub use ra_db::{Canceled, CrateGraph, CrateId, FileId, FilePosition, FileRange, SourceRootId, Edition}; pub use hir::Documentation; +pub use ra_db::{ + Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, +}; pub type Cancelable = Result; diff --git a/crates/ra_ide_api/src/line_index.rs b/crates/ra_ide_api/src/line_index.rs index a53cf9ee006..71de8a928ea 100644 --- a/crates/ra_ide_api/src/line_index.rs +++ b/crates/ra_ide_api/src/line_index.rs @@ -145,7 +145,7 @@ pub fn to_line_col(text: &str, offset: TextUnit) -> LineCol { mod test_line_index { use super::*; use proptest::{prelude::*, proptest}; - use ra_text_edit::test_utils::{arb_text, arb_offset}; + use ra_text_edit::test_utils::{arb_offset, arb_text}; #[test] fn test_line_index() { diff --git a/crates/ra_ide_api/src/line_index_utils.rs b/crates/ra_ide_api/src/line_index_utils.rs index a03467011d8..f9073dca2cd 100644 --- a/crates/ra_ide_api/src/line_index_utils.rs +++ b/crates/ra_ide_api/src/line_index_utils.rs @@ -1,6 +1,6 @@ +use crate::{line_index::Utf16Char, LineCol, LineIndex}; +use ra_syntax::{TextRange, TextUnit}; use ra_text_edit::{AtomTextEdit, TextEdit}; -use ra_syntax::{TextUnit, TextRange}; -use crate::{LineIndex, LineCol, line_index::Utf16Char}; #[derive(Debug, Clone)] enum Step { @@ -292,8 +292,8 @@ pub fn translate_offset_with_edit( #[cfg(test)] mod test { use super::*; - use proptest::{prelude::*, proptest}; use crate::line_index; + use proptest::{prelude::*, proptest}; use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit}; use ra_text_edit::TextEdit; diff --git a/crates/ra_ide_api/src/matching_brace.rs b/crates/ra_ide_api/src/matching_brace.rs index 7f3e65b460c..438b078964c 100644 --- a/crates/ra_ide_api/src/matching_brace.rs +++ b/crates/ra_ide_api/src/matching_brace.rs @@ -1,10 +1,4 @@ -use ra_syntax::{ - SourceFile, TextUnit, - algo::find_token_at_offset, - SyntaxKind::{self}, - ast::AstNode, - T -}; +use ra_syntax::{algo::find_token_at_offset, ast::AstNode, SourceFile, SyntaxKind, TextUnit, T}; pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option { const BRACES: &[SyntaxKind] = diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs index cb12dd0b120..4dbbd489aec 100644 --- a/crates/ra_ide_api/src/mock_analysis.rs +++ b/crates/ra_ide_api/src/mock_analysis.rs @@ -3,7 +3,10 @@ use std::sync::Arc; use relative_path::RelativePathBuf; use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; -use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId, Edition::Edition2018}; +use crate::{ + Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition::Edition2018, FileId, FilePosition, + FileRange, SourceRootId, +}; /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis /// from a set of in-memory files. diff --git a/crates/ra_ide_api/src/name_ref_kind.rs b/crates/ra_ide_api/src/name_ref_kind.rs index 000036db423..67381c9c8dd 100644 --- a/crates/ra_ide_api/src/name_ref_kind.rs +++ b/crates/ra_ide_api/src/name_ref_kind.rs @@ -1,5 +1,5 @@ -use ra_syntax::{AstNode, AstPtr, ast}; use hir::Either; +use ra_syntax::{ast, AstNode, AstPtr}; use test_utils::tested_by; use crate::db::RootDatabase; diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs index 27788c98462..7d5f9ea2c21 100644 --- a/crates/ra_ide_api/src/parent_module.rs +++ b/crates/ra_ide_api/src/parent_module.rs @@ -1,6 +1,6 @@ -use ra_db::{FilePosition, FileId, CrateId}; +use ra_db::{CrateId, FileId, FilePosition}; -use crate::{NavigationTarget, db::RootDatabase}; +use crate::{db::RootDatabase, NavigationTarget}; /// This returns `Vec` because a module may be included from several places. We /// don't handle this case yet though, so the Vec has length at most one. @@ -29,10 +29,10 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec { #[cfg(test)] mod tests { use crate::{ - AnalysisChange, CrateGraph, mock_analysis::{analysis_and_position, MockAnalysis}, + AnalysisChange, CrateGraph, Edition::Edition2018, -}; + }; #[test] fn test_resolve_parent_module() { diff --git a/crates/ra_ide_api/src/references.rs b/crates/ra_ide_api/src/references.rs index 12cdc6a6d16..766c0ad7430 100644 --- a/crates/ra_ide_api/src/references.rs +++ b/crates/ra_ide_api/src/references.rs @@ -1,22 +1,11 @@ +use hir::{source_binder, Either, ModuleSource}; +use ra_db::SourceDatabase; +use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SourceFile, SyntaxNode}; use relative_path::{RelativePath, RelativePathBuf}; -use hir::{ModuleSource, source_binder, Either}; -use ra_db::{SourceDatabase}; -use ra_syntax::{ - AstNode, SyntaxNode, SourceFile, - ast, - algo::find_node_at_offset, -}; use crate::{ - db::RootDatabase, - FilePosition, - FileRange, - FileId, - NavigationTarget, - FileSystemEdit, - SourceChange, - SourceFileEdit, - TextRange, + db::RootDatabase, FileId, FilePosition, FileRange, FileSystemEdit, NavigationTarget, + SourceChange, SourceFileEdit, TextRange, }; #[derive(Debug, Clone)] @@ -210,13 +199,12 @@ fn rename_reference( #[cfg(test)] mod tests { + use crate::{ + mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, + ReferenceSearchResult, + }; use insta::assert_debug_snapshot_matches; use test_utils::assert_eq_text; - use crate::{ - mock_analysis::single_file_with_position, - mock_analysis::analysis_and_position, - FileId, ReferenceSearchResult -}; #[test] fn test_find_all_refs_for_local() { diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index afe629d5016..2d2d0b40ef4 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs @@ -1,9 +1,9 @@ use itertools::Itertools; -use ra_syntax::{ - TextRange, SyntaxNode, - ast::{self, AstNode, NameOwner, ModuleItemOwner, AttrsOwner}, -}; use ra_db::SourceDatabase; +use ra_syntax::{ + ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner}, + SyntaxNode, TextRange, +}; use crate::{db::RootDatabase, FileId}; diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index ce25f4a875a..1bcba0b8bdb 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs @@ -1,20 +1,20 @@ -use std::{ - fmt, - iter::FromIterator, - sync::Arc, -}; +use std::{fmt, iter::FromIterator, sync::Arc}; -use ra_syntax::{TreeArc, SyntaxNode, Parse, AstNode}; -use ra_db::{ - FileTextQuery, SourceRootId, - salsa::{Database, debug::{DebugQueryTable, TableEntry}}, -}; -use ra_prof::{Bytes, memory_usage}; use hir::MacroFile; +use ra_db::{ + salsa::{ + debug::{DebugQueryTable, TableEntry}, + Database, + }, + FileTextQuery, SourceRootId, +}; +use ra_prof::{memory_usage, Bytes}; +use ra_syntax::{AstNode, Parse, SyntaxNode, TreeArc}; use crate::{ - FileId, db::RootDatabase, - symbol_index::{SymbolIndex, LibrarySymbolsQuery}, + db::RootDatabase, + symbol_index::{LibrarySymbolsQuery, SymbolIndex}, + FileId, }; pub(crate) fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats { diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs index a6cd7bf610b..2ca0a25d447 100644 --- a/crates/ra_ide_api/src/symbol_index.rs +++ b/crates/ra_ide_api/src/symbol_index.rs @@ -20,31 +20,27 @@ //! file in the current workspace, and run a query against the union of all //! those FSTs. use std::{ - hash::{Hash, Hasher}, - sync::Arc, - mem, fmt, + hash::{Hash, Hasher}, + mem, + sync::Arc, }; use fst::{self, Streamer}; -use ra_syntax::{ - SyntaxNode, SyntaxNodePtr, SourceFile, SmolStr, TreeArc, AstNode, - algo::{visit::{visitor, Visitor}}, - SyntaxKind::{self, *}, - ast::{self, NameOwner}, - WalkEvent, - TextRange, -}; use ra_db::{ - SourceRootId, SourceDatabase, salsa::{self, ParallelDatabase}, + SourceDatabase, SourceRootId, +}; +use ra_syntax::{ + algo::visit::{visitor, Visitor}, + ast::{self, NameOwner}, + AstNode, SmolStr, SourceFile, + SyntaxKind::{self, *}, + SyntaxNode, SyntaxNodePtr, TextRange, TreeArc, WalkEvent, }; use rayon::prelude::*; -use crate::{ - FileId, Query, - db::RootDatabase, -}; +use crate::{db::RootDatabase, FileId, Query}; #[salsa::query_group(SymbolsDatabaseStorage)] pub(crate) trait SymbolsDatabase: hir::db::HirDatabase { @@ -305,15 +301,11 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option { #[cfg(test)] mod tests { + use crate::{display::NavigationTarget, mock_analysis::single_file, Query}; use ra_syntax::{ SmolStr, - SyntaxKind::{FN_DEF, STRUCT_DEF} -}; - use crate::{ - display::NavigationTarget, - mock_analysis::single_file, - Query, -}; + SyntaxKind::{FN_DEF, STRUCT_DEF}, + }; #[test] fn test_world_symbols_with_no_container() { diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 3a04a51cd82..7c4285b0256 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -1,12 +1,12 @@ -use rustc_hash::{FxHashSet, FxHashMap}; +use rustc_hash::{FxHashMap, FxHashSet}; -use ra_syntax::{ - ast, AstNode, TextRange, Direction, SmolStr, SyntaxKind, SyntaxKind::*, SyntaxElement, T, -}; use ra_db::SourceDatabase; use ra_prof::profile; +use ra_syntax::{ + ast, AstNode, Direction, SmolStr, SyntaxElement, SyntaxKind, SyntaxKind::*, TextRange, T, +}; -use crate::{FileId, db::RootDatabase}; +use crate::{db::RootDatabase, FileId}; #[derive(Debug)] pub struct HighlightedRange { @@ -64,7 +64,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec Option { let file = db.parse(position.file_id).tree; diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index 9095bee894e..3851aadf24c 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs @@ -1,8 +1,9 @@ use lsp_types::{ - CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DocumentOnTypeFormattingOptions, - ExecuteCommandOptions, FoldingRangeProviderCapability, RenameOptions, RenameProviderCapability, + CodeActionProviderCapability, CodeLensOptions, CompletionOptions, + DocumentOnTypeFormattingOptions, ExecuteCommandOptions, FoldingRangeProviderCapability, + GenericCapability, ImplementationProviderCapability, RenameOptions, RenameProviderCapability, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability, TextDocumentSyncKind, - TextDocumentSyncOptions, ImplementationProviderCapability, GenericCapability, TypeDefinitionProviderCapability + TextDocumentSyncOptions, TypeDefinitionProviderCapability, }; pub fn server_capabilities() -> ServerCapabilities { diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs index 082ac8609c4..050c5fd950e 100644 --- a/crates/ra_lsp_server/src/cargo_target_spec.rs +++ b/crates/ra_lsp_server/src/cargo_target_spec.rs @@ -1,7 +1,7 @@ use crate::{ project_model::{self, TargetKind}, world::WorldSnapshot, - Result + Result, }; use ra_ide_api::{FileId, RunnableKind}; diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 25749258958..c8128f55bdd 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -1,13 +1,13 @@ use lsp_types::{ - self, CreateFile, Documentation, DocumentChangeOperation, DocumentChanges, Location, LocationLink, - MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, - TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, - WorkspaceEdit, + self, CreateFile, DocumentChangeOperation, DocumentChanges, Documentation, Location, + LocationLink, MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, SymbolKind, + TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams, Url, + VersionedTextDocumentIdentifier, WorkspaceEdit, }; use ra_ide_api::{ - CompletionItem, CompletionItemKind, FileId, FilePosition, FileRange, FileSystemEdit, - NavigationTarget, SourceChange, SourceFileEdit, RangeInfo, - LineCol, LineIndex, translate_offset_with_edit, InsertTextFormat + translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, + FileRange, FileSystemEdit, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, + SourceChange, SourceFileEdit, }; use ra_syntax::{SyntaxKind, TextRange, TextUnit}; use ra_text_edit::{AtomTextEdit, TextEdit}; diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 14cfa401f5c..56a263aa566 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs @@ -10,4 +10,7 @@ pub mod init; mod world; pub type Result = std::result::Result>; -pub use crate::{caps::server_capabilities, main_loop::main_loop, main_loop::LspError, init::InitializationOptions}; +pub use crate::{ + caps::server_capabilities, init::InitializationOptions, main_loop::main_loop, + main_loop::LspError, +}; diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 4aadb5ea87c..6aa6dd49fbb 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs @@ -1,8 +1,8 @@ -use serde::Deserialize; use flexi_logger::{Duplicate, Logger}; use gen_lsp_server::{run_server, stdio_transport}; +use serde::Deserialize; -use ra_lsp_server::{Result, InitializationOptions}; +use ra_lsp_server::{InitializationOptions, Result}; use ra_prof; fn main() -> Result<()> { diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index aeb8a22992a..cb73e65866d 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -2,7 +2,7 @@ mod handlers; mod subscriptions; pub(crate) mod pending_requests; -use std::{fmt, path::PathBuf, sync::Arc, time::Instant, error::Error}; +use std::{error::Error, fmt, path::PathBuf, sync::Arc, time::Instant}; use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender}; use gen_lsp_server::{ @@ -10,21 +10,20 @@ use gen_lsp_server::{ }; use lsp_types::NumberOrString; use ra_ide_api::{Canceled, FileId, LibraryData}; +use ra_prof::profile; use ra_vfs::VfsTask; use serde::{de::DeserializeOwned, Serialize}; use threadpool::ThreadPool; -use ra_prof::profile; use crate::{ main_loop::{ + pending_requests::{PendingRequest, PendingRequests}, subscriptions::Subscriptions, - pending_requests::{PendingRequests, PendingRequest}, }, project_model::workspace_loader, req, world::{WorldSnapshot, WorldState}, - Result, - InitializationOptions, + InitializationOptions, Result, }; const THREADPOOL_SIZE: usize = 8; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 47222cd0ac2..bbbc93b1cb3 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -1,22 +1,21 @@ -use std::{io::Write as _, fmt::Write as _}; +use std::{fmt::Write as _, io::Write as _}; use gen_lsp_server::ErrorCode; use lsp_types::{ - CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, CodeAction, - DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, - FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, - MarkupKind, Position, PrepareRenameResponse, Range, - RenameParams,SymbolInformation, TextDocumentIdentifier, TextEdit, - WorkspaceEdit, + CodeAction, CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity, + DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeKind, + FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, Position, + PrepareRenameResponse, Range, RenameParams, SymbolInformation, TextDocumentIdentifier, + TextEdit, WorkspaceEdit, }; use ra_ide_api::{ - FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, RunnableKind, Severity, Cancelable, - AssistId, + AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo, + RunnableKind, Severity, }; -use ra_syntax::{AstNode, SyntaxKind, TextUnit, TextRange}; use ra_prof::profile; +use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; use rustc_hash::FxHashMap; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use serde_json::to_value; use url_serde::Ser; diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs index 7d6440fadcc..1130d08de93 100644 --- a/crates/ra_lsp_server/src/project_model.rs +++ b/crates/ra_lsp_server/src/project_model.rs @@ -5,7 +5,7 @@ use thread_worker::Worker; use crate::Result; pub use ra_project_model::{ - ProjectWorkspace, CargoWorkspace, Package, Target, TargetKind, Sysroot, + CargoWorkspace, Package, ProjectWorkspace, Sysroot, Target, TargetKind, }; pub fn workspace_loader() -> Worker> { diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index 992c24eac3f..27f2deb3474 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -4,12 +4,11 @@ use serde::{Deserialize, Serialize}; use url_serde; pub use lsp_types::{ - notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, CodeLensParams, - CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, DocumentSymbolParams, - DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, - PublishDiagnosticsParams, ReferenceParams, SignatureHelp, TextDocumentEdit, - TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, - MessageType, ShowMessageParams, + notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, + CodeLensParams, CompletionParams, CompletionResponse, DocumentOnTypeFormattingParams, + DocumentSymbolParams, DocumentSymbolResponse, ExecuteCommandParams, Hover, InitializeResult, + MessageType, PublishDiagnosticsParams, ReferenceParams, ShowMessageParams, SignatureHelp, + TextDocumentEdit, TextDocumentPositionParams, TextEdit, WorkspaceEdit, WorkspaceSymbolParams, }; pub enum AnalyzerStatus {} diff --git a/crates/ra_lsp_server/src/vfs_filter.rs b/crates/ra_lsp_server/src/vfs_filter.rs index dd20c12031f..e16a57da567 100644 --- a/crates/ra_lsp_server/src/vfs_filter.rs +++ b/crates/ra_lsp_server/src/vfs_filter.rs @@ -1,6 +1,6 @@ -use std::path::PathBuf; use ra_project_model::ProjectRoot; -use ra_vfs::{RootEntry, Filter, RelativePath}; +use ra_vfs::{Filter, RelativePath, RootEntry}; +use std::path::PathBuf; /// `IncludeRustFiles` is used to convert /// from `ProjectRoot` to `RootEntry` for VFS diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 7822e1c1c5c..fdc577622ea 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -3,22 +3,20 @@ use std::{ sync::Arc, }; +use gen_lsp_server::ErrorCode; use lsp_types::Url; +use parking_lot::RwLock; use ra_ide_api::{ - Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, - SourceRootId + Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, }; use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; use relative_path::RelativePathBuf; -use parking_lot::RwLock; -use gen_lsp_server::ErrorCode; use crate::{ main_loop::pending_requests::{CompletedRequest, LatestRequests}, project_model::ProjectWorkspace, vfs_filter::IncludeRustFiles, - Result, - LspError, + LspError, Result, }; /// `WorldState` is the primary mutable state of the language server diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 40d825893e3..d271b02fc5f 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -1,16 +1,14 @@ mod support; -use std::{ - collections::HashMap, - time::Instant, -}; +use std::{collections::HashMap, time::Instant}; use lsp_types::{ - CodeActionContext, DocumentFormattingParams, FormattingOptions, Position, Range, DidOpenTextDocumentParams, TextDocumentItem, TextDocumentPositionParams + CodeActionContext, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions, + Position, Range, TextDocumentItem, TextDocumentPositionParams, }; use ra_lsp_server::req::{ - CodeActionParams, CodeActionRequest, Formatting, Runnables, RunnablesParams, CompletionParams, Completion, - DidOpenTextDocument, OnEnter, + CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument, + Formatting, OnEnter, Runnables, RunnablesParams, }; use serde_json::json; use tempfile::TempDir; diff --git a/crates/ra_lsp_server/tests/heavy_tests/support.rs b/crates/ra_lsp_server/tests/heavy_tests/support.rs index 75912afdd45..a5e352da155 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/support.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/support.rs @@ -11,20 +11,17 @@ use flexi_logger::Logger; use gen_lsp_server::{RawMessage, RawNotification, RawRequest}; use lsp_types::{ notification::DidOpenTextDocument, + notification::{Notification, ShowMessage}, request::{Request, Shutdown}, DidOpenTextDocumentParams, TextDocumentIdentifier, TextDocumentItem, Url, - notification::{Notification, ShowMessage}, }; use serde::Serialize; use serde_json::{to_string_pretty, Value}; use tempfile::TempDir; +use test_utils::{find_mismatch, parse_fixture}; use thread_worker::Worker; -use test_utils::{parse_fixture, find_mismatch}; -use ra_lsp_server::{ - main_loop, req, - InitializationOptions, -}; +use ra_lsp_server::{main_loop, req, InitializationOptions}; pub struct Project<'a> { fixture: &'a str, diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index c146252a48e..52c3d03b55d 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs @@ -41,14 +41,8 @@ pub enum ExpandError { } pub use crate::syntax_bridge::{ - ast_to_token_tree, - token_tree_to_ast_item_list, - syntax_node_to_token_tree, - token_tree_to_expr, - token_tree_to_pat, - token_tree_to_ty, - token_tree_to_macro_items, - token_tree_to_macro_stmts, + ast_to_token_tree, syntax_node_to_token_tree, token_tree_to_ast_item_list, token_tree_to_expr, + token_tree_to_macro_items, token_tree_to_macro_stmts, token_tree_to_pat, token_tree_to_ty, }; /// This struct contains AST for a single `macro_rules` definition. What might diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 55a6ecf587c..fbad8ebe2db 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs @@ -1,12 +1,12 @@ +use ra_syntax::SmolStr; /// This module takes a (parsed) definition of `macro_rules` invocation, a /// `tt::TokenTree` representing an argument of macro invocation, and produces a /// `tt::TokenTree` for the result of the expansion. use rustc_hash::FxHashMap; -use ra_syntax::SmolStr; use tt::TokenId; -use crate::ExpandError; use crate::tt_cursor::TtCursor; +use crate::ExpandError; pub(crate) fn expand( rules: &crate::MacroRules, diff --git a/crates/ra_mbe/src/mbe_parser.rs b/crates/ra_mbe/src/mbe_parser.rs index dca16b5376e..a2988585206 100644 --- a/crates/ra_mbe/src/mbe_parser.rs +++ b/crates/ra_mbe/src/mbe_parser.rs @@ -1,8 +1,8 @@ +use crate::tt_cursor::TtCursor; /// This module parses a raw `tt::TokenStream` into macro-by-example token /// stream. This is a *mostly* identify function, expect for handling of /// `$var:tt_kind` and `$(repeat),*` constructs. use crate::ParseError; -use crate::tt_cursor::TtCursor; pub(crate) fn parse(tt: &tt::Subtree) -> Result { let mut parser = TtCursor::new(tt); diff --git a/crates/ra_mbe/src/subtree_parser.rs b/crates/ra_mbe/src/subtree_parser.rs index 4a6f6aa45f8..5688e7f7fbb 100644 --- a/crates/ra_mbe/src/subtree_parser.rs +++ b/crates/ra_mbe/src/subtree_parser.rs @@ -1,8 +1,8 @@ use crate::subtree_source::SubtreeTokenSource; use ra_parser::{TokenSource, TreeSink}; -use ra_syntax::{SyntaxKind}; -use tt::buffer::{TokenBuffer, Cursor}; +use ra_syntax::SyntaxKind; +use tt::buffer::{Cursor, TokenBuffer}; struct OffsetTokenSink<'a> { cursor: Cursor<'a>, diff --git a/crates/ra_mbe/src/subtree_source.rs b/crates/ra_mbe/src/subtree_source.rs index 7647e16d8c2..2489c996bce 100644 --- a/crates/ra_mbe/src/subtree_source.rs +++ b/crates/ra_mbe/src/subtree_source.rs @@ -1,7 +1,7 @@ -use ra_parser::{TokenSource, Token}; +use ra_parser::{Token, TokenSource}; use ra_syntax::{classify_literal, SmolStr, SyntaxKind, SyntaxKind::*, T}; -use std::cell::{RefCell, Cell}; -use tt::buffer::{TokenBuffer, Cursor}; +use std::cell::{Cell, RefCell}; +use tt::buffer::{Cursor, TokenBuffer}; #[derive(Debug, Clone, Eq, PartialEq)] struct TtToken { diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index cb039ca376c..b91b0e7a5a0 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -1,11 +1,11 @@ -use ra_parser::{TreeSink, ParseError}; -use ra_syntax::{ - AstNode, SyntaxNode, TextRange, SyntaxKind, SmolStr, SyntaxTreeBuilder, TreeArc, SyntaxElement, - ast, SyntaxKind::*, TextUnit, T -}; -use tt::buffer::{TokenBuffer, Cursor}; -use crate::subtree_source::{SubtreeTokenSource}; +use crate::subtree_source::SubtreeTokenSource; use crate::ExpandError; +use ra_parser::{ParseError, TreeSink}; +use ra_syntax::{ + ast, AstNode, SmolStr, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxNode, SyntaxTreeBuilder, + TextRange, TextUnit, TreeArc, T, +}; +use tt::buffer::{Cursor, TokenBuffer}; /// Maps `tt::TokenId` to the relative range of the original token. #[derive(Default)] @@ -367,7 +367,7 @@ impl<'a> TreeSink for TtTreeSink<'a> { #[cfg(test)] mod tests { use super::*; - use crate::tests::{expand, create_rules}; + use crate::tests::{create_rules, expand}; use ra_parser::TokenSource; #[test] diff --git a/crates/ra_mbe/src/tt_cursor.rs b/crates/ra_mbe/src/tt_cursor.rs index d85ab43e407..503c77ef31d 100644 --- a/crates/ra_mbe/src/tt_cursor.rs +++ b/crates/ra_mbe/src/tt_cursor.rs @@ -1,6 +1,6 @@ -use crate::ParseError; use crate::subtree_parser::Parser; -use smallvec::{SmallVec, smallvec}; +use crate::ParseError; +use smallvec::{smallvec, SmallVec}; #[derive(Debug, Clone)] pub(crate) struct TtCursor<'a> { diff --git a/crates/ra_parser/src/event.rs b/crates/ra_parser/src/event.rs index 51beb086688..a7d06a815cb 100644 --- a/crates/ra_parser/src/event.rs +++ b/crates/ra_parser/src/event.rs @@ -10,8 +10,9 @@ use std::mem; use crate::{ - ParseError, TreeSink, + ParseError, SyntaxKind::{self, *}, + TreeSink, }; /// `Parser` produces a flat list of `Event`s. diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index 5997636d622..6580340975b 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -37,9 +37,9 @@ mod type_params; mod types; use crate::{ + parser::{CompletedMarker, Marker, Parser}, SyntaxKind::{self, *}, TokenSet, - parser::{CompletedMarker, Marker, Parser}, }; pub(crate) fn root(p: &mut Parser) { diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index 8a2e253ac96..159ed50dfd8 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs @@ -3,10 +3,10 @@ use std::cell::Cell; use drop_bomb::DropBomb; use crate::{ - SyntaxKind::{self, ERROR, EOF, TOMBSTONE}, - TokenSource, ParseError, TokenSet, event::Event, - T + ParseError, + SyntaxKind::{self, EOF, ERROR, TOMBSTONE}, + TokenSet, TokenSource, T, }; /// `Parser` struct provides the low-level API for diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index 6f79187456f..919cc1b3cef 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs @@ -2,18 +2,21 @@ mod memory_usage; use std::{ cell::RefCell, - time::{Duration, Instant}, - mem, + collections::HashSet, io::{stderr, Write}, iter::repeat, - collections::HashSet, - sync::{RwLock, atomic::{AtomicBool, Ordering}}, + mem, + sync::{ + atomic::{AtomicBool, Ordering}, + RwLock, + }, + time::{Duration, Instant}, }; -use once_cell::sync::Lazy; use itertools::Itertools; +use once_cell::sync::Lazy; -pub use crate::memory_usage::{MemoryUsage, Bytes}; +pub use crate::memory_usage::{Bytes, MemoryUsage}; // We use jemalloc mainly to get heap usage statistics, actual performance // difference is not measures. diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index d5ebf2c7a84..2b06e9e372c 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs @@ -1,9 +1,9 @@ use std::path::{Path, PathBuf}; -use cargo_metadata::{MetadataCommand, CargoOpt}; -use ra_arena::{Arena, RawId, impl_arena_id}; -use rustc_hash::FxHashMap; +use cargo_metadata::{CargoOpt, MetadataCommand}; +use ra_arena::{impl_arena_id, Arena, RawId}; use ra_db::Edition; +use rustc_hash::FxHashMap; use crate::Result; diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 42156bea6fe..74b7efa9ad9 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -3,15 +3,15 @@ mod json_project; mod sysroot; use std::{ + error::Error, fs::File, io::BufReader, path::{Path, PathBuf}, - error::Error }; use rustc_hash::FxHashMap; -use ra_db::{CrateGraph, FileId, Edition}; +use ra_db::{CrateGraph, Edition, FileId}; use serde_json::from_reader; diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 9e0d8aaac73..a419b81e8b5 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs @@ -3,7 +3,7 @@ use std::{ process::Command, }; -use ra_arena::{Arena, RawId, impl_arena_id}; +use ra_arena::{impl_arena_id, Arena, RawId}; use crate::Result; diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index d31d0034332..fad8da13235 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs @@ -2,7 +2,7 @@ pub mod visit; use itertools::Itertools; -use crate::{SyntaxNode, TextRange, TextUnit, AstNode, Direction, SyntaxToken, SyntaxElement}; +use crate::{AstNode, Direction, SyntaxElement, SyntaxNode, SyntaxToken, TextRange, TextUnit}; pub use rowan::TokenAtOffset; diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 319110b6a7b..3dcf39f7e16 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -9,16 +9,16 @@ mod expr_extensions; use std::marker::PhantomData; use crate::{ - syntax_node::{SyntaxNode, SyntaxNodeChildren, TreeArc, SyntaxToken}, + syntax_node::{SyntaxNode, SyntaxNodeChildren, SyntaxToken, TreeArc}, SmolStr, }; pub use self::{ + expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp}, + extensions::{FieldKind, PathSegmentKind, SelfParamKind, StructKind}, generated::*, - traits::*, tokens::*, - extensions::{PathSegmentKind, StructKind,FieldKind, SelfParamKind}, - expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind,ArrayExprKind}, + traits::*, }; /// The main trait to go from untyped `SyntaxNode` to a typed ast. The diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index d88671d45e0..87dbb0ea5e1 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -1,10 +1,10 @@ //! Various extension methods to ast Expr Nodes, which are hard to code-generate. use crate::{ - SyntaxToken, SyntaxElement, SmolStr, - ast::{self, AstNode, AstChildren, children, child_opt}, + ast::{self, child_opt, children, AstChildren, AstNode}, + SmolStr, SyntaxElement, SyntaxKind::*, - T + SyntaxToken, T, }; #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 930b2d9fadf..72a30232df2 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -4,10 +4,10 @@ use itertools::Itertools; use crate::{ - SmolStr, SyntaxToken, - ast::{self, AstNode, children, child_opt}, + ast::{self, child_opt, children, AstNode}, + SmolStr, SyntaxElement, SyntaxKind::*, - SyntaxElement, T, + SyntaxToken, T, }; use ra_parser::SyntaxKind; diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 08882ea69b3..be63b3c9e5c 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs @@ -1,9 +1,9 @@ //! There are many AstNodes, but only a few tokens, so we hand-write them here. use crate::{ - SyntaxToken, - SyntaxKind::{COMMENT, WHITESPACE}, ast::AstToken, + SyntaxKind::{COMMENT, WHITESPACE}, + SyntaxToken, }; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -61,7 +61,7 @@ pub enum CommentPlacement { } const COMMENT_PREFIX_TO_KIND: &[(&str, CommentKind)] = { - use {CommentShape::*, CommentPlacement::*}; + use {CommentPlacement::*, CommentShape::*}; &[ ("///", CommentKind { shape: Line, doc: Some(Outer) }), ("//!", CommentKind { shape: Line, doc: Some(Inner) }), diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 43348540082..29cb53e35ba 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -5,8 +5,8 @@ use itertools::Itertools; use crate::{ - syntax_node::{SyntaxNodeChildren, SyntaxElementChildren}, - ast::{self, child_opt, children, AstNode, AstToken, AstChildren}, + ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, + syntax_node::{SyntaxElementChildren, SyntaxNodeChildren}, }; pub trait TypeAscriptionOwner: AstNode { diff --git a/crates/ra_syntax/src/fuzz.rs b/crates/ra_syntax/src/fuzz.rs index 6a9905bd14f..6d114aad409 100644 --- a/crates/ra_syntax/src/fuzz.rs +++ b/crates/ra_syntax/src/fuzz.rs @@ -1,4 +1,4 @@ -use crate::{SourceFile, validation, TextUnit, TextRange, AstNode}; +use crate::{validation, AstNode, SourceFile, TextRange, TextUnit}; use ra_text_edit::AtomTextEdit; use std::str::{self, FromStr}; diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index e46ad12dbf1..9790a984d52 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -31,23 +31,26 @@ pub mod ast; #[doc(hidden)] pub mod fuzz; -use std::{sync::Arc, fmt::Write}; +use std::{fmt::Write, sync::Arc}; use ra_text_edit::AtomTextEdit; use crate::syntax_node::GreenNode; -pub use rowan::{SmolStr, TextRange, TextUnit}; -pub use ra_parser::SyntaxKind; -pub use ra_parser::T; pub use crate::{ ast::AstNode, - syntax_error::{SyntaxError, SyntaxErrorKind, Location}, + parsing::{classify_literal, tokenize, Token}, + ptr::{AstPtr, SyntaxNodePtr}, + syntax_error::{Location, SyntaxError, SyntaxErrorKind}, + syntax_node::{ + Direction, InsertPosition, SyntaxElement, SyntaxNode, SyntaxToken, SyntaxTreeBuilder, + TreeArc, WalkEvent, + }, syntax_text::SyntaxText, - syntax_node::{Direction, SyntaxNode, WalkEvent, TreeArc, SyntaxTreeBuilder, SyntaxElement, SyntaxToken, InsertPosition}, - ptr::{SyntaxNodePtr, AstPtr}, - parsing::{tokenize, classify_literal, Token}, }; +pub use ra_parser::SyntaxKind; +pub use ra_parser::T; +pub use rowan::{SmolStr, TextRange, TextUnit}; /// `Parse` is the result of the parsing: a syntax tree and a collection of /// errors. diff --git a/crates/ra_syntax/src/parsing.rs b/crates/ra_syntax/src/parsing.rs index 4c1fa6c4f37..0387f037806 100644 --- a/crates/ra_syntax/src/parsing.rs +++ b/crates/ra_syntax/src/parsing.rs @@ -6,12 +6,9 @@ mod text_token_source; mod text_tree_sink; mod reparsing; -use crate::{ - SyntaxError, - syntax_node::GreenNode, -}; +use crate::{syntax_node::GreenNode, SyntaxError}; -pub use self::lexer::{tokenize, classify_literal, Token}; +pub use self::lexer::{classify_literal, tokenize, Token}; pub(crate) use self::reparsing::incremental_reparse; diff --git a/crates/ra_syntax/src/parsing/lexer.rs b/crates/ra_syntax/src/parsing/lexer.rs index 6eb96f03da0..60cf37047d7 100644 --- a/crates/ra_syntax/src/parsing/lexer.rs +++ b/crates/ra_syntax/src/parsing/lexer.rs @@ -6,8 +6,7 @@ mod strings; use crate::{ SyntaxKind::{self, *}, - TextUnit, - T, + TextUnit, T, }; use self::{ diff --git a/crates/ra_syntax/src/parsing/lexer/numbers.rs b/crates/ra_syntax/src/parsing/lexer/numbers.rs index 874fb8b320d..e53ae231b33 100644 --- a/crates/ra_syntax/src/parsing/lexer/numbers.rs +++ b/crates/ra_syntax/src/parsing/lexer/numbers.rs @@ -1,7 +1,4 @@ -use crate::parsing::lexer::{ - ptr::Ptr, - classes::*, -}; +use crate::parsing::lexer::{classes::*, ptr::Ptr}; use crate::SyntaxKind::{self, *}; diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs index cf27a339343..eeca94020d8 100644 --- a/crates/ra_syntax/src/parsing/reparsing.rs +++ b/crates/ra_syntax/src/parsing/reparsing.rs @@ -6,19 +6,20 @@ //! - otherwise, we search for the nearest `{}` block which contains the edit //! and try to parse only this block. -use ra_text_edit::AtomTextEdit; use ra_parser::Reparser; +use ra_text_edit::AtomTextEdit; use crate::{ - SyntaxKind::*, TextRange, TextUnit, SyntaxError, algo, - syntax_node::{GreenNode, SyntaxNode, GreenToken, SyntaxElement}, parsing::{ + lexer::{tokenize, Token}, text_token_source::TextTokenSource, text_tree_sink::TextTreeSink, - lexer::{tokenize, Token}, }, - T, + syntax_node::{GreenNode, GreenToken, SyntaxElement, SyntaxNode}, + SyntaxError, + SyntaxKind::*, + TextRange, TextUnit, T, }; pub(crate) fn incremental_reparse( @@ -168,10 +169,10 @@ fn merge_errors( mod tests { use std::sync::Arc; - use test_utils::{extract_range, assert_eq_text}; + use test_utils::{assert_eq_text, extract_range}; - use crate::{SourceFile, AstNode, Parse}; use super::*; + use crate::{AstNode, Parse, SourceFile}; fn do_check(before: &str, replace_with: &str, reparsed_len: u32) { let (range, before) = extract_range(before); diff --git a/crates/ra_syntax/src/parsing/text_token_source.rs b/crates/ra_syntax/src/parsing/text_token_source.rs index 71d2947f775..f592b499fd2 100644 --- a/crates/ra_syntax/src/parsing/text_token_source.rs +++ b/crates/ra_syntax/src/parsing/text_token_source.rs @@ -1,10 +1,7 @@ -use ra_parser::TokenSource; use ra_parser::Token as PToken; +use ra_parser::TokenSource; -use crate::{ - SyntaxKind::EOF, TextRange, TextUnit, - parsing::lexer::Token, -}; +use crate::{parsing::lexer::Token, SyntaxKind::EOF, TextRange, TextUnit}; pub(crate) struct TextTokenSource<'t> { text: &'t str, diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs index 71fc515f2ea..bf1b35c95a3 100644 --- a/crates/ra_syntax/src/parsing/text_tree_sink.rs +++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs @@ -1,12 +1,13 @@ use std::mem; -use ra_parser::{TreeSink, ParseError}; +use ra_parser::{ParseError, TreeSink}; use crate::{ - SmolStr, SyntaxError, TextUnit, TextRange, SyntaxTreeBuilder, - SyntaxKind::{self, *}, parsing::Token, syntax_node::GreenNode, + SmolStr, SyntaxError, + SyntaxKind::{self, *}, + SyntaxTreeBuilder, TextRange, TextUnit, }; /// Bridges the parser with our specific syntax tree representation. diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index 10cddb85283..0550dca1a1b 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs @@ -1,10 +1,5 @@ -use std::{ - marker::PhantomData, - iter::successors, -}; -use crate::{ - AstNode, SyntaxKind, SyntaxNode, TextRange, -}; +use crate::{AstNode, SyntaxKind, SyntaxNode, TextRange}; +use std::{iter::successors, marker::PhantomData}; /// A pointer to a syntax node inside a file. It can be used to remember a /// specific node across reparses of the same file. diff --git a/crates/ra_syntax/src/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs index d29c0cf6c70..5aefec768fc 100644 --- a/crates/ra_syntax/src/syntax_error.rs +++ b/crates/ra_syntax/src/syntax_error.rs @@ -2,10 +2,7 @@ use std::fmt; use ra_parser::ParseError; -use crate::{ - TextRange, TextUnit, - validation::EscapeError, -}; +use crate::{validation::EscapeError, TextRange, TextUnit}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SyntaxError { diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index 4105b522094..80c8639c8f4 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs @@ -7,18 +7,18 @@ //! modules just wraps its API. use std::{ - ops::RangeInclusive, - fmt::{self, Write}, borrow::Borrow, + fmt::{self, Write}, iter::successors, + ops::RangeInclusive, }; use ra_parser::ParseError; -use rowan::{TransparentNewType, GreenNodeBuilder}; +use rowan::{GreenNodeBuilder, TransparentNewType}; use crate::{ - SmolStr, SyntaxKind, TextUnit, TextRange, SyntaxText, SourceFile, AstNode, SyntaxNodePtr, syntax_error::{SyntaxError, SyntaxErrorKind}, + AstNode, SmolStr, SourceFile, SyntaxKind, SyntaxNodePtr, SyntaxText, TextRange, TextUnit, }; pub use rowan::WalkEvent; diff --git a/crates/ra_syntax/src/syntax_text.rs b/crates/ra_syntax/src/syntax_text.rs index c9038cd5c06..e648dc082d9 100644 --- a/crates/ra_syntax/src/syntax_text.rs +++ b/crates/ra_syntax/src/syntax_text.rs @@ -1,6 +1,9 @@ -use std::{fmt, ops::{self, Bound}}; +use std::{ + fmt, + ops::{self, Bound}, +}; -use crate::{SmolStr, SyntaxNode, TextRange, TextUnit, SyntaxElement}; +use crate::{SmolStr, SyntaxElement, SyntaxNode, TextRange, TextUnit}; #[derive(Clone)] pub struct SyntaxText<'a> { diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index b53900a4bbf..87522ec181c 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs @@ -4,11 +4,10 @@ mod block; mod field_expr; use crate::{ - SourceFile, SyntaxError, AstNode, SyntaxNode, TextUnit, - SyntaxKind::{BYTE, BYTE_STRING, STRING, CHAR}, - ast, algo::visit::{visitor_ctx, VisitorCtx}, - T, + ast, AstNode, SourceFile, SyntaxError, + SyntaxKind::{BYTE, BYTE_STRING, CHAR, STRING}, + SyntaxNode, TextUnit, T, }; pub(crate) use unescape::EscapeError; diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs index f2cf3cbbd88..46650d9b0b9 100644 --- a/crates/ra_syntax/src/validation/block.rs +++ b/crates/ra_syntax/src/validation/block.rs @@ -1,7 +1,8 @@ -use crate::{SyntaxKind::*, - ast::{self, AttrsOwner, AstNode}, +use crate::{ + ast::{self, AstNode, AttrsOwner}, SyntaxError, SyntaxErrorKind::*, + SyntaxKind::*, }; pub(crate) fn validate_block_node(node: &ast::Block, errors: &mut Vec) { diff --git a/crates/ra_syntax/src/validation/field_expr.rs b/crates/ra_syntax/src/validation/field_expr.rs index 2b405062e21..d3020edf783 100644 --- a/crates/ra_syntax/src/validation/field_expr.rs +++ b/crates/ra_syntax/src/validation/field_expr.rs @@ -1,6 +1,7 @@ -use crate::{ast::{self, FieldKind}, - SyntaxError, - SyntaxErrorKind::*, +use crate::{ + ast::{self, FieldKind}, + SyntaxError, + SyntaxErrorKind::*, }; pub(crate) fn validate_field_expr_node(node: &ast::FieldExpr, errors: &mut Vec) { diff --git a/crates/ra_syntax/src/validation/unescape.rs b/crates/ra_syntax/src/validation/unescape.rs index 91dbcfae87f..4c3a7effc0d 100644 --- a/crates/ra_syntax/src/validation/unescape.rs +++ b/crates/ra_syntax/src/validation/unescape.rs @@ -7,8 +7,8 @@ //! //! Hopefully, we'll share this code in a proper way some day -use std::str::Chars; use std::ops::Range; +use std::str::Chars; #[derive(Debug, PartialEq, Eq, Clone, Hash)] pub enum EscapeError { diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index f31e12588e4..2442c850584 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs @@ -4,11 +4,11 @@ extern crate walkdir; use std::{ fmt::Write, - path::{PathBuf, Component}, + path::{Component, PathBuf}, }; -use test_utils::{project_dir, dir_tests, read_text, collect_tests}; -use ra_syntax::{SourceFile, fuzz}; +use ra_syntax::{fuzz, SourceFile}; +use test_utils::{collect_tests, dir_tests, project_dir, read_text}; #[test] fn lexer_tests() { diff --git a/crates/ra_text_edit/src/test_utils.rs b/crates/ra_text_edit/src/test_utils.rs index 2dc0e71af26..2d6e7f2163b 100644 --- a/crates/ra_text_edit/src/test_utils.rs +++ b/crates/ra_text_edit/src/test_utils.rs @@ -1,6 +1,6 @@ -use proptest::prelude::*; -use text_unit::{TextUnit, TextRange}; use crate::{AtomTextEdit, TextEdit}; +use proptest::prelude::*; +use text_unit::{TextRange, TextUnit}; pub fn arb_text() -> proptest::string::RegexGeneratorStrategy { // generate multiple newlines diff --git a/crates/ra_tools/src/bin/pre-commit.rs b/crates/ra_tools/src/bin/pre-commit.rs index 95bb55cae98..a628f64b24b 100644 --- a/crates/ra_tools/src/bin/pre-commit.rs +++ b/crates/ra_tools/src/bin/pre-commit.rs @@ -1,6 +1,6 @@ use std::process::Command; -use ra_tools::{Result, run_rustfmt, run, project_root, Overwrite}; +use ra_tools::{project_root, run, run_rustfmt, Overwrite, Result}; fn main() -> Result<()> { run_rustfmt(Overwrite)?; diff --git a/crates/ra_tools/src/lib.rs b/crates/ra_tools/src/lib.rs index 821209567db..d56e0d2efd4 100644 --- a/crates/ra_tools/src/lib.rs +++ b/crates/ra_tools/src/lib.rs @@ -1,10 +1,10 @@ use std::{ - fs, collections::HashMap, + error::Error, + fs, + io::{Error as IoError, ErrorKind}, path::{Path, PathBuf}, process::{Command, Output, Stdio}, - io::{Error as IoError, ErrorKind}, - error::Error }; use itertools::Itertools; diff --git a/crates/ra_tools/src/main.rs b/crates/ra_tools/src/main.rs index 846e0223e0c..7ed592f71cd 100644 --- a/crates/ra_tools/src/main.rs +++ b/crates/ra_tools/src/main.rs @@ -1,10 +1,10 @@ use clap::{App, SubCommand}; use core::str; use ra_tools::{ - generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, - Overwrite, Result, run_fuzzer, run_clippy, + gen_tests, generate, install_format_hook, run, run_clippy, run_fuzzer, run_rustfmt, + run_with_output, Overwrite, Result, }; -use std::{path::{PathBuf}, env}; +use std::{env, path::PathBuf}; fn main() -> Result<()> { let matches = App::new("tasks") diff --git a/crates/ra_tools/tests/cli.rs b/crates/ra_tools/tests/cli.rs index 83640218f7f..ae0eb337d21 100644 --- a/crates/ra_tools/tests/cli.rs +++ b/crates/ra_tools/tests/cli.rs @@ -1,6 +1,6 @@ use walkdir::WalkDir; -use ra_tools::{generate, gen_tests, run_rustfmt, Verify, project_root}; +use ra_tools::{gen_tests, generate, project_root, run_rustfmt, Verify}; #[test] fn generated_grammar_is_fresh() { diff --git a/crates/ra_tt/src/buffer.rs b/crates/ra_tt/src/buffer.rs index 5659aeae8bf..48c22a2d8a3 100644 --- a/crates/ra_tt/src/buffer.rs +++ b/crates/ra_tt/src/buffer.rs @@ -1,4 +1,4 @@ -use crate::{TokenTree, Subtree}; +use crate::{Subtree, TokenTree}; #[derive(Copy, Clone, Debug, Eq, PartialEq)] struct EntryId(usize); diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 8bb3b3937f2..ea99ac06293 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -3,11 +3,11 @@ pub mod marks; use std::{ fs, - path::{Path, PathBuf} + path::{Path, PathBuf}, }; -use text_unit::{TextRange, TextUnit}; use serde_json::Value; +use text_unit::{TextRange, TextUnit}; pub use difference::Changeset as __Changeset; diff --git a/rustfmt.toml b/rustfmt.toml index 63d651a85f6..71007de81b9 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,2 @@ -reorder_imports = false reorder_modules = false use_small_heuristics = "Max"