Move annotations below item attributes
This commit is contained in:
@@ -5,7 +5,7 @@ use ide_db::{
|
|||||||
helpers::visit_file_defs,
|
helpers::visit_file_defs,
|
||||||
RootDatabase,
|
RootDatabase,
|
||||||
};
|
};
|
||||||
use syntax::{ast::NameOwner, AstNode, TextRange, TextSize};
|
use syntax::{ast::NameOwner, AstNode, TextRange};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
fn_references::find_all_methods,
|
fn_references::find_all_methods,
|
||||||
@@ -80,26 +80,26 @@ pub(crate) fn annotations(
|
|||||||
|
|
||||||
visit_file_defs(&Semantics::new(db), file_id, &mut |def| match def {
|
visit_file_defs(&Semantics::new(db), file_id, &mut |def| match def {
|
||||||
Either::Left(def) => {
|
Either::Left(def) => {
|
||||||
let node = match def {
|
let range = match def {
|
||||||
hir::ModuleDef::Const(konst) => {
|
hir::ModuleDef::Const(konst) => {
|
||||||
konst.source(db).and_then(|node| range_and_position_of(&node, file_id))
|
konst.source(db).and_then(|node| name_range(&node, file_id))
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Trait(trait_) => {
|
hir::ModuleDef::Trait(trait_) => {
|
||||||
trait_.source(db).and_then(|node| range_and_position_of(&node, file_id))
|
trait_.source(db).and_then(|node| name_range(&node, file_id))
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Adt(hir::Adt::Struct(strukt)) => {
|
hir::ModuleDef::Adt(hir::Adt::Struct(strukt)) => {
|
||||||
strukt.source(db).and_then(|node| range_and_position_of(&node, file_id))
|
strukt.source(db).and_then(|node| name_range(&node, file_id))
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Adt(hir::Adt::Enum(enum_)) => {
|
hir::ModuleDef::Adt(hir::Adt::Enum(enum_)) => {
|
||||||
enum_.source(db).and_then(|node| range_and_position_of(&node, file_id))
|
enum_.source(db).and_then(|node| name_range(&node, file_id))
|
||||||
}
|
}
|
||||||
hir::ModuleDef::Adt(hir::Adt::Union(union)) => {
|
hir::ModuleDef::Adt(hir::Adt::Union(union)) => {
|
||||||
union.source(db).and_then(|node| range_and_position_of(&node, file_id))
|
union.source(db).and_then(|node| name_range(&node, file_id))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let (offset, range) = match node {
|
let (range, offset) = match range {
|
||||||
Some(node) => node,
|
Some(range) => (range, range.start()),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -122,18 +122,12 @@ pub(crate) fn annotations(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn range_and_position_of<T: NameOwner>(
|
fn name_range<T: NameOwner>(node: &InFile<T>, file_id: FileId) -> Option<TextRange> {
|
||||||
node: &InFile<T>,
|
if node.file_id == file_id.into() {
|
||||||
file_id: FileId,
|
node.value.name().map(|it| it.syntax().text_range())
|
||||||
) -> Option<(TextSize, TextRange)> {
|
} else {
|
||||||
if node.file_id != file_id.into() {
|
|
||||||
// Node is outside the file we are adding annotations to (e.g. macros).
|
// Node is outside the file we are adding annotations to (e.g. macros).
|
||||||
None
|
None
|
||||||
} else {
|
|
||||||
Some((
|
|
||||||
node.value.name()?.syntax().text_range().start(),
|
|
||||||
node.value.syntax().text_range(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,13 +135,15 @@ pub(crate) fn annotations(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if config.annotate_method_references {
|
if config.annotate_method_references {
|
||||||
annotations.extend(find_all_methods(db, file_id).into_iter().map(|method| Annotation {
|
annotations.extend(find_all_methods(db, file_id).into_iter().map(
|
||||||
range: method.range,
|
|FileRange { file_id, range }| Annotation {
|
||||||
kind: AnnotationKind::HasReferences {
|
range,
|
||||||
position: FilePosition { file_id, offset: method.range.start() },
|
kind: AnnotationKind::HasReferences {
|
||||||
data: None,
|
position: FilePosition { file_id, offset: range.start() },
|
||||||
|
data: None,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
annotations
|
annotations
|
||||||
@@ -266,7 +262,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 0..22,
|
range: 6..10,
|
||||||
kind: HasReferences {
|
kind: HasReferences {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -287,7 +283,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 24..48,
|
range: 30..36,
|
||||||
kind: HasReferences {
|
kind: HasReferences {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -370,7 +366,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 0..12,
|
range: 7..11,
|
||||||
kind: HasImpls {
|
kind: HasImpls {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -384,7 +380,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 0..12,
|
range: 7..11,
|
||||||
kind: HasReferences {
|
kind: HasReferences {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -478,7 +474,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 0..12,
|
range: 7..11,
|
||||||
kind: HasImpls {
|
kind: HasImpls {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -502,7 +498,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 0..12,
|
range: 7..11,
|
||||||
kind: HasReferences {
|
kind: HasReferences {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -529,7 +525,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 14..34,
|
range: 20..31,
|
||||||
kind: HasImpls {
|
kind: HasImpls {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -553,7 +549,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 14..34,
|
range: 20..31,
|
||||||
kind: HasReferences {
|
kind: HasReferences {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -712,7 +708,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 0..12,
|
range: 7..11,
|
||||||
kind: HasImpls {
|
kind: HasImpls {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
@@ -736,7 +732,7 @@ fn main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Annotation {
|
Annotation {
|
||||||
range: 0..12,
|
range: 7..11,
|
||||||
kind: HasReferences {
|
kind: HasReferences {
|
||||||
position: FilePosition {
|
position: FilePosition {
|
||||||
file_id: FileId(
|
file_id: FileId(
|
||||||
|
|||||||
Reference in New Issue
Block a user