cargo fmt

This commit is contained in:
BenjaminBrienen 2025-03-10 12:42:27 +01:00
parent 87f837cec7
commit 7535bb4661
571 changed files with 2210 additions and 2458 deletions

View file

@ -24,17 +24,19 @@ pub(crate) mod vis;
use std::iter;
use hir::{sym, HasAttrs, Name, ScopeDef, Variant};
use ide_db::{imports::import_assets::LocatedImport, RootDatabase, SymbolKind};
use syntax::{ast, SmolStr, ToSmolStr};
use hir::{HasAttrs, Name, ScopeDef, Variant, sym};
use ide_db::{RootDatabase, SymbolKind, imports::import_assets::LocatedImport};
use syntax::{SmolStr, ToSmolStr, ast};
use crate::{
CompletionContext, CompletionItem, CompletionItemKind,
context::{
DotAccess, ItemListKind, NameContext, NameKind, NameRefContext, NameRefKind,
PathCompletionCtx, PathKind, PatternContext, TypeLocation, Visible,
},
item::Builder,
render::{
RenderContext,
const_::render_const,
function::{render_fn, render_method},
literal::{render_struct_literal, render_variant_lit},
@ -44,9 +46,7 @@ use crate::{
render_tuple_field,
type_alias::{render_type_alias, render_type_alias_with_eq},
union_literal::render_union_literal,
RenderContext,
},
CompletionContext, CompletionItem, CompletionItemKind,
};
/// Represents an in-progress set of completions being built.

View file

@ -5,22 +5,22 @@
use std::sync::LazyLock;
use ide_db::{
FxHashMap, SymbolKind,
generated::lints::{
Lint, CLIPPY_LINTS, CLIPPY_LINT_GROUPS, DEFAULT_LINTS, FEATURES, RUSTDOC_LINTS,
CLIPPY_LINT_GROUPS, CLIPPY_LINTS, DEFAULT_LINTS, FEATURES, Lint, RUSTDOC_LINTS,
},
syntax_helpers::node_ext::parse_tt_as_comma_sep_paths,
FxHashMap, SymbolKind,
};
use itertools::Itertools;
use syntax::{
ast::{self, AttrKind},
AstNode, Edition, SyntaxKind, T,
ast::{self, AttrKind},
};
use crate::{
Completions,
context::{AttrCtx, CompletionContext, PathCompletionCtx, Qualified},
item::CompletionItem,
Completions,
};
mod cfg;

View file

@ -2,9 +2,9 @@
use ide_db::SymbolKind;
use itertools::Itertools;
use syntax::{algo, ast::Ident, AstToken, Direction, NodeOrToken, SyntaxKind};
use syntax::{AstToken, Direction, NodeOrToken, SyntaxKind, algo, ast::Ident};
use crate::{completions::Completions, context::CompletionContext, CompletionItem};
use crate::{CompletionItem, completions::Completions, context::CompletionContext};
pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext<'_>) {
let add_completion = |item: &str| {

View file

@ -1,13 +1,13 @@
//! Completion for derives
use hir::ScopeDef;
use ide_db::{documentation::HasDocs, SymbolKind};
use ide_db::{SymbolKind, documentation::HasDocs};
use itertools::Itertools;
use syntax::{SmolStr, ToSmolStr};
use crate::{
Completions,
context::{CompletionContext, ExistingDerives, PathCompletionCtx, Qualified},
item::CompletionItem,
Completions,
};
pub(crate) fn complete_derive_path(

View file

@ -1,8 +1,8 @@
//! Completion for lints
use ide_db::{documentation::Documentation, generated::lints::Lint, SymbolKind};
use ide_db::{SymbolKind, documentation::Documentation, generated::lints::Lint};
use syntax::ast;
use crate::{context::CompletionContext, item::CompletionItem, Completions};
use crate::{Completions, context::CompletionContext, item::CompletionItem};
pub(super) fn complete_lint(
acc: &mut Completions,

View file

@ -3,7 +3,7 @@ use hir::ModuleDef;
use ide_db::SymbolKind;
use syntax::ast;
use crate::{context::CompletionContext, item::CompletionItem, Completions};
use crate::{Completions, context::CompletionContext, item::CompletionItem};
pub(super) fn complete_macro_use(
acc: &mut Completions,

View file

@ -3,7 +3,7 @@
use ide_db::SymbolKind;
use syntax::ast;
use crate::{context::CompletionContext, item::CompletionItem, Completions};
use crate::{Completions, context::CompletionContext, item::CompletionItem};
pub(super) fn complete_repr(
acc: &mut Completions,

View file

@ -7,11 +7,11 @@ use ide_db::FxHashSet;
use syntax::SmolStr;
use crate::{
CompletionItem, CompletionItemKind, Completions,
context::{
CompletionContext, DotAccess, DotAccessExprCtx, DotAccessKind, PathCompletionCtx,
PathExprCtx, Qualified,
},
CompletionItem, CompletionItemKind, Completions,
};
/// Complete dot accesses, i.e. fields or methods.

View file

@ -3,34 +3,46 @@
use hir::MacroFileIdExt;
use ide_db::syntax_helpers::node_ext::macro_call_for_string_token;
use syntax::{
ast::{self, IsString},
AstToken,
ast::{self, IsString},
};
use crate::{
completions::Completions, context::CompletionContext, CompletionItem, CompletionItemKind,
CompletionItem, CompletionItemKind, completions::Completions, context::CompletionContext,
};
const CARGO_DEFINED_VARS: &[(&str, &str)] = &[
("CARGO","Path to the cargo binary performing the build"),
("CARGO_MANIFEST_DIR","The directory containing the manifest of your package"),
("CARGO_PKG_VERSION","The full version of your package"),
("CARGO_PKG_VERSION_MAJOR","The major version of your package"),
("CARGO_PKG_VERSION_MINOR","The minor version of your package"),
("CARGO_PKG_VERSION_PATCH","The patch version of your package"),
("CARGO_PKG_VERSION_PRE","The pre-release version of your package"),
("CARGO_PKG_AUTHORS","Colon separated list of authors from the manifest of your package"),
("CARGO_PKG_NAME","The name of your package"),
("CARGO_PKG_DESCRIPTION","The description from the manifest of your package"),
("CARGO_PKG_HOMEPAGE","The home page from the manifest of your package"),
("CARGO_PKG_REPOSITORY","The repository from the manifest of your package"),
("CARGO_PKG_LICENSE","The license from the manifest of your package"),
("CARGO_PKG_LICENSE_FILE","The license file from the manifest of your package"),
("CARGO_PKG_RUST_VERSION","The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version"),
("CARGO_CRATE_NAME","The name of the crate that is currently being compiled"),
("CARGO_BIN_NAME","The name of the binary that is currently being compiled (if it is a binary). This name does not include any file extension, such as .exe"),
("CARGO_PRIMARY_PACKAGE","This environment variable will be set if the package being built is primary. Primary packages are the ones the user selected on the command-line, either with -p flags or the defaults based on the current directory and the default workspace members. This environment variable will not be set when building dependencies. This is only set when compiling the package (not when running binaries or tests)"),
("CARGO_TARGET_TMPDIR","Only set when building integration test or benchmark code. This is a path to a directory inside the target directory where integration tests or benchmarks are free to put any data needed by the tests/benches. Cargo initially creates this directory but doesn't manage its content in any way, this is the responsibility of the test code")
("CARGO", "Path to the cargo binary performing the build"),
("CARGO_MANIFEST_DIR", "The directory containing the manifest of your package"),
("CARGO_PKG_VERSION", "The full version of your package"),
("CARGO_PKG_VERSION_MAJOR", "The major version of your package"),
("CARGO_PKG_VERSION_MINOR", "The minor version of your package"),
("CARGO_PKG_VERSION_PATCH", "The patch version of your package"),
("CARGO_PKG_VERSION_PRE", "The pre-release version of your package"),
("CARGO_PKG_AUTHORS", "Colon separated list of authors from the manifest of your package"),
("CARGO_PKG_NAME", "The name of your package"),
("CARGO_PKG_DESCRIPTION", "The description from the manifest of your package"),
("CARGO_PKG_HOMEPAGE", "The home page from the manifest of your package"),
("CARGO_PKG_REPOSITORY", "The repository from the manifest of your package"),
("CARGO_PKG_LICENSE", "The license from the manifest of your package"),
("CARGO_PKG_LICENSE_FILE", "The license file from the manifest of your package"),
(
"CARGO_PKG_RUST_VERSION",
"The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version",
),
("CARGO_CRATE_NAME", "The name of the crate that is currently being compiled"),
(
"CARGO_BIN_NAME",
"The name of the binary that is currently being compiled (if it is a binary). This name does not include any file extension, such as .exe",
),
(
"CARGO_PRIMARY_PACKAGE",
"This environment variable will be set if the package being built is primary. Primary packages are the ones the user selected on the command-line, either with -p flags or the defaults based on the current directory and the default workspace members. This environment variable will not be set when building dependencies. This is only set when compiling the package (not when running binaries or tests)",
),
(
"CARGO_TARGET_TMPDIR",
"Only set when building integration test or benchmark code. This is a path to a directory inside the target directory where integration tests or benchmarks are free to put any data needed by the tests/benches. Cargo initially creates this directory but doesn't manage its content in any way, this is the responsibility of the test code",
),
];
pub(crate) fn complete_cargo_env_vars(

View file

@ -2,14 +2,14 @@
use std::ops::ControlFlow;
use hir::{sym, Name, PathCandidateCallback, ScopeDef};
use hir::{Name, PathCandidateCallback, ScopeDef, sym};
use ide_db::FxHashSet;
use syntax::ast;
use crate::{
CompletionContext, Completions,
completions::record::add_default_update,
context::{BreakableKind, PathCompletionCtx, PathExprCtx, Qualified},
CompletionContext, Completions,
};
struct PathCallback<'a, F> {
@ -79,11 +79,7 @@ pub(crate) fn complete_expr_path(
let wants_const_token =
ref_expr_parent.is_some() && has_raw_token && !has_const_token && !has_mut_token;
let wants_mut_token = if ref_expr_parent.is_some() {
if has_raw_token {
!has_const_token && !has_mut_token
} else {
!has_mut_token
}
if has_raw_token { !has_const_token && !has_mut_token } else { !has_mut_token }
} else {
false
};

View file

@ -1,11 +1,11 @@
//! Completes function abi strings.
use syntax::{
ast::{self, IsString},
AstNode, AstToken, SmolStr,
ast::{self, IsString},
};
use crate::{
completions::Completions, context::CompletionContext, CompletionItem, CompletionItemKind,
CompletionItem, CompletionItemKind, completions::Completions, context::CompletionContext,
};
// Most of these are feature gated, we should filter/add feature gate completions once we have them.

View file

@ -1,10 +1,10 @@
//! Completion for extern crates
use hir::Name;
use ide_db::{documentation::HasDocs, SymbolKind};
use ide_db::{SymbolKind, documentation::HasDocs};
use syntax::ToSmolStr;
use crate::{context::CompletionContext, CompletionItem, CompletionItemKind};
use crate::{CompletionItem, CompletionItemKind, context::CompletionContext};
use super::Completions;

View file

@ -1,8 +1,8 @@
//! Completion of field list position.
use crate::{
context::{PathCompletionCtx, Qualified},
CompletionContext, Completions,
context::{PathCompletionCtx, Qualified},
};
pub(crate) fn complete_field_list_tuple_variant(

View file

@ -5,16 +5,16 @@ use ide_db::imports::{
insert_use::ImportScope,
};
use itertools::Itertools;
use syntax::{ast, AstNode, SyntaxNode};
use syntax::{AstNode, SyntaxNode, ast};
use crate::{
Completions,
config::AutoImportExclusionType,
context::{
CompletionContext, DotAccess, PathCompletionCtx, PathKind, PatternContext, Qualified,
TypeLocation,
},
render::{render_resolution_with_import, render_resolution_with_import_pat, RenderContext},
Completions,
render::{RenderContext, render_resolution_with_import, render_resolution_with_import_pat},
};
// Feature: Completion With Autoimport
@ -404,11 +404,7 @@ fn import_on_the_fly_method(
fn import_name(ctx: &CompletionContext<'_>) -> String {
let token_kind = ctx.token.kind();
if token_kind.is_any_identifier() {
ctx.token.to_string()
} else {
String::new()
}
if token_kind.is_any_identifier() { ctx.token.to_string() } else { String::new() }
}
fn import_assets_for_path(

View file

@ -3,14 +3,14 @@
use hir::HirDisplay;
use ide_db::FxHashMap;
use syntax::{
algo,
AstNode, Direction, SyntaxKind, TextRange, TextSize, algo,
ast::{self, HasModuleItem},
match_ast, AstNode, Direction, SyntaxKind, TextRange, TextSize,
match_ast,
};
use crate::{
context::{ParamContext, ParamKind, PatternContext},
CompletionContext, CompletionItem, CompletionItemKind, Completions,
context::{ParamContext, ParamKind, PatternContext},
};
// FIXME: Make this a submodule of [`pattern`]

View file

@ -1,11 +1,11 @@
//! Completes identifiers in format string literals.
use hir::{ModuleDef, ScopeDef};
use ide_db::{syntax_helpers::format_string::is_format_string, SymbolKind};
use ide_db::{SymbolKind, syntax_helpers::format_string::is_format_string};
use itertools::Itertools;
use syntax::{ast, AstToken, TextRange, TextSize, ToSmolStr};
use syntax::{AstToken, TextRange, TextSize, ToSmolStr, ast};
use crate::{context::CompletionContext, CompletionItem, CompletionItemKind, Completions};
use crate::{CompletionItem, CompletionItemKind, Completions, context::CompletionContext};
/// Complete identifiers in format strings.
pub(crate) fn format_string(

View file

@ -1,8 +1,8 @@
//! Completion of paths and keywords at item list position.
use crate::{
context::{ItemListKind, PathCompletionCtx, PathExprCtx, Qualified},
CompletionContext, Completions,
context::{ItemListKind, PathCompletionCtx, PathExprCtx, Qualified},
};
pub(crate) mod trait_impl;

View file

@ -31,20 +31,21 @@
//! }
//! ```
use hir::{db::ExpandDatabase, MacroFileId, Name};
use hir::{MacroFileId, Name, db::ExpandDatabase};
use ide_db::text_edit::TextEdit;
use ide_db::{
documentation::HasDocs, path_transform::PathTransform,
syntax_helpers::prettify_macro_expansion, traits::get_missing_assoc_items, SymbolKind,
SymbolKind, documentation::HasDocs, path_transform::PathTransform,
syntax_helpers::prettify_macro_expansion, traits::get_missing_assoc_items,
};
use syntax::{
ast::{self, edit_in_place::AttrsOwnerEdit, make, HasGenericArgs, HasTypeBounds},
format_smolstr, ted, AstNode, SmolStr, SyntaxElement, SyntaxKind, TextRange, ToSmolStr, T,
AstNode, SmolStr, SyntaxElement, SyntaxKind, T, TextRange, ToSmolStr,
ast::{self, HasGenericArgs, HasTypeBounds, edit_in_place::AttrsOwnerEdit, make},
format_smolstr, ted,
};
use crate::{
context::PathCompletionCtx, CompletionContext, CompletionItem, CompletionItemKind,
CompletionRelevance, Completions,
CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
context::PathCompletionCtx,
};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

View file

@ -7,7 +7,7 @@
//! there is no value in lifting these out into the outline module test since they will either not
//! show up for normal completions, or they won't show completions other than lifetimes depending
//! on the fixture input.
use hir::{sym, Name, ScopeDef};
use hir::{Name, ScopeDef, sym};
use crate::{
completions::Completions,

View file

@ -4,12 +4,12 @@ use std::iter;
use hir::{HirFileIdExt, Module};
use ide_db::{
base_db::{SourceDatabase, VfsPath},
FxHashSet, RootDatabase, SymbolKind,
base_db::{SourceDatabase, VfsPath},
};
use syntax::{ast, AstNode, SyntaxKind};
use syntax::{AstNode, SyntaxKind, ast};
use crate::{context::CompletionContext, CompletionItem, Completions};
use crate::{CompletionItem, Completions, context::CompletionContext};
/// Complete mod declaration, i.e. `mod $0;`
pub(crate) fn complete_mod(

View file

@ -5,8 +5,8 @@ use ide_db::syntax_helpers::suggest_name;
use syntax::ast::Pat;
use crate::{
context::{PathCompletionCtx, PatternContext, PatternRefutability, Qualified},
CompletionContext, Completions,
context::{PathCompletionCtx, PatternContext, PatternRefutability, Qualified},
};
/// Completes constants and paths in unqualified patterns.

View file

@ -5,24 +5,24 @@ mod format_like;
use base_db::SourceDatabase;
use hir::{ItemInNs, Semantics};
use ide_db::{
RootDatabase, SnippetCap,
documentation::{Documentation, HasDocs},
imports::insert_use::ImportScope,
text_edit::TextEdit,
ty_filter::TryEnum,
RootDatabase, SnippetCap,
};
use stdx::never;
use syntax::{
ast::{self, AstNode, AstToken},
SyntaxKind::{BLOCK_EXPR, EXPR_STMT, FOR_EXPR, IF_EXPR, LOOP_EXPR, STMT_LIST, WHILE_EXPR},
TextRange, TextSize,
ast::{self, AstNode, AstToken},
};
use crate::{
CompletionItem, CompletionItemKind, CompletionRelevance, Completions, SnippetScope,
completions::postfix::format_like::add_format_like_completions,
context::{BreakableKind, CompletionContext, DotAccess, DotAccessKind},
item::{Builder, CompletionRelevancePostfixMatch},
CompletionItem, CompletionItemKind, CompletionRelevance, Completions, SnippetScope,
};
pub(crate) fn complete_postfix(
@ -414,8 +414,8 @@ mod tests {
use expect_test::expect;
use crate::{
tests::{check, check_edit, check_edit_with_config, TEST_CONFIG},
CompletionConfig, Snippet,
tests::{TEST_CONFIG, check, check_edit, check_edit_with_config},
};
#[test]
@ -697,15 +697,17 @@ fn main() {
#[test]
fn custom_postfix_completion() {
let config = CompletionConfig {
snippets: vec![Snippet::new(
&[],
&["break".into()],
&["ControlFlow::Break(${receiver})".into()],
"",
&["core::ops::ControlFlow".into()],
crate::SnippetScope::Expr,
)
.unwrap()],
snippets: vec![
Snippet::new(
&[],
&["break".into()],
&["ControlFlow::Break(${receiver})".into()],
"",
&["core::ops::ControlFlow".into()],
crate::SnippetScope::Expr,
)
.unwrap(),
],
..TEST_CONFIG
};

View file

@ -17,15 +17,15 @@
// ![Format String Completion](https://user-images.githubusercontent.com/48062697/113020656-b560f500-917a-11eb-87de-02991f61beb8.gif)
use ide_db::{
syntax_helpers::format_string_exprs::{parse_format_exprs, with_placeholders, Arg},
SnippetCap,
syntax_helpers::format_string_exprs::{Arg, parse_format_exprs, with_placeholders},
};
use syntax::{ast, AstToken};
use syntax::{AstToken, ast};
use crate::{
Completions,
completions::postfix::{build_postfix_snippet_builder, escape_snippet_bits},
context::CompletionContext,
Completions,
};
/// Mapping ("postfix completion item" => "macro to use")

View file

@ -1,14 +1,14 @@
//! Complete fields in record literals and patterns.
use ide_db::SymbolKind;
use syntax::{
ast::{self, Expr},
SmolStr,
ast::{self, Expr},
};
use crate::{
context::{DotAccess, DotAccessExprCtx, DotAccessKind, PatternContext},
CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance,
CompletionRelevancePostfixMatch, Completions,
context::{DotAccess, DotAccessExprCtx, DotAccessKind, PatternContext},
};
pub(crate) fn complete_record_pattern_fields(
@ -144,8 +144,8 @@ mod tests {
use ide_db::SnippetCap;
use crate::{
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
CompletionConfig,
tests::{TEST_CONFIG, check_edit, check_edit_with_config},
};
#[test]

View file

@ -1,11 +1,11 @@
//! This file provides snippet completions, like `pd` => `eprintln!(...)`.
use ide_db::{documentation::Documentation, imports::insert_use::ImportScope, SnippetCap};
use ide_db::{SnippetCap, documentation::Documentation, imports::insert_use::ImportScope};
use crate::{
CompletionContext, CompletionItem, CompletionItemKind, Completions, SnippetScope,
context::{ItemListKind, PathCompletionCtx, PathExprCtx, Qualified},
item::Builder,
CompletionContext, CompletionItem, CompletionItemKind, Completions, SnippetScope,
};
pub(crate) fn complete_expr_snippet(
@ -153,23 +153,25 @@ fn add_custom_completions(
#[cfg(test)]
mod tests {
use crate::{
tests::{check_edit_with_config, TEST_CONFIG},
CompletionConfig, Snippet,
tests::{TEST_CONFIG, check_edit_with_config},
};
#[test]
fn custom_snippet_completion() {
check_edit_with_config(
CompletionConfig {
snippets: vec![Snippet::new(
&["break".into()],
&[],
&["ControlFlow::Break(())".into()],
"",
&["core::ops::ControlFlow".into()],
crate::SnippetScope::Expr,
)
.unwrap()],
snippets: vec![
Snippet::new(
&["break".into()],
&[],
&["ControlFlow::Break(())".into()],
"",
&["core::ops::ControlFlow".into()],
crate::SnippetScope::Expr,
)
.unwrap(),
],
..TEST_CONFIG
},
"break",

View file

@ -1,12 +1,12 @@
//! Completion of names from the current scope in type position.
use hir::{HirDisplay, ScopeDef};
use syntax::{ast, AstNode};
use syntax::{AstNode, ast};
use crate::{
CompletionContext, Completions,
context::{PathCompletionCtx, Qualified, TypeAscriptionTarget, TypeLocation},
render::render_type_inference,
CompletionContext, Completions,
};
pub(crate) fn complete_type_path(

View file

@ -2,12 +2,12 @@
use hir::ScopeDef;
use ide_db::{FxHashSet, SymbolKind};
use syntax::{ast, format_smolstr, AstNode};
use syntax::{AstNode, ast, format_smolstr};
use crate::{
CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
context::{CompletionContext, PathCompletionCtx, Qualified},
item::Builder,
CompletionItem, CompletionItemKind, CompletionRelevance, Completions,
};
pub(crate) fn complete_use_path(

View file

@ -1,8 +1,8 @@
//! Completion for visibility specifiers.
use crate::{
context::{CompletionContext, PathCompletionCtx, Qualified},
Completions,
context::{CompletionContext, PathCompletionCtx, Qualified},
};
pub(crate) fn complete_vis_path(

View file

@ -5,9 +5,9 @@
//! completions if we are allowed to.
use hir::ImportPathConfig;
use ide_db::{imports::insert_use::InsertUseConfig, SnippetCap};
use ide_db::{SnippetCap, imports::insert_use::InsertUseConfig};
use crate::{snippet::Snippet, CompletionFieldsToResolve};
use crate::{CompletionFieldsToResolve, snippet::Snippet};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompletionConfig<'a> {

View file

@ -6,26 +6,27 @@ mod tests;
use std::{iter, ops::ControlFlow};
use base_db::{salsa::AsDynDatabase, RootQueryDb as _};
use base_db::{RootQueryDb as _, salsa::AsDynDatabase};
use hir::{
DisplayTarget, HasAttrs, Local, ModPath, ModuleDef, ModuleSource, Name, PathResolution,
ScopeDef, Semantics, SemanticsScope, Symbol, Type, TypeInfo,
};
use ide_db::{
famous_defs::FamousDefs, helpers::is_editable_crate, FilePosition, FxHashMap, FxHashSet,
RootDatabase,
FilePosition, FxHashMap, FxHashSet, RootDatabase, famous_defs::FamousDefs,
helpers::is_editable_crate,
};
use syntax::{
ast::{self, AttrKind, NameOrNameRef},
match_ast, AstNode, Edition, SmolStr,
AstNode, Edition, SmolStr,
SyntaxKind::{self, *},
SyntaxToken, TextRange, TextSize, T,
SyntaxToken, T, TextRange, TextSize,
ast::{self, AttrKind, NameOrNameRef},
match_ast,
};
use crate::{
config::AutoImportExclusionType,
context::analysis::{expand_and_analyze, AnalysisResult},
CompletionConfig,
config::AutoImportExclusionType,
context::analysis::{AnalysisResult, expand_and_analyze},
};
const COMPLETION_MARKER: &str = "raCompletionMarker";
@ -676,11 +677,7 @@ impl CompletionContext<'_> {
};
}
if self.is_doc_hidden(attrs, defining_crate) {
Visible::No
} else {
Visible::Yes
}
if self.is_doc_hidden(attrs, defining_crate) { Visible::No } else { Visible::Yes }
}
pub(crate) fn is_doc_hidden(&self, attrs: &hir::Attrs, defining_crate: hir::Crate) -> bool {

View file

@ -2,24 +2,25 @@
use std::iter;
use hir::{ExpandResult, Semantics, Type, TypeInfo, Variant};
use ide_db::{active_parameter::ActiveParameter, RootDatabase};
use ide_db::{RootDatabase, active_parameter::ActiveParameter};
use itertools::Either;
use syntax::{
AstNode, AstToken, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken,
T, TextRange, TextSize,
algo::{self, ancestors_at_offset, find_node_at_offset, non_trivia_sibling},
ast::{
self, AttrKind, HasArgList, HasGenericArgs, HasGenericParams, HasLoopBody, HasName,
NameOrNameRef,
},
match_ast, AstNode, AstToken, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode,
SyntaxToken, TextRange, TextSize, T,
match_ast,
};
use crate::context::{
AttrCtx, BreakableKind, CompletionAnalysis, DotAccess, DotAccessExprCtx, DotAccessKind,
ItemListKind, LifetimeContext, LifetimeKind, NameContext, NameKind, NameRefContext,
NameRefKind, ParamContext, ParamKind, PathCompletionCtx, PathExprCtx, PathKind, PatternContext,
PatternRefutability, Qualified, QualifierCtx, TypeAscriptionTarget, TypeLocation,
COMPLETION_MARKER,
AttrCtx, BreakableKind, COMPLETION_MARKER, CompletionAnalysis, DotAccess, DotAccessExprCtx,
DotAccessKind, ItemListKind, LifetimeContext, LifetimeKind, NameContext, NameKind,
NameRefContext, NameRefKind, ParamContext, ParamKind, PathCompletionCtx, PathExprCtx, PathKind,
PatternContext, PatternRefutability, Qualified, QualifierCtx, TypeAscriptionTarget,
TypeLocation,
};
#[derive(Debug)]

View file

@ -1,9 +1,9 @@
use expect_test::{expect, Expect};
use expect_test::{Expect, expect};
use hir::HirDisplay;
use crate::{
context::CompletionContext,
tests::{position, TEST_CONFIG},
tests::{TEST_CONFIG, position},
};
fn check_expected_type_and_name(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {

View file

@ -5,17 +5,17 @@ use std::{fmt, mem};
use hir::Mutability;
use ide_db::text_edit::TextEdit;
use ide_db::{
documentation::Documentation, imports::import_assets::LocatedImport, RootDatabase, SnippetCap,
SymbolKind,
RootDatabase, SnippetCap, SymbolKind, documentation::Documentation,
imports::import_assets::LocatedImport,
};
use itertools::Itertools;
use smallvec::SmallVec;
use stdx::{format_to, impl_from, never};
use syntax::{format_smolstr, Edition, SmolStr, TextRange, TextSize};
use syntax::{Edition, SmolStr, TextRange, TextSize, format_smolstr};
use crate::{
context::{CompletionContext, PathCompletionCtx},
render::{render_path_resolution, RenderContext},
render::{RenderContext, render_path_resolution},
};
/// `CompletionItem` describes a single completion entity which expands to 1 or more entries in the

View file

@ -11,11 +11,11 @@ mod snippet;
mod tests;
use ide_db::{
FilePosition, FxHashSet, RootDatabase,
base_db::salsa::AsDynDatabase,
imports::insert_use::{self, ImportScope},
syntax_helpers::tree_diff::diff,
text_edit::TextEdit,
FilePosition, FxHashSet, RootDatabase,
};
use syntax::ast::make;

View file

@ -10,17 +10,19 @@ pub(crate) mod type_alias;
pub(crate) mod union_literal;
pub(crate) mod variant;
use hir::{sym, AsAssocItem, HasAttrs, HirDisplay, ModuleDef, ScopeDef, Type};
use hir::{AsAssocItem, HasAttrs, HirDisplay, ModuleDef, ScopeDef, Type, sym};
use ide_db::text_edit::TextEdit;
use ide_db::{
RootDatabase, SnippetCap, SymbolKind,
documentation::{Documentation, HasDocs},
helpers::item_name,
imports::import_assets::LocatedImport,
RootDatabase, SnippetCap, SymbolKind,
};
use syntax::{ast, format_smolstr, AstNode, SmolStr, SyntaxKind, TextRange, ToSmolStr};
use syntax::{AstNode, SmolStr, SyntaxKind, TextRange, ToSmolStr, ast, format_smolstr};
use crate::{
CompletionContext, CompletionItem, CompletionItemKind, CompletionItemRefMode,
CompletionRelevance,
context::{DotAccess, DotAccessKind, PathCompletionCtx, PathKind, PatternContext},
item::{Builder, CompletionRelevanceTypeMatch},
render::{
@ -28,8 +30,6 @@ use crate::{
literal::render_variant_lit,
macro_::{render_macro, render_macro_pat},
},
CompletionContext, CompletionItem, CompletionItemKind, CompletionItemRefMode,
CompletionRelevance,
};
/// Interface for data and methods required for items rendering.
#[derive(Debug, Clone)]
@ -683,14 +683,14 @@ fn path_ref_match(
mod tests {
use std::cmp;
use expect_test::{expect, Expect};
use expect_test::{Expect, expect};
use ide_db::SymbolKind;
use itertools::Itertools;
use crate::{
item::CompletionRelevanceTypeMatch,
tests::{check_edit, do_completion, get_all_items, TEST_CONFIG},
CompletionItem, CompletionItemKind, CompletionRelevance, CompletionRelevancePostfixMatch,
item::CompletionRelevanceTypeMatch,
tests::{TEST_CONFIG, check_edit, do_completion, get_all_items},
};
#[track_caller]

View file

@ -1,12 +1,13 @@
//! Renderer for function calls.
use hir::{db::HirDatabase, AsAssocItem, HirDisplay};
use hir::{AsAssocItem, HirDisplay, db::HirDatabase};
use ide_db::{SnippetCap, SymbolKind};
use itertools::Itertools;
use stdx::{format_to, to_lower_snake_case};
use syntax::{format_smolstr, AstNode, SmolStr, ToSmolStr};
use syntax::{AstNode, SmolStr, ToSmolStr, format_smolstr};
use crate::{
CallableSnippets,
context::{
CompleteSemicolon, CompletionContext, DotAccess, DotAccessKind, PathCompletionCtx, PathKind,
},
@ -15,9 +16,8 @@ use crate::{
CompletionRelevanceReturnType, CompletionRelevanceTraitInfo,
},
render::{
compute_exact_name_match, compute_ref_match, compute_type_match, match_types, RenderContext,
RenderContext, compute_exact_name_match, compute_ref_match, compute_type_match, match_types,
},
CallableSnippets,
};
#[derive(Debug)]
@ -293,11 +293,7 @@ fn ref_of_param(ctx: &CompletionContext<'_>, arg: &str, ty: &hir::Type) -> &'sta
for (name, local) in ctx.locals.iter().sorted_by_key(|&(k, _)| k.clone()) {
if name.as_str() == arg {
return if local.ty(ctx.db) == derefed_ty {
if ty.is_mutable_reference() {
"&mut "
} else {
"&"
}
if ty.is_mutable_reference() { "&mut " } else { "&" }
} else {
""
};
@ -398,8 +394,8 @@ fn params(
#[cfg(test)]
mod tests {
use crate::{
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
CallableSnippets, CompletionConfig,
tests::{TEST_CONFIG, check_edit, check_edit_with_config},
};
#[test]

View file

@ -1,23 +1,22 @@
//! Renderer for `enum` variants.
use hir::{db::HirDatabase, StructKind};
use hir::{StructKind, db::HirDatabase};
use ide_db::{
documentation::{Documentation, HasDocs},
SymbolKind,
documentation::{Documentation, HasDocs},
};
use crate::{
CompletionItemKind, CompletionRelevance, CompletionRelevanceReturnType,
context::{CompletionContext, PathCompletionCtx, PathKind},
item::{Builder, CompletionItem, CompletionRelevanceFn},
render::{
compute_type_match,
RenderContext, compute_type_match,
variant::{
format_literal_label, format_literal_lookup, render_record_lit, render_tuple_lit,
visible_fields, RenderedLiteral,
RenderedLiteral, format_literal_label, format_literal_lookup, render_record_lit,
render_tuple_lit, visible_fields,
},
RenderContext,
},
CompletionItemKind, CompletionRelevance, CompletionRelevanceReturnType,
};
pub(crate) fn render_variant_lit(
@ -164,11 +163,7 @@ impl Variant {
Variant::Struct(it) => visible_fields(ctx, &fields, it)?,
Variant::EnumVariant(it) => visible_fields(ctx, &fields, it)?,
};
if !fields_omitted {
Some(visible_fields)
} else {
None
}
if !fields_omitted { Some(visible_fields) } else { None }
}
fn kind(self, db: &dyn HirDatabase) -> StructKind {

View file

@ -1,8 +1,8 @@
//! Renderer for macro invocations.
use hir::HirDisplay;
use ide_db::{documentation::Documentation, SymbolKind};
use syntax::{format_smolstr, SmolStr, ToSmolStr};
use ide_db::{SymbolKind, documentation::Documentation};
use syntax::{SmolStr, ToSmolStr, format_smolstr};
use crate::{
context::{PathCompletionCtx, PathKind, PatternContext},

View file

@ -1,17 +1,17 @@
//! Renderer for patterns.
use hir::{db::HirDatabase, Name, StructKind};
use ide_db::{documentation::HasDocs, SnippetCap};
use hir::{Name, StructKind, db::HirDatabase};
use ide_db::{SnippetCap, documentation::HasDocs};
use itertools::Itertools;
use syntax::{Edition, SmolStr, ToSmolStr};
use crate::{
CompletionItem, CompletionItemKind,
context::{ParamContext, ParamKind, PathCompletionCtx, PatternContext},
render::{
variant::{format_literal_label, format_literal_lookup, visible_fields},
RenderContext,
variant::{format_literal_label, format_literal_lookup, visible_fields},
},
CompletionItem, CompletionItemKind,
};
pub(crate) fn render_struct_pat(

View file

@ -6,11 +6,11 @@ use itertools::Itertools;
use syntax::ToSmolStr;
use crate::{
render::{
variant::{format_literal_label, format_literal_lookup, visible_fields},
RenderContext,
},
CompletionItem, CompletionItemKind,
render::{
RenderContext,
variant::{format_literal_label, format_literal_lookup, visible_fields},
},
};
pub(crate) fn render_union_literal(

View file

@ -1,7 +1,7 @@
//! Code common to structs, unions, and enum variants.
use crate::context::CompletionContext;
use hir::{sym, HasAttrs, HasCrate, HasVisibility, HirDisplay, StructKind};
use hir::{HasAttrs, HasCrate, HasVisibility, HirDisplay, StructKind, sym};
use ide_db::SnippetCap;
use itertools::Itertools;
use syntax::SmolStr;

View file

@ -28,8 +28,8 @@ use base_db::SourceDatabase;
use expect_test::Expect;
use hir::PrefixKind;
use ide_db::{
imports::insert_use::{ImportGranularity, InsertUseConfig},
FilePosition, RootDatabase, SnippetCap,
imports::insert_use::{ImportGranularity, InsertUseConfig},
};
use itertools::Itertools;
use stdx::{format_to, trim_indent};
@ -37,8 +37,8 @@ use test_fixture::ChangeFixture;
use test_utils::assert_eq_text;
use crate::{
resolve_completion_edits, CallableSnippets, CompletionConfig, CompletionFieldsToResolve,
CompletionItem, CompletionItemKind,
CallableSnippets, CompletionConfig, CompletionFieldsToResolve, CompletionItem,
CompletionItemKind, resolve_completion_edits,
};
/// Lots of basic item definitions

View file

@ -1,13 +1,13 @@
//! Completion tests for expressions.
use expect_test::{expect, Expect};
use expect_test::{Expect, expect};
use crate::{
CompletionConfig,
config::AutoImportExclusionType,
tests::{
check, check_edit, check_with_base_items, completion_list_with_config, BASE_ITEMS_FIXTURE,
TEST_CONFIG,
BASE_ITEMS_FIXTURE, TEST_CONFIG, check, check_edit, check_with_base_items,
completion_list_with_config,
},
CompletionConfig,
};
fn check_with_config(

View file

@ -1,9 +1,9 @@
use expect_test::{expect, Expect};
use expect_test::{Expect, expect};
use crate::{
context::{CompletionAnalysis, NameContext, NameKind, NameRefKind},
tests::{check_edit, check_edit_with_config, TEST_CONFIG},
CompletionConfig,
context::{CompletionAnalysis, NameContext, NameKind, NameRefKind},
tests::{TEST_CONFIG, check_edit, check_edit_with_config},
};
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {

View file

@ -1,8 +1,8 @@
use base_db::SourceDatabase;
use expect_test::{expect, Expect};
use expect_test::{Expect, expect};
use itertools::Itertools;
use crate::tests::{completion_list_with_config_raw, position, TEST_CONFIG};
use crate::tests::{TEST_CONFIG, completion_list_with_config_raw, position};
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
let completions = completion_list_with_config_raw(TEST_CONFIG, ra_fixture, true, None);

View file

@ -1,14 +1,14 @@
//! Tests that don't fit into a specific category.
use expect_test::{expect, Expect};
use expect_test::{Expect, expect};
use ide_db::SymbolKind;
use crate::{
tests::{
check, check_edit, check_no_kw, check_with_trigger_character, do_completion_with_config,
TEST_CONFIG,
},
CompletionItemKind,
tests::{
TEST_CONFIG, check, check_edit, check_no_kw, check_with_trigger_character,
do_completion_with_config,
},
};
#[test]