mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Adjust the assist group name
This commit is contained in:
parent
24f7028d3f
commit
07058cbf9f
@ -1,9 +1,3 @@
|
|||||||
use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase};
|
|
||||||
use ra_syntax::{
|
|
||||||
ast::{self, AstNode},
|
|
||||||
SyntaxNode,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_ctx::{Assist, AssistCtx},
|
assist_ctx::{Assist, AssistCtx},
|
||||||
insert_use_statement, AssistId,
|
insert_use_statement, AssistId,
|
||||||
@ -13,7 +7,12 @@ use hir::{
|
|||||||
AssocContainerId, AssocItem, Crate, Function, ModPath, Module, ModuleDef, PathResolution,
|
AssocContainerId, AssocItem, Crate, Function, ModPath, Module, ModuleDef, PathResolution,
|
||||||
SourceAnalyzer, Trait, Type,
|
SourceAnalyzer, Trait, Type,
|
||||||
};
|
};
|
||||||
|
use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase};
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
|
use ra_syntax::{
|
||||||
|
ast::{self, AstNode},
|
||||||
|
SyntaxNode,
|
||||||
|
};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
@ -50,9 +49,13 @@ pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut group =
|
let assist_group_name = if proposed_imports.len() == 1 {
|
||||||
// TODO kb create another method and add something about traits there
|
format!("Import `{}`", proposed_imports.iter().next().unwrap())
|
||||||
ctx.add_assist_group(format!("Import {}", auto_import_assets.get_search_query()));
|
} else {
|
||||||
|
auto_import_assets.get_import_group_message()
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut group = ctx.add_assist_group(assist_group_name);
|
||||||
for import in proposed_imports {
|
for import in proposed_imports {
|
||||||
group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| {
|
group.add_assist(AssistId("auto_import"), format!("Import `{}`", &import), |edit| {
|
||||||
edit.target(auto_import_assets.syntax_under_caret.text_range());
|
edit.target(auto_import_assets.syntax_under_caret.text_range());
|
||||||
@ -119,6 +122,19 @@ impl AutoImportAssets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_import_group_message(&self) -> String {
|
||||||
|
match &self.import_candidate {
|
||||||
|
ImportCandidate::UnqualifiedName(name_ref)
|
||||||
|
| ImportCandidate::QualifierStart(name_ref) => format!("Import {}", name_ref.syntax()),
|
||||||
|
ImportCandidate::TraitFunction(_, trait_function) => {
|
||||||
|
format!("Import a trait for function {}", trait_function.syntax())
|
||||||
|
}
|
||||||
|
ImportCandidate::TraitMethod(_, trait_method) => {
|
||||||
|
format!("Import a trait for method {}", trait_method.syntax())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn search_for_imports(
|
fn search_for_imports(
|
||||||
&self,
|
&self,
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user