mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Show substitution where hovering over generic things
There are few things to note in the implementation: First, this is a best-effort implementation. Mainly, type aliases may not be shown (due to their eager nature it's harder) and partial pathes (aka. hovering over `Struct` in `Struct::method`) are not supported at all. Second, we only need to show substitutions in expression and pattern position, because in type position all generic arguments always have to be written explicitly.
This commit is contained in:
parent
27e824fad4
commit
b5486ffc42
29 changed files with 1019 additions and 190 deletions
|
@ -49,10 +49,10 @@ use crate::{
|
|||
semantics::source_to_def::{ChildContainer, SourceToDefCache, SourceToDefCtx},
|
||||
source_analyzer::{name_hygiene, resolve_hir_path, SourceAnalyzer},
|
||||
Access, Adjust, Adjustment, Adt, AutoBorrow, BindingMode, BuiltinAttr, Callable, Const,
|
||||
ConstParam, Crate, DeriveHelper, Enum, Field, Function, HasSource, HirFileId, Impl, InFile,
|
||||
InlineAsmOperand, ItemInNs, Label, LifetimeParam, Local, Macro, Module, ModuleDef, Name,
|
||||
OverloadedDeref, Path, ScopeDef, Static, Struct, ToolModule, Trait, TraitAlias, TupleField,
|
||||
Type, TypeAlias, TypeParam, Union, Variant, VariantDef,
|
||||
ConstParam, Crate, DeriveHelper, Enum, Field, Function, GenericSubstitution, HasSource,
|
||||
HirFileId, Impl, InFile, InlineAsmOperand, ItemInNs, Label, LifetimeParam, Local, Macro,
|
||||
Module, ModuleDef, Name, OverloadedDeref, Path, ScopeDef, Static, Struct, ToolModule, Trait,
|
||||
TraitAlias, TupleField, Type, TypeAlias, TypeParam, Union, Variant, VariantDef,
|
||||
};
|
||||
|
||||
const CONTINUE_NO_BREAKS: ControlFlow<Infallible, ()> = ControlFlow::Continue(());
|
||||
|
@ -1415,7 +1415,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||
pub fn resolve_method_call_fallback(
|
||||
&self,
|
||||
call: &ast::MethodCallExpr,
|
||||
) -> Option<Either<Function, Field>> {
|
||||
) -> Option<(Either<Function, Field>, Option<GenericSubstitution>)> {
|
||||
self.analyze(call.syntax())?.resolve_method_call_fallback(self.db, call)
|
||||
}
|
||||
|
||||
|
@ -1458,7 +1458,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||
pub fn resolve_field_fallback(
|
||||
&self,
|
||||
field: &ast::FieldExpr,
|
||||
) -> Option<Either<Either<Field, TupleField>, Function>> {
|
||||
) -> Option<(Either<Either<Field, TupleField>, Function>, Option<GenericSubstitution>)> {
|
||||
self.analyze(field.syntax())?.resolve_field_fallback(self.db, field)
|
||||
}
|
||||
|
||||
|
@ -1466,10 +1466,25 @@ impl<'db> SemanticsImpl<'db> {
|
|||
&self,
|
||||
field: &ast::RecordExprField,
|
||||
) -> Option<(Field, Option<Local>, Type)> {
|
||||
self.resolve_record_field_with_substitution(field)
|
||||
.map(|(field, local, ty, _)| (field, local, ty))
|
||||
}
|
||||
|
||||
pub fn resolve_record_field_with_substitution(
|
||||
&self,
|
||||
field: &ast::RecordExprField,
|
||||
) -> Option<(Field, Option<Local>, Type, GenericSubstitution)> {
|
||||
self.analyze(field.syntax())?.resolve_record_field(self.db, field)
|
||||
}
|
||||
|
||||
pub fn resolve_record_pat_field(&self, field: &ast::RecordPatField) -> Option<(Field, Type)> {
|
||||
self.resolve_record_pat_field_with_subst(field).map(|(field, ty, _)| (field, ty))
|
||||
}
|
||||
|
||||
pub fn resolve_record_pat_field_with_subst(
|
||||
&self,
|
||||
field: &ast::RecordPatField,
|
||||
) -> Option<(Field, Type, GenericSubstitution)> {
|
||||
self.analyze(field.syntax())?.resolve_record_pat_field(self.db, field)
|
||||
}
|
||||
|
||||
|
@ -1525,6 +1540,13 @@ impl<'db> SemanticsImpl<'db> {
|
|||
}
|
||||
|
||||
pub fn resolve_path(&self, path: &ast::Path) -> Option<PathResolution> {
|
||||
self.resolve_path_with_subst(path).map(|(it, _)| it)
|
||||
}
|
||||
|
||||
pub fn resolve_path_with_subst(
|
||||
&self,
|
||||
path: &ast::Path,
|
||||
) -> Option<(PathResolution, Option<GenericSubstitution>)> {
|
||||
self.analyze(path.syntax())?.resolve_path(self.db, path)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue