mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Also consider associated constants
This commit is contained in:
parent
f65daf23df
commit
3ccf8b746a
@ -115,7 +115,7 @@ impl AutoImportAssets {
|
|||||||
match &self.import_candidate {
|
match &self.import_candidate {
|
||||||
ImportCandidate::UnqualifiedName(name) => name,
|
ImportCandidate::UnqualifiedName(name) => name,
|
||||||
ImportCandidate::QualifierStart(qualifier_start) => qualifier_start,
|
ImportCandidate::QualifierStart(qualifier_start) => qualifier_start,
|
||||||
ImportCandidate::TraitFunction(_, trait_function_name) => trait_function_name,
|
ImportCandidate::TraitAssocItem(_, trait_function_name) => trait_function_name,
|
||||||
ImportCandidate::TraitMethod(_, trait_method_name) => trait_method_name,
|
ImportCandidate::TraitMethod(_, trait_method_name) => trait_method_name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,8 +126,8 @@ impl AutoImportAssets {
|
|||||||
ImportCandidate::QualifierStart(qualifier_start) => {
|
ImportCandidate::QualifierStart(qualifier_start) => {
|
||||||
format!("Import {}", qualifier_start)
|
format!("Import {}", qualifier_start)
|
||||||
}
|
}
|
||||||
ImportCandidate::TraitFunction(_, trait_function_name) => {
|
ImportCandidate::TraitAssocItem(_, trait_function_name) => {
|
||||||
format!("Import a trait for function {}", trait_function_name)
|
format!("Import a trait for item {}", trait_function_name)
|
||||||
}
|
}
|
||||||
ImportCandidate::TraitMethod(_, trait_method_name) => {
|
ImportCandidate::TraitMethod(_, trait_method_name) => {
|
||||||
format!("Import a trait for method {}", trait_method_name)
|
format!("Import a trait for method {}", trait_method_name)
|
||||||
@ -142,7 +142,7 @@ impl AutoImportAssets {
|
|||||||
.find_imports(&self.get_search_query())
|
.find_imports(&self.get_search_query())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|module_def| match &self.import_candidate {
|
.map(|module_def| match &self.import_candidate {
|
||||||
ImportCandidate::TraitFunction(function_callee, _) => {
|
ImportCandidate::TraitAssocItem(function_callee, _) => {
|
||||||
let mut applicable_traits = Vec::new();
|
let mut applicable_traits = Vec::new();
|
||||||
if let ModuleDef::Function(located_function) = module_def {
|
if let ModuleDef::Function(located_function) = module_def {
|
||||||
let trait_candidates: FxHashSet<_> =
|
let trait_candidates: FxHashSet<_> =
|
||||||
@ -255,10 +255,10 @@ enum ImportCandidate {
|
|||||||
/// First part of the qualified name.
|
/// First part of the qualified name.
|
||||||
/// For 'std::collections::HashMap', that will be 'std'.
|
/// For 'std::collections::HashMap', that will be 'std'.
|
||||||
QualifierStart(String),
|
QualifierStart(String),
|
||||||
/// A trait function that has no self parameter.
|
/// A trait associated function (with no self parameter) or associated constant.
|
||||||
/// For 'test_mod::TestEnum::test_function', `Type` is the `test_mod::TestEnum` expression type
|
/// For 'test_mod::TestEnum::test_function', `Type` is the `test_mod::TestEnum` expression type
|
||||||
/// and `String` is the `test_function`
|
/// and `String` is the `test_function`
|
||||||
TraitFunction(Type, String),
|
TraitAssocItem(Type, String),
|
||||||
/// A trait method with self parameter.
|
/// A trait method with self parameter.
|
||||||
/// For 'test_enum.test_method()', `Type` is the `test_enum` expression type
|
/// For 'test_enum.test_method()', `Type` is the `test_enum` expression type
|
||||||
/// and `String` is the `test_method`
|
/// and `String` is the `test_method`
|
||||||
@ -303,7 +303,7 @@ impl ImportCandidate {
|
|||||||
source_analyzer.resolve_path(db, &qualifier)?
|
source_analyzer.resolve_path(db, &qualifier)?
|
||||||
};
|
};
|
||||||
if let PathResolution::Def(ModuleDef::Adt(function_callee)) = qualifier_resolution {
|
if let PathResolution::Def(ModuleDef::Adt(function_callee)) = qualifier_resolution {
|
||||||
Some(ImportCandidate::TraitFunction(
|
Some(ImportCandidate::TraitAssocItem(
|
||||||
function_callee.ty(db),
|
function_callee.ty(db),
|
||||||
segment.syntax().to_string(),
|
segment.syntax().to_string(),
|
||||||
))
|
))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user