mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Allow navigation targets to be duplicated when the focus range lies in the macro definition site
This commit is contained in:
parent
9b7ec5e31b
commit
9cb13b6efb
38 changed files with 851 additions and 488 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -608,6 +608,7 @@ dependencies = [
|
||||||
name = "ide"
|
name = "ide"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"arrayvec",
|
||||||
"cfg",
|
"cfg",
|
||||||
"cov-mark",
|
"cov-mark",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl ChangeFixture {
|
||||||
|
|
||||||
let mut file_set = FileSet::default();
|
let mut file_set = FileSet::default();
|
||||||
let mut current_source_root_kind = SourceRootKind::Local;
|
let mut current_source_root_kind = SourceRootKind::Local;
|
||||||
let mut file_id = FileId(0);
|
let mut file_id = FileId::from_raw(0);
|
||||||
let mut roots = Vec::new();
|
let mut roots = Vec::new();
|
||||||
|
|
||||||
let mut file_position = None;
|
let mut file_position = None;
|
||||||
|
@ -210,7 +210,7 @@ impl ChangeFixture {
|
||||||
let path = VfsPath::new_virtual_path(meta.path);
|
let path = VfsPath::new_virtual_path(meta.path);
|
||||||
file_set.insert(file_id, path);
|
file_set.insert(file_id, path);
|
||||||
files.push(file_id);
|
files.push(file_id);
|
||||||
file_id.0 += 1;
|
file_id = FileId::from_raw(file_id.index() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if crates.is_empty() {
|
if crates.is_empty() {
|
||||||
|
@ -255,7 +255,7 @@ impl ChangeFixture {
|
||||||
|
|
||||||
if let Some(mini_core) = mini_core {
|
if let Some(mini_core) = mini_core {
|
||||||
let core_file = file_id;
|
let core_file = file_id;
|
||||||
file_id.0 += 1;
|
file_id = FileId::from_raw(file_id.index() + 1);
|
||||||
|
|
||||||
let mut fs = FileSet::default();
|
let mut fs = FileSet::default();
|
||||||
fs.insert(core_file, VfsPath::new_virtual_path("/sysroot/core/lib.rs".to_string()));
|
fs.insert(core_file, VfsPath::new_virtual_path("/sysroot/core/lib.rs".to_string()));
|
||||||
|
@ -296,7 +296,6 @@ impl ChangeFixture {
|
||||||
let mut proc_macros = ProcMacros::default();
|
let mut proc_macros = ProcMacros::default();
|
||||||
if !proc_macro_names.is_empty() {
|
if !proc_macro_names.is_empty() {
|
||||||
let proc_lib_file = file_id;
|
let proc_lib_file = file_id;
|
||||||
file_id.0 += 1;
|
|
||||||
|
|
||||||
proc_macro_defs.extend(default_test_proc_macros());
|
proc_macro_defs.extend(default_test_proc_macros());
|
||||||
let (proc_macro, source) = filter_test_proc_macros(&proc_macro_names, proc_macro_defs);
|
let (proc_macro, source) = filter_test_proc_macros(&proc_macro_names, proc_macro_defs);
|
||||||
|
|
|
@ -880,7 +880,7 @@ mod tests {
|
||||||
fn detect_cyclic_dependency_indirect() {
|
fn detect_cyclic_dependency_indirect() {
|
||||||
let mut graph = CrateGraph::default();
|
let mut graph = CrateGraph::default();
|
||||||
let crate1 = graph.add_crate_root(
|
let crate1 = graph.add_crate_root(
|
||||||
FileId(1u32),
|
FileId::from_raw(1u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -893,7 +893,7 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let crate2 = graph.add_crate_root(
|
let crate2 = graph.add_crate_root(
|
||||||
FileId(2u32),
|
FileId::from_raw(2u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -906,7 +906,7 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let crate3 = graph.add_crate_root(
|
let crate3 = graph.add_crate_root(
|
||||||
FileId(3u32),
|
FileId::from_raw(3u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -942,7 +942,7 @@ mod tests {
|
||||||
fn detect_cyclic_dependency_direct() {
|
fn detect_cyclic_dependency_direct() {
|
||||||
let mut graph = CrateGraph::default();
|
let mut graph = CrateGraph::default();
|
||||||
let crate1 = graph.add_crate_root(
|
let crate1 = graph.add_crate_root(
|
||||||
FileId(1u32),
|
FileId::from_raw(1u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -955,7 +955,7 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let crate2 = graph.add_crate_root(
|
let crate2 = graph.add_crate_root(
|
||||||
FileId(2u32),
|
FileId::from_raw(2u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -985,7 +985,7 @@ mod tests {
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
let mut graph = CrateGraph::default();
|
let mut graph = CrateGraph::default();
|
||||||
let crate1 = graph.add_crate_root(
|
let crate1 = graph.add_crate_root(
|
||||||
FileId(1u32),
|
FileId::from_raw(1u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -998,7 +998,7 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let crate2 = graph.add_crate_root(
|
let crate2 = graph.add_crate_root(
|
||||||
FileId(2u32),
|
FileId::from_raw(2u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -1011,7 +1011,7 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let crate3 = graph.add_crate_root(
|
let crate3 = graph.add_crate_root(
|
||||||
FileId(3u32),
|
FileId::from_raw(3u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -1041,7 +1041,7 @@ mod tests {
|
||||||
fn dashes_are_normalized() {
|
fn dashes_are_normalized() {
|
||||||
let mut graph = CrateGraph::default();
|
let mut graph = CrateGraph::default();
|
||||||
let crate1 = graph.add_crate_root(
|
let crate1 = graph.add_crate_root(
|
||||||
FileId(1u32),
|
FileId::from_raw(1u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -1054,7 +1054,7 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let crate2 = graph.add_crate_root(
|
let crate2 = graph.add_crate_root(
|
||||||
FileId(2u32),
|
FileId::from_raw(2u32),
|
||||||
Edition2018,
|
Edition2018,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl fmt::Debug for SpanAnchor {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl tt::SpanAnchor for SpanAnchor {
|
impl tt::SpanAnchor for SpanAnchor {
|
||||||
const DUMMY: Self = SpanAnchor { file_id: FileId(0), ast_id: ROOT_ERASED_FILE_AST_ID };
|
const DUMMY: Self = SpanAnchor { file_id: FileId::BOGUS, ast_id: ROOT_ERASED_FILE_AST_ID };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Input to the analyzer is a set of files, where each file is identified by
|
/// Input to the analyzer is a set of files, where each file is identified by
|
||||||
|
@ -99,12 +99,6 @@ impl From<HirFileId> for u32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u32> for HirFileId {
|
|
||||||
fn from(value: u32) -> Self {
|
|
||||||
HirFileId(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<MacroCallId> for HirFileId {
|
impl From<MacroCallId> for HirFileId {
|
||||||
fn from(value: MacroCallId) -> Self {
|
fn from(value: MacroCallId) -> Self {
|
||||||
value.as_file()
|
value.as_file()
|
||||||
|
@ -147,7 +141,7 @@ pub enum HirFileIdRepr {
|
||||||
impl fmt::Debug for HirFileIdRepr {
|
impl fmt::Debug for HirFileIdRepr {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::FileId(arg0) => f.debug_tuple("FileId").field(&arg0.0).finish(),
|
Self::FileId(arg0) => f.debug_tuple("FileId").field(&arg0.index()).finish(),
|
||||||
Self::MacroFile(arg0) => {
|
Self::MacroFile(arg0) => {
|
||||||
f.debug_tuple("MacroFile").field(&arg0.macro_call_id.0).finish()
|
f.debug_tuple("MacroFile").field(&arg0.macro_call_id.0).finish()
|
||||||
}
|
}
|
||||||
|
@ -156,9 +150,9 @@ impl fmt::Debug for HirFileIdRepr {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<FileId> for HirFileId {
|
impl From<FileId> for HirFileId {
|
||||||
fn from(FileId(id): FileId) -> Self {
|
fn from(id: FileId) -> Self {
|
||||||
assert!(id < Self::MAX_FILE_ID);
|
assert!(id.index() < Self::MAX_FILE_ID);
|
||||||
HirFileId(id)
|
HirFileId(id.index())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +186,7 @@ impl HirFileId {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn file_id(self) -> Option<FileId> {
|
pub fn file_id(self) -> Option<FileId> {
|
||||||
match self.0 & Self::MACRO_FILE_TAG_MASK {
|
match self.0 & Self::MACRO_FILE_TAG_MASK {
|
||||||
0 => Some(FileId(self.0)),
|
0 => Some(FileId::from_raw(self.0)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +194,7 @@ impl HirFileId {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn repr(self) -> HirFileIdRepr {
|
pub fn repr(self) -> HirFileIdRepr {
|
||||||
match self.0 & Self::MACRO_FILE_TAG_MASK {
|
match self.0 & Self::MACRO_FILE_TAG_MASK {
|
||||||
0 => HirFileIdRepr::FileId(FileId(self.0)),
|
0 => HirFileIdRepr::FileId(FileId::from_raw(self.0)),
|
||||||
_ => HirFileIdRepr::MacroFile(MacroFileId {
|
_ => HirFileIdRepr::MacroFile(MacroFileId {
|
||||||
macro_call_id: MacroCallId(InternId::from(self.0 ^ Self::MACRO_FILE_TAG_MASK)),
|
macro_call_id: MacroCallId(InternId::from(self.0 ^ Self::MACRO_FILE_TAG_MASK)),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn assert_parse_result(input: &str, expected: DocExpr) {
|
||||||
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
|
let tt = source_file.syntax().descendants().find_map(ast::TokenTree::cast).unwrap();
|
||||||
let tt = syntax_node_to_token_tree(
|
let tt = syntax_node_to_token_tree(
|
||||||
tt.syntax(),
|
tt.syntax(),
|
||||||
SpanMapRef::RealSpanMap(&RealSpanMap::absolute(FileId(0))),
|
SpanMapRef::RealSpanMap(&RealSpanMap::absolute(FileId::from_raw(0))),
|
||||||
);
|
);
|
||||||
let cfg = DocExpr::parse(&tt);
|
let cfg = DocExpr::parse(&tt);
|
||||||
assert_eq!(cfg, expected);
|
assert_eq!(cfg, expected);
|
||||||
|
|
|
@ -524,7 +524,7 @@ fn file_id_and_params_of(
|
||||||
(src.file_id, src.value.generic_param_list())
|
(src.file_id, src.value.generic_param_list())
|
||||||
}
|
}
|
||||||
// We won't be using this ID anyway
|
// We won't be using this ID anyway
|
||||||
GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => (FileId(!0).into(), None),
|
GenericDefId::EnumVariantId(_) | GenericDefId::ConstId(_) => (FileId::BOGUS.into(), None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -307,6 +307,40 @@ impl InFile<TextRange> {
|
||||||
};
|
};
|
||||||
range
|
range
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn original_node_file_range(
|
||||||
|
self,
|
||||||
|
db: &dyn db::ExpandDatabase,
|
||||||
|
) -> (FileRange, SyntaxContextId) {
|
||||||
|
match self.file_id.repr() {
|
||||||
|
HirFileIdRepr::FileId(file_id) => {
|
||||||
|
(FileRange { file_id, range: self.value }, SyntaxContextId::ROOT)
|
||||||
|
}
|
||||||
|
HirFileIdRepr::MacroFile(mac_file) => {
|
||||||
|
match ExpansionInfo::new(db, mac_file).map_node_range_up(db, self.value) {
|
||||||
|
Some(it) => it,
|
||||||
|
None => {
|
||||||
|
let loc = db.lookup_intern_macro_call(mac_file.macro_call_id);
|
||||||
|
(loc.kind.original_call_range(db), SyntaxContextId::ROOT)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn original_node_file_range_opt(
|
||||||
|
self,
|
||||||
|
db: &dyn db::ExpandDatabase,
|
||||||
|
) -> Option<(FileRange, SyntaxContextId)> {
|
||||||
|
match self.file_id.repr() {
|
||||||
|
HirFileIdRepr::FileId(file_id) => {
|
||||||
|
Some((FileRange { file_id, range: self.value }, SyntaxContextId::ROOT))
|
||||||
|
}
|
||||||
|
HirFileIdRepr::MacroFile(mac_file) => {
|
||||||
|
ExpansionInfo::new(db, mac_file).map_node_range_up(db, self.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: AstNode> InFile<N> {
|
impl<N: AstNode> InFile<N> {
|
||||||
|
|
|
@ -54,8 +54,10 @@ pub(crate) fn fixup_syntax(span_map: SpanMapRef<'_>, node: &SyntaxNode) -> Synta
|
||||||
let dummy_range = TextRange::empty(TextSize::new(0));
|
let dummy_range = TextRange::empty(TextSize::new(0));
|
||||||
// we use a file id of `FileId(!0)` to signal a fake node, and the text range's start offset as
|
// we use a file id of `FileId(!0)` to signal a fake node, and the text range's start offset as
|
||||||
// the index into the replacement vec but only if the end points to !0
|
// the index into the replacement vec but only if the end points to !0
|
||||||
let dummy_anchor =
|
let dummy_anchor = SpanAnchor {
|
||||||
SpanAnchor { file_id: FileId(!0), ast_id: ErasedFileAstId::from_raw(RawIdx::from(!0)) };
|
file_id: FileId::from_raw(!0),
|
||||||
|
ast_id: ErasedFileAstId::from_raw(RawIdx::from(!0)),
|
||||||
|
};
|
||||||
let fake_span = |range| SpanData {
|
let fake_span = |range| SpanData {
|
||||||
range: dummy_range,
|
range: dummy_range,
|
||||||
anchor: dummy_anchor,
|
anchor: dummy_anchor,
|
||||||
|
@ -308,7 +310,7 @@ fn reverse_fixups_(tt: &mut Subtree, undo_info: &[Subtree]) {
|
||||||
.filter(|tt| match tt {
|
.filter(|tt| match tt {
|
||||||
tt::TokenTree::Leaf(leaf) => {
|
tt::TokenTree::Leaf(leaf) => {
|
||||||
let span = leaf.span();
|
let span = leaf.span();
|
||||||
span.anchor.file_id != FileId(!0) || span.range.end() == TextSize::new(!0)
|
span.anchor.file_id != FileId::from_raw(!0) || span.range.end() == TextSize::new(!0)
|
||||||
}
|
}
|
||||||
tt::TokenTree::Subtree(_) => true,
|
tt::TokenTree::Subtree(_) => true,
|
||||||
})
|
})
|
||||||
|
@ -318,7 +320,7 @@ fn reverse_fixups_(tt: &mut Subtree, undo_info: &[Subtree]) {
|
||||||
SmallVec::from_const([tt.into()])
|
SmallVec::from_const([tt.into()])
|
||||||
}
|
}
|
||||||
tt::TokenTree::Leaf(leaf) => {
|
tt::TokenTree::Leaf(leaf) => {
|
||||||
if leaf.span().anchor.file_id == FileId(!0) {
|
if leaf.span().anchor.file_id == FileId::from_raw(!0) {
|
||||||
let original = undo_info[u32::from(leaf.span().range.start()) as usize].clone();
|
let original = undo_info[u32::from(leaf.span().range.start()) as usize].clone();
|
||||||
if original.delimiter.kind == tt::DelimiterKind::Invisible {
|
if original.delimiter.kind == tt::DelimiterKind::Invisible {
|
||||||
original.token_trees.into()
|
original.token_trees.into()
|
||||||
|
@ -373,7 +375,7 @@ mod tests {
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn check(ra_fixture: &str, mut expect: Expect) {
|
fn check(ra_fixture: &str, mut expect: Expect) {
|
||||||
let parsed = syntax::SourceFile::parse(ra_fixture);
|
let parsed = syntax::SourceFile::parse(ra_fixture);
|
||||||
let span_map = SpanMap::RealSpanMap(Arc::new(RealSpanMap::absolute(FileId(0))));
|
let span_map = SpanMap::RealSpanMap(Arc::new(RealSpanMap::absolute(FileId::from_raw(0))));
|
||||||
let fixups = super::fixup_syntax(span_map.as_ref(), &parsed.syntax_node());
|
let fixups = super::fixup_syntax(span_map.as_ref(), &parsed.syntax_node());
|
||||||
let mut tt = mbe::syntax_node_to_token_tree_modified(
|
let mut tt = mbe::syntax_node_to_token_tree_modified(
|
||||||
&parsed.syntax_node(),
|
&parsed.syntax_node(),
|
||||||
|
|
|
@ -197,6 +197,7 @@ pub trait SyntaxContextExt {
|
||||||
fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> Self;
|
fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> Self;
|
||||||
fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> Self;
|
fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> Self;
|
||||||
fn parent_ctxt(self, db: &dyn ExpandDatabase) -> Self;
|
fn parent_ctxt(self, db: &dyn ExpandDatabase) -> Self;
|
||||||
|
fn remove_mark(&mut self, db: &dyn ExpandDatabase) -> (Option<MacroCallId>, Transparency);
|
||||||
fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<MacroCallId>, Transparency);
|
fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<MacroCallId>, Transparency);
|
||||||
fn marks(self, db: &dyn ExpandDatabase) -> Vec<(Option<MacroCallId>, Transparency)>;
|
fn marks(self, db: &dyn ExpandDatabase) -> Vec<(Option<MacroCallId>, Transparency)>;
|
||||||
}
|
}
|
||||||
|
@ -223,6 +224,11 @@ impl SyntaxContextExt for SyntaxContextId {
|
||||||
let data = db.lookup_intern_syntax_context(self);
|
let data = db.lookup_intern_syntax_context(self);
|
||||||
(data.outer_expn, data.outer_transparency)
|
(data.outer_expn, data.outer_transparency)
|
||||||
}
|
}
|
||||||
|
fn remove_mark(&mut self, db: &dyn ExpandDatabase) -> (Option<MacroCallId>, Transparency) {
|
||||||
|
let data = db.lookup_intern_syntax_context(*self);
|
||||||
|
*self = data.parent;
|
||||||
|
(data.outer_expn, data.outer_transparency)
|
||||||
|
}
|
||||||
fn marks(self, db: &dyn ExpandDatabase) -> Vec<(Option<MacroCallId>, Transparency)> {
|
fn marks(self, db: &dyn ExpandDatabase) -> Vec<(Option<MacroCallId>, Transparency)> {
|
||||||
let mut marks = marks_rev(self, db).collect::<Vec<_>>();
|
let mut marks = marks_rev(self, db).collect::<Vec<_>>();
|
||||||
marks.reverse();
|
marks.reverse();
|
||||||
|
|
|
@ -380,6 +380,21 @@ impl MacroDefId {
|
||||||
db.intern_macro_call(MacroCallLoc { def: self, krate, eager: None, kind, call_site })
|
db.intern_macro_call(MacroCallLoc { def: self, krate, eager: None, kind, call_site })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn definition_range(&self, db: &dyn db::ExpandDatabase) -> InFile<TextRange> {
|
||||||
|
match self.kind {
|
||||||
|
MacroDefKind::Declarative(id)
|
||||||
|
| MacroDefKind::BuiltIn(_, id)
|
||||||
|
| MacroDefKind::BuiltInAttr(_, id)
|
||||||
|
| MacroDefKind::BuiltInDerive(_, id)
|
||||||
|
| MacroDefKind::BuiltInEager(_, id) => {
|
||||||
|
id.with_value(db.ast_id_map(id.file_id).get(id.value).text_range())
|
||||||
|
}
|
||||||
|
MacroDefKind::ProcMacro(_, _, id) => {
|
||||||
|
id.with_value(db.ast_id_map(id.file_id).get(id.value).text_range())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
|
pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
MacroDefKind::ProcMacro(.., id) => return Either::Right(id),
|
MacroDefKind::ProcMacro(.., id) => return Either::Right(id),
|
||||||
|
|
|
@ -261,8 +261,8 @@ mod tests {
|
||||||
assert_eq!(quoted.to_string(), "hello");
|
assert_eq!(quoted.to_string(), "hello");
|
||||||
let t = format!("{quoted:?}");
|
let t = format!("{quoted:?}");
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
SUBTREE $$ SpanData { range: 0..0, anchor: SpanAnchor(FileId(4294967295), 0), ctx: SyntaxContextId(0) } SpanData { range: 0..0, anchor: SpanAnchor(FileId(4294967295), 0), ctx: SyntaxContextId(0) }
|
SUBTREE $$ SpanData { range: 0..0, anchor: SpanAnchor(FileId(937550), 0), ctx: SyntaxContextId(0) } SpanData { range: 0..0, anchor: SpanAnchor(FileId(937550), 0), ctx: SyntaxContextId(0) }
|
||||||
IDENT hello SpanData { range: 0..0, anchor: SpanAnchor(FileId(4294967295), 0), ctx: SyntaxContextId(0) }"#]].assert_eq(&t);
|
IDENT hello SpanData { range: 0..0, anchor: SpanAnchor(FileId(937550), 0), ctx: SyntaxContextId(0) }"#]].assert_eq(&t);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -241,7 +241,7 @@ fn modpath_from_str(db: &dyn HirDatabase, link: &str) -> Option<ModPath> {
|
||||||
ModPath::from_src(
|
ModPath::from_src(
|
||||||
db.upcast(),
|
db.upcast(),
|
||||||
ast_path,
|
ast_path,
|
||||||
SpanMapRef::RealSpanMap(&RealSpanMap::absolute(FileId(0))),
|
SpanMapRef::RealSpanMap(&RealSpanMap::absolute(FileId::BOGUS)),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,7 @@ pub use {
|
||||||
},
|
},
|
||||||
hir_expand::{
|
hir_expand::{
|
||||||
attrs::{Attr, AttrId},
|
attrs::{Attr, AttrId},
|
||||||
|
hygiene::{marks_rev, SyntaxContextExt},
|
||||||
name::{known, Name},
|
name::{known, Name},
|
||||||
tt, ExpandResult, HirFileId, HirFileIdExt, InFile, InMacroFile, InRealFile, MacroFileId,
|
tt, ExpandResult, HirFileId, HirFileIdExt, InFile, InMacroFile, InRealFile, MacroFileId,
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,7 +9,7 @@ use hir_def::{
|
||||||
};
|
};
|
||||||
use hir_expand::{HirFileId, InFile};
|
use hir_expand::{HirFileId, InFile};
|
||||||
use hir_ty::db::HirDatabase;
|
use hir_ty::db::HirDatabase;
|
||||||
use syntax::{ast::HasName, AstNode, SmolStr, SyntaxNode, SyntaxNodePtr};
|
use syntax::{ast::HasName, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr};
|
||||||
|
|
||||||
use crate::{Module, ModuleDef, Semantics};
|
use crate::{Module, ModuleDef, Semantics};
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ pub struct DeclarationLocation {
|
||||||
/// This points to the whole syntax node of the declaration.
|
/// This points to the whole syntax node of the declaration.
|
||||||
pub ptr: SyntaxNodePtr,
|
pub ptr: SyntaxNodePtr,
|
||||||
/// This points to the [`syntax::ast::Name`] identifier of the declaration.
|
/// This points to the [`syntax::ast::Name`] identifier of the declaration.
|
||||||
pub name_ptr: SyntaxNodePtr,
|
pub name_ptr: AstPtr<syntax::ast::Name>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeclarationLocation {
|
impl DeclarationLocation {
|
||||||
|
@ -185,7 +185,7 @@ impl<'a> SymbolCollector<'a> {
|
||||||
let dec_loc = DeclarationLocation {
|
let dec_loc = DeclarationLocation {
|
||||||
hir_file_id: source.file_id,
|
hir_file_id: source.file_id,
|
||||||
ptr: SyntaxNodePtr::new(use_tree_src.syntax()),
|
ptr: SyntaxNodePtr::new(use_tree_src.syntax()),
|
||||||
name_ptr: SyntaxNodePtr::new(name.syntax()),
|
name_ptr: AstPtr::new(&name),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.symbols.push(FileSymbol {
|
self.symbols.push(FileSymbol {
|
||||||
|
@ -289,7 +289,7 @@ impl<'a> SymbolCollector<'a> {
|
||||||
let dec_loc = DeclarationLocation {
|
let dec_loc = DeclarationLocation {
|
||||||
hir_file_id: source.file_id,
|
hir_file_id: source.file_id,
|
||||||
ptr: SyntaxNodePtr::new(source.value.syntax()),
|
ptr: SyntaxNodePtr::new(source.value.syntax()),
|
||||||
name_ptr: SyntaxNodePtr::new(name_node.syntax()),
|
name_ptr: AstPtr::new(&name_node),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(attrs) = def.attrs(self.db) {
|
if let Some(attrs) = def.attrs(self.db) {
|
||||||
|
@ -322,7 +322,7 @@ impl<'a> SymbolCollector<'a> {
|
||||||
let dec_loc = DeclarationLocation {
|
let dec_loc = DeclarationLocation {
|
||||||
hir_file_id: declaration.file_id,
|
hir_file_id: declaration.file_id,
|
||||||
ptr: SyntaxNodePtr::new(module.syntax()),
|
ptr: SyntaxNodePtr::new(module.syntax()),
|
||||||
name_ptr: SyntaxNodePtr::new(name_node.syntax()),
|
name_ptr: AstPtr::new(&name_node),
|
||||||
};
|
};
|
||||||
|
|
||||||
let def = ModuleDef::Module(module_id.into());
|
let def = ModuleDef::Module(module_id.into());
|
||||||
|
|
|
@ -27,10 +27,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 83..119,
|
range: 83..119,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 109..118,
|
range: 109..118,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -54,10 +56,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 0..81,
|
range: 0..81,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 74..80,
|
range: 74..80,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -81,10 +85,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 0..81,
|
range: 0..81,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 74..80,
|
range: 74..80,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: true,
|
is_alias: true,
|
||||||
|
@ -108,10 +114,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 0..81,
|
range: 0..81,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 74..80,
|
range: 74..80,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: true,
|
is_alias: true,
|
||||||
|
@ -135,10 +143,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 0..81,
|
range: 0..81,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 74..80,
|
range: 74..80,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: true,
|
is_alias: true,
|
||||||
|
@ -162,10 +172,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 83..119,
|
range: 83..119,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 109..118,
|
range: 109..118,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: true,
|
is_alias: true,
|
||||||
|
@ -189,10 +201,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 0..81,
|
range: 0..81,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 74..80,
|
range: 74..80,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: true,
|
is_alias: true,
|
||||||
|
|
|
@ -25,10 +25,12 @@
|
||||||
kind: TYPE_ALIAS,
|
kind: TYPE_ALIAS,
|
||||||
range: 397..417,
|
range: 397..417,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 402..407,
|
range: 402..407,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -50,10 +52,12 @@
|
||||||
kind: CONST,
|
kind: CONST,
|
||||||
range: 340..361,
|
range: 340..361,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 346..351,
|
range: 346..351,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -75,10 +79,12 @@
|
||||||
kind: CONST,
|
kind: CONST,
|
||||||
range: 520..592,
|
range: 520..592,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 526..542,
|
range: 526..542,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -102,10 +108,12 @@
|
||||||
kind: ENUM,
|
kind: ENUM,
|
||||||
range: 185..207,
|
range: 185..207,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 190..194,
|
range: 190..194,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -129,10 +137,12 @@
|
||||||
kind: USE_TREE,
|
kind: USE_TREE,
|
||||||
range: 654..676,
|
range: 654..676,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 663..676,
|
range: 663..676,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -156,10 +166,12 @@
|
||||||
kind: MACRO_DEF,
|
kind: MACRO_DEF,
|
||||||
range: 153..168,
|
range: 153..168,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 159..164,
|
range: 159..164,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -181,10 +193,12 @@
|
||||||
kind: STATIC,
|
kind: STATIC,
|
||||||
range: 362..396,
|
range: 362..396,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 369..375,
|
range: 369..375,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -208,10 +222,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 170..184,
|
range: 170..184,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 177..183,
|
range: 177..183,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -235,10 +251,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 0..22,
|
range: 0..22,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 6..21,
|
range: 6..21,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -262,10 +280,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 318..336,
|
range: 318..336,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 325..335,
|
range: 325..335,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: Some(
|
container_name: Some(
|
||||||
"main",
|
"main",
|
||||||
|
@ -291,10 +311,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 555..581,
|
range: 555..581,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 562..580,
|
range: 562..580,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: Some(
|
container_name: Some(
|
||||||
"CONST_WITH_INNER",
|
"CONST_WITH_INNER",
|
||||||
|
@ -320,10 +342,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 479..507,
|
range: 479..507,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 486..506,
|
range: 486..506,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -345,10 +369,12 @@
|
||||||
kind: TRAIT,
|
kind: TRAIT,
|
||||||
range: 261..300,
|
range: 261..300,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 267..272,
|
range: 267..272,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -372,10 +398,12 @@
|
||||||
kind: USE_TREE,
|
kind: USE_TREE,
|
||||||
range: 682..696,
|
range: 682..696,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 691..696,
|
range: 691..696,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -399,10 +427,12 @@
|
||||||
kind: UNION,
|
kind: UNION,
|
||||||
range: 208..222,
|
range: 208..222,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 214..219,
|
range: 214..219,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -426,10 +456,12 @@
|
||||||
kind: MODULE,
|
kind: MODULE,
|
||||||
range: 419..457,
|
range: 419..457,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 423..428,
|
range: 423..428,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -453,10 +485,12 @@
|
||||||
kind: MODULE,
|
kind: MODULE,
|
||||||
range: 594..604,
|
range: 594..604,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 598..603,
|
range: 598..603,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -480,10 +514,12 @@
|
||||||
kind: MACRO_RULES,
|
kind: MACRO_RULES,
|
||||||
range: 51..131,
|
range: 51..131,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 64..77,
|
range: 64..77,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -505,10 +541,12 @@
|
||||||
kind: FN,
|
kind: FN,
|
||||||
range: 242..257,
|
range: 242..257,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 245..252,
|
range: 245..252,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -532,10 +570,12 @@
|
||||||
kind: MACRO_RULES,
|
kind: MACRO_RULES,
|
||||||
range: 1..48,
|
range: 1..48,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 14..31,
|
range: 14..31,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -557,10 +597,12 @@
|
||||||
kind: FN,
|
kind: FN,
|
||||||
range: 302..338,
|
range: 302..338,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 305..309,
|
range: 305..309,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -584,10 +626,12 @@
|
||||||
kind: USE_TREE,
|
kind: USE_TREE,
|
||||||
range: 611..648,
|
range: 611..648,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 628..648,
|
range: 628..648,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -609,10 +653,12 @@
|
||||||
kind: FN,
|
kind: FN,
|
||||||
range: 279..298,
|
range: 279..298,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 282..290,
|
range: 282..290,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: Some(
|
container_name: Some(
|
||||||
"Trait",
|
"Trait",
|
||||||
|
@ -649,10 +695,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 435..455,
|
range: 435..455,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 442..454,
|
range: 442..454,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -687,10 +735,12 @@
|
||||||
kind: USE_TREE,
|
kind: USE_TREE,
|
||||||
range: 111..143,
|
range: 111..143,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 127..143,
|
range: 127..143,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -714,10 +764,12 @@
|
||||||
kind: STRUCT,
|
kind: STRUCT,
|
||||||
range: 0..20,
|
range: 0..20,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 7..19,
|
range: 7..19,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -741,10 +793,12 @@
|
||||||
kind: USE_TREE,
|
kind: USE_TREE,
|
||||||
range: 25..59,
|
range: 25..59,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 41..59,
|
range: 41..59,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -768,10 +822,12 @@
|
||||||
kind: USE_TREE,
|
kind: USE_TREE,
|
||||||
range: 65..105,
|
range: 65..105,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 95..105,
|
range: 95..105,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
@ -795,10 +851,12 @@
|
||||||
kind: USE_TREE,
|
kind: USE_TREE,
|
||||||
range: 65..105,
|
range: 65..105,
|
||||||
},
|
},
|
||||||
name_ptr: SyntaxNodePtr {
|
name_ptr: AstPtr(
|
||||||
|
SyntaxNodePtr {
|
||||||
kind: NAME,
|
kind: NAME,
|
||||||
range: 95..105,
|
range: 95..105,
|
||||||
},
|
},
|
||||||
|
),
|
||||||
},
|
},
|
||||||
container_name: None,
|
container_name: None,
|
||||||
is_alias: false,
|
is_alias: false,
|
||||||
|
|
|
@ -14,6 +14,7 @@ doctest = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cov-mark = "2.0.0-pre.1"
|
cov-mark = "2.0.0-pre.1"
|
||||||
crossbeam-channel = "0.5.5"
|
crossbeam-channel = "0.5.5"
|
||||||
|
arrayvec = "0.7.4"
|
||||||
either.workspace = true
|
either.workspace = true
|
||||||
itertools.workspace = true
|
itertools.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! Entry point for call-hierarchy
|
//! Entry point for call-hierarchy
|
||||||
|
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
use hir::{DescendPreference, Semantics};
|
use hir::{DescendPreference, Semantics};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
defs::{Definition, NameClass, NameRefClass},
|
defs::{Definition, NameClass, NameRefClass},
|
||||||
|
@ -66,7 +68,10 @@ pub(crate) fn incoming_calls(
|
||||||
def.try_to_nav(sema.db)
|
def.try_to_nav(sema.db)
|
||||||
});
|
});
|
||||||
if let Some(nav) = nav {
|
if let Some(nav) = nav {
|
||||||
calls.add(nav, sema.original_range(name.syntax()).range);
|
calls.add(nav.call_site, sema.original_range(name.syntax()).range);
|
||||||
|
if let Some(other) = nav.def_site {
|
||||||
|
calls.add(other, sema.original_range(name.syntax()).range);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,8 +122,9 @@ pub(crate) fn outgoing_calls(
|
||||||
function.try_to_nav(db).zip(Some(range))
|
function.try_to_nav(db).zip(Some(range))
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
Some((nav_target, range))
|
Some(nav_target.into_iter().zip(iter::repeat(range)))
|
||||||
})
|
})
|
||||||
|
.flatten()
|
||||||
.for_each(|(nav, range)| calls.add(nav, range));
|
.for_each(|(nav, range)| calls.add(nav, range));
|
||||||
|
|
||||||
Some(calls.into_items())
|
Some(calls.into_items())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::ffi::OsStr;
|
use std::{ffi::OsStr, iter};
|
||||||
|
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
use hir::Semantics;
|
use hir::Semantics;
|
||||||
|
@ -63,10 +63,12 @@ fn check_doc_links(ra_fixture: &str) {
|
||||||
let defs = extract_definitions_from_docs(&docs);
|
let defs = extract_definitions_from_docs(&docs);
|
||||||
let actual: Vec<_> = defs
|
let actual: Vec<_> = defs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_, link, ns)| {
|
.flat_map(|(_, link, ns)| {
|
||||||
let def = resolve_doc_path_for_def(sema.db, cursor_def, &link, ns)
|
let def = resolve_doc_path_for_def(sema.db, cursor_def, &link, ns)
|
||||||
.unwrap_or_else(|| panic!("Failed to resolve {link}"));
|
.unwrap_or_else(|| panic!("Failed to resolve {link}"));
|
||||||
let nav_target = def.try_to_nav(sema.db).unwrap();
|
def.try_to_nav(sema.db).unwrap().into_iter().zip(iter::repeat(link))
|
||||||
|
})
|
||||||
|
.map(|(nav_target, link)| {
|
||||||
let range =
|
let range =
|
||||||
FileRange { file_id: nav_target.file_id, range: nav_target.focus_or_full_range() };
|
FileRange { file_id: nav_target.file_id, range: nav_target.focus_or_full_range() };
|
||||||
(range, link)
|
(range, link)
|
||||||
|
|
|
@ -66,6 +66,7 @@ pub(crate) fn goto_declaration(
|
||||||
let item = trait_.items(db).into_iter().find(|it| it.name(db) == name)?;
|
let item = trait_.items(db).into_iter().find(|it| it.name(db) == name)?;
|
||||||
item.try_to_nav(db)
|
item.try_to_nav(db)
|
||||||
})
|
})
|
||||||
|
.flatten()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if info.is_empty() {
|
if info.is_empty() {
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub(crate) fn goto_definition(
|
||||||
if let Some(doc_comment) = token_as_doc_comment(&original_token) {
|
if let Some(doc_comment) = token_as_doc_comment(&original_token) {
|
||||||
return doc_comment.get_definition_with_descend_at(sema, offset, |def, _, link_range| {
|
return doc_comment.get_definition_with_descend_at(sema, offset, |def, _, link_range| {
|
||||||
let nav = def.try_to_nav(db)?;
|
let nav = def.try_to_nav(db)?;
|
||||||
Some(RangeInfo::new(link_range, vec![nav]))
|
Some(RangeInfo::new(link_range, nav.collect()))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ pub(crate) fn goto_definition(
|
||||||
.resolved_crate(db)
|
.resolved_crate(db)
|
||||||
.map(|it| it.root_module().to_nav(sema.db))
|
.map(|it| it.root_module().to_nav(sema.db))
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
try_filter_trait_item_definition(sema, &def)
|
try_filter_trait_item_definition(sema, &def)
|
||||||
|
@ -138,6 +139,7 @@ fn try_lookup_include_path(
|
||||||
docs: None,
|
docs: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// finds the trait definition of an impl'd item, except function
|
/// finds the trait definition of an impl'd item, except function
|
||||||
/// e.g.
|
/// e.g.
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -166,13 +168,13 @@ fn try_filter_trait_item_definition(
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|itm| discriminant(*itm) == discri_value)
|
.filter(|itm| discriminant(*itm) == discri_value)
|
||||||
.find_map(|itm| (itm.name(db)? == name).then(|| itm.try_to_nav(db)).flatten())
|
.find_map(|itm| (itm.name(db)? == name).then(|| itm.try_to_nav(db)).flatten())
|
||||||
.map(|it| vec![it])
|
.map(|it| it.collect())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn def_to_nav(db: &RootDatabase, def: Definition) -> Vec<NavigationTarget> {
|
fn def_to_nav(db: &RootDatabase, def: Definition) -> Vec<NavigationTarget> {
|
||||||
def.try_to_nav(db).map(|it| vec![it]).unwrap_or_default()
|
def.try_to_nav(db).map(|it| it.collect()).unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -405,8 +407,6 @@ fn bar() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: We should emit two targets here, one for the identifier in the declaration, one for
|
|
||||||
// the macro call
|
|
||||||
#[test]
|
#[test]
|
||||||
fn goto_def_for_macro_defined_fn_no_arg() {
|
fn goto_def_for_macro_defined_fn_no_arg() {
|
||||||
check(
|
check(
|
||||||
|
@ -414,7 +414,7 @@ fn bar() {
|
||||||
//- /lib.rs
|
//- /lib.rs
|
||||||
macro_rules! define_fn {
|
macro_rules! define_fn {
|
||||||
() => (fn foo() {})
|
() => (fn foo() {})
|
||||||
|
//^^^
|
||||||
}
|
}
|
||||||
|
|
||||||
define_fn!();
|
define_fn!();
|
||||||
|
|
|
@ -82,7 +82,11 @@ pub(crate) fn goto_implementation(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impls_for_ty(sema: &Semantics<'_, RootDatabase>, ty: hir::Type) -> Vec<NavigationTarget> {
|
fn impls_for_ty(sema: &Semantics<'_, RootDatabase>, ty: hir::Type) -> Vec<NavigationTarget> {
|
||||||
Impl::all_for_type(sema.db, ty).into_iter().filter_map(|imp| imp.try_to_nav(sema.db)).collect()
|
Impl::all_for_type(sema.db, ty)
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|imp| imp.try_to_nav(sema.db))
|
||||||
|
.flatten()
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn impls_for_trait(
|
fn impls_for_trait(
|
||||||
|
@ -92,6 +96,7 @@ fn impls_for_trait(
|
||||||
Impl::all_for_trait(sema.db, trait_)
|
Impl::all_for_trait(sema.db, trait_)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|imp| imp.try_to_nav(sema.db))
|
.filter_map(|imp| imp.try_to_nav(sema.db))
|
||||||
|
.flatten()
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +114,7 @@ fn impls_for_trait_item(
|
||||||
})?;
|
})?;
|
||||||
item.try_to_nav(sema.db)
|
item.try_to_nav(sema.db)
|
||||||
})
|
})
|
||||||
|
.flatten()
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,13 @@ pub(crate) fn goto_type_definition(
|
||||||
|
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let mut push = |def: Definition| {
|
let mut push = |def: Definition| {
|
||||||
if let Some(nav) = def.try_to_nav(db) {
|
if let Some(navs) = def.try_to_nav(db) {
|
||||||
|
for nav in navs {
|
||||||
if !res.contains(&nav) {
|
if !res.contains(&nav) {
|
||||||
res.push(nav);
|
res.push(nav);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let mut process_ty = |ty: hir::Type| {
|
let mut process_ty = |ty: hir::Type| {
|
||||||
// collect from each `ty` into the `res` result vec
|
// collect from each `ty` into the `res` result vec
|
||||||
|
|
|
@ -117,7 +117,7 @@ fn highlight_closure_captures(
|
||||||
local
|
local
|
||||||
.sources(sema.db)
|
.sources(sema.db)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_nav(sema.db))
|
.flat_map(|x| x.to_nav(sema.db))
|
||||||
.filter(|decl| decl.file_id == file_id)
|
.filter(|decl| decl.file_id == file_id)
|
||||||
.filter_map(|decl| decl.focus_range)
|
.filter_map(|decl| decl.focus_range)
|
||||||
.map(move |range| HighlightedRange { range, category })
|
.map(move |range| HighlightedRange { range, category })
|
||||||
|
@ -216,7 +216,7 @@ fn highlight_references(
|
||||||
local
|
local
|
||||||
.sources(sema.db)
|
.sources(sema.db)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| x.to_nav(sema.db))
|
.flat_map(|x| x.to_nav(sema.db))
|
||||||
.filter(|decl| decl.file_id == file_id)
|
.filter(|decl| decl.file_id == file_id)
|
||||||
.filter_map(|decl| decl.focus_range)
|
.filter_map(|decl| decl.focus_range)
|
||||||
.map(|range| HighlightedRange { range, category })
|
.map(|range| HighlightedRange { range, category })
|
||||||
|
@ -225,15 +225,20 @@ fn highlight_references(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
def => {
|
def => {
|
||||||
let hl_range = match def {
|
let navs = match def {
|
||||||
Definition::Module(module) => {
|
Definition::Module(module) => {
|
||||||
Some(NavigationTarget::from_module_to_decl(sema.db, module))
|
NavigationTarget::from_module_to_decl(sema.db, module)
|
||||||
}
|
}
|
||||||
def => def.try_to_nav(sema.db),
|
def => match def.try_to_nav(sema.db) {
|
||||||
|
Some(it) => it,
|
||||||
|
None => continue,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
for nav in navs {
|
||||||
|
if nav.file_id != file_id {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
.filter(|decl| decl.file_id == file_id)
|
let hl_range = nav.focus_range.map(|range| {
|
||||||
.and_then(|decl| decl.focus_range)
|
|
||||||
.map(|range| {
|
|
||||||
let category = references::decl_mutability(&def, node, range)
|
let category = references::decl_mutability(&def, node, range)
|
||||||
.then_some(ReferenceCategory::Write);
|
.then_some(ReferenceCategory::Write);
|
||||||
HighlightedRange { range, category }
|
HighlightedRange { range, category }
|
||||||
|
@ -244,6 +249,7 @@ fn highlight_references(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.extend(usages);
|
res.extend(usages);
|
||||||
if res.is_empty() {
|
if res.is_empty() {
|
||||||
|
|
|
@ -21,6 +21,7 @@ use crate::{
|
||||||
doc_links::token_as_doc_comment,
|
doc_links::token_as_doc_comment,
|
||||||
markdown_remove::remove_markdown,
|
markdown_remove::remove_markdown,
|
||||||
markup::Markup,
|
markup::Markup,
|
||||||
|
navigation_target::UpmappingResult,
|
||||||
runnables::{runnable_fn, runnable_mod},
|
runnables::{runnable_fn, runnable_mod},
|
||||||
FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, TryToNav,
|
FileId, FilePosition, NavigationTarget, RangeInfo, Runnable, TryToNav,
|
||||||
};
|
};
|
||||||
|
@ -73,7 +74,7 @@ impl HoverAction {
|
||||||
it.module(db)?,
|
it.module(db)?,
|
||||||
it.name(db).map(|name| name.display(db).to_string()),
|
it.name(db).map(|name| name.display(db).to_string()),
|
||||||
),
|
),
|
||||||
nav: it.try_to_nav(db)?,
|
nav: it.try_to_nav(db)?.call_site(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -342,22 +343,26 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov
|
||||||
}
|
}
|
||||||
|
|
||||||
let adt = match def {
|
let adt = match def {
|
||||||
Definition::Trait(it) => return it.try_to_nav(db).map(to_action),
|
Definition::Trait(it) => {
|
||||||
|
return it.try_to_nav(db).map(UpmappingResult::call_site).map(to_action)
|
||||||
|
}
|
||||||
Definition::Adt(it) => Some(it),
|
Definition::Adt(it) => Some(it),
|
||||||
Definition::SelfType(it) => it.self_ty(db).as_adt(),
|
Definition::SelfType(it) => it.self_ty(db).as_adt(),
|
||||||
_ => None,
|
_ => None,
|
||||||
}?;
|
}?;
|
||||||
adt.try_to_nav(db).map(to_action)
|
adt.try_to_nav(db).map(UpmappingResult::call_site).map(to_action)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_fn_references_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
|
fn show_fn_references_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
|
||||||
match def {
|
match def {
|
||||||
Definition::Function(it) => it.try_to_nav(db).map(|nav_target| {
|
Definition::Function(it) => {
|
||||||
|
it.try_to_nav(db).map(UpmappingResult::call_site).map(|nav_target| {
|
||||||
HoverAction::Reference(FilePosition {
|
HoverAction::Reference(FilePosition {
|
||||||
file_id: nav_target.file_id,
|
file_id: nav_target.file_id,
|
||||||
offset: nav_target.focus_or_full_range().start(),
|
offset: nav_target.focus_or_full_range().start(),
|
||||||
})
|
})
|
||||||
}),
|
})
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,6 +315,7 @@ impl HirWrite for InlayHintLabelBuilder<'_> {
|
||||||
}
|
}
|
||||||
self.make_new_part();
|
self.make_new_part();
|
||||||
let Some(location) = ModuleDef::from(def).try_to_nav(self.db) else { return };
|
let Some(location) = ModuleDef::from(def).try_to_nav(self.db) else { return };
|
||||||
|
let location = location.call_site();
|
||||||
let location =
|
let location =
|
||||||
FileRange { file_id: location.file_id, range: location.focus_or_full_range() };
|
FileRange { file_id: location.file_id, range: location.focus_or_full_range() };
|
||||||
self.location = Some(location);
|
self.location = Some(location);
|
||||||
|
|
|
@ -100,7 +100,7 @@ pub use crate::{
|
||||||
markup::Markup,
|
markup::Markup,
|
||||||
moniker::{MonikerDescriptorKind, MonikerKind, MonikerResult, PackageInformation},
|
moniker::{MonikerDescriptorKind, MonikerKind, MonikerResult, PackageInformation},
|
||||||
move_item::Direction,
|
move_item::Direction,
|
||||||
navigation_target::NavigationTarget,
|
navigation_target::{NavigationTarget, UpmappingResult},
|
||||||
prime_caches::ParallelPrimeCachesProgress,
|
prime_caches::ParallelPrimeCachesProgress,
|
||||||
references::ReferenceSearchResult,
|
references::ReferenceSearchResult,
|
||||||
rename::RenameError,
|
rename::RenameError,
|
||||||
|
@ -230,7 +230,7 @@ impl Analysis {
|
||||||
// `AnalysisHost` for creating a fully-featured analysis.
|
// `AnalysisHost` for creating a fully-featured analysis.
|
||||||
pub fn from_single_file(text: String) -> (Analysis, FileId) {
|
pub fn from_single_file(text: String) -> (Analysis, FileId) {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let file_id = FileId(0);
|
let file_id = FileId::from_raw(0);
|
||||||
let mut file_set = FileSet::default();
|
let mut file_set = FileSet::default();
|
||||||
file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_string()));
|
file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_string()));
|
||||||
let source_root = SourceRoot::new_local(file_set);
|
let source_root = SourceRoot::new_local(file_set);
|
||||||
|
@ -413,6 +413,7 @@ impl Analysis {
|
||||||
symbol_index::world_symbols(db, query)
|
symbol_index::world_symbols(db, query)
|
||||||
.into_iter() // xx: should we make this a par iter?
|
.into_iter() // xx: should we make this a par iter?
|
||||||
.filter_map(|s| s.try_to_nav(db))
|
.filter_map(|s| s.try_to_nav(db))
|
||||||
|
.map(UpmappingResult::call_site)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
use arrayvec::ArrayVec;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{
|
use hir::{
|
||||||
db::ExpandDatabase, symbols::FileSymbol, AssocItem, FieldSource, HasContainer, HasSource,
|
db::ExpandDatabase, symbols::FileSymbol, AssocItem, FieldSource, HasContainer, HasSource,
|
||||||
|
@ -72,15 +73,15 @@ impl fmt::Debug for NavigationTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait ToNav {
|
pub(crate) trait ToNav {
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget;
|
fn to_nav(&self, db: &RootDatabase) -> UpmappingResult<NavigationTarget>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait TryToNav {
|
pub(crate) trait TryToNav {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget>;
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: TryToNav, U: TryToNav> TryToNav for Either<T, U> {
|
impl<T: TryToNav, U: TryToNav> TryToNav for Either<T, U> {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
match self {
|
match self {
|
||||||
Either::Left(it) => it.try_to_nav(db),
|
Either::Left(it) => it.try_to_nav(db),
|
||||||
Either::Right(it) => it.try_to_nav(db),
|
Either::Right(it) => it.try_to_nav(db),
|
||||||
|
@ -93,23 +94,30 @@ impl NavigationTarget {
|
||||||
self.focus_range.unwrap_or(self.full_range)
|
self.focus_range.unwrap_or(self.full_range)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
|
pub(crate) fn from_module_to_decl(
|
||||||
|
db: &RootDatabase,
|
||||||
|
module: hir::Module,
|
||||||
|
) -> UpmappingResult<NavigationTarget> {
|
||||||
let name = module.name(db).map(|it| it.to_smol_str()).unwrap_or_default();
|
let name = module.name(db).map(|it| it.to_smol_str()).unwrap_or_default();
|
||||||
if let Some(InFile { value, file_id }) = &module.declaration_source(db) {
|
match module.declaration_source(db) {
|
||||||
let (file_id, full_range, focus_range) =
|
Some(InFile { value, file_id }) => {
|
||||||
orig_range_with_focus(db, *file_id, value.syntax(), value.name());
|
orig_range_with_focus(db, file_id, value.syntax(), value.name()).map(
|
||||||
|
|(FileRange { file_id, range: full_range }, focus_range)| {
|
||||||
let mut res = NavigationTarget::from_syntax(
|
let mut res = NavigationTarget::from_syntax(
|
||||||
file_id,
|
file_id,
|
||||||
name,
|
name.clone(),
|
||||||
focus_range,
|
focus_range,
|
||||||
full_range,
|
full_range,
|
||||||
SymbolKind::Module,
|
SymbolKind::Module,
|
||||||
);
|
);
|
||||||
res.docs = module.docs(db);
|
res.docs = module.docs(db);
|
||||||
res.description = Some(module.display(db).to_string());
|
res.description = Some(module.display(db).to_string());
|
||||||
return res;
|
res
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_ => module.to_nav(db),
|
||||||
}
|
}
|
||||||
module.to_nav(db)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -135,13 +143,14 @@ impl NavigationTarget {
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
InFile { file_id, value }: InFile<&dyn ast::HasName>,
|
InFile { file_id, value }: InFile<&dyn ast::HasName>,
|
||||||
kind: SymbolKind,
|
kind: SymbolKind,
|
||||||
) -> NavigationTarget {
|
) -> UpmappingResult<NavigationTarget> {
|
||||||
let name = value.name().map(|it| it.text().into()).unwrap_or_else(|| "_".into());
|
let name: SmolStr = value.name().map(|it| it.text().into()).unwrap_or_else(|| "_".into());
|
||||||
|
|
||||||
let (file_id, full_range, focus_range) =
|
orig_range_with_focus(db, file_id, value.syntax(), value.name()).map(
|
||||||
orig_range_with_focus(db, file_id, value.syntax(), value.name());
|
|(FileRange { file_id, range: full_range }, focus_range)| {
|
||||||
|
NavigationTarget::from_syntax(file_id, name.clone(), focus_range, full_range, kind)
|
||||||
NavigationTarget::from_syntax(file_id, name, focus_range, full_range, kind)
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_syntax(
|
fn from_syntax(
|
||||||
|
@ -166,19 +175,19 @@ impl NavigationTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for FileSymbol {
|
impl TryToNav for FileSymbol {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let full_range = self.loc.original_range(db);
|
let root = db.parse_or_expand(self.loc.hir_file_id);
|
||||||
let focus_range = self.loc.original_name_range(db);
|
self.loc.ptr.to_node(&root);
|
||||||
let focus_range = if focus_range.file_id == full_range.file_id
|
Some(
|
||||||
&& full_range.range.contains_range(focus_range.range)
|
orig_range_with_focus(
|
||||||
{
|
db,
|
||||||
Some(focus_range.range)
|
self.loc.hir_file_id,
|
||||||
} else {
|
&self.loc.ptr.to_node(&root),
|
||||||
None
|
Some(self.loc.name_ptr.to_node(&root)),
|
||||||
};
|
)
|
||||||
|
.map(|(FileRange { file_id, range: full_range }, focus_range)| {
|
||||||
Some(NavigationTarget {
|
NavigationTarget {
|
||||||
file_id: full_range.file_id,
|
file_id,
|
||||||
name: self
|
name: self
|
||||||
.is_alias
|
.is_alias
|
||||||
.then(|| self.def.name(db))
|
.then(|| self.def.name(db))
|
||||||
|
@ -186,7 +195,7 @@ impl TryToNav for FileSymbol {
|
||||||
.map_or_else(|| self.name.clone(), |it| it.to_smol_str()),
|
.map_or_else(|| self.name.clone(), |it| it.to_smol_str()),
|
||||||
alias: self.is_alias.then(|| self.name.clone()),
|
alias: self.is_alias.then(|| self.name.clone()),
|
||||||
kind: Some(hir::ModuleDefId::from(self.def).into()),
|
kind: Some(hir::ModuleDefId::from(self.def).into()),
|
||||||
full_range: full_range.range,
|
full_range,
|
||||||
focus_range,
|
focus_range,
|
||||||
container_name: self.container_name.clone(),
|
container_name: self.container_name.clone(),
|
||||||
description: match self.def {
|
description: match self.def {
|
||||||
|
@ -203,12 +212,14 @@ impl TryToNav for FileSymbol {
|
||||||
hir::ModuleDef::BuiltinType(_) => None,
|
hir::ModuleDef::BuiltinType(_) => None,
|
||||||
},
|
},
|
||||||
docs: None,
|
docs: None,
|
||||||
})
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for Definition {
|
impl TryToNav for Definition {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
match self {
|
match self {
|
||||||
Definition::Local(it) => Some(it.to_nav(db)),
|
Definition::Local(it) => Some(it.to_nav(db)),
|
||||||
Definition::Label(it) => Some(it.to_nav(db)),
|
Definition::Label(it) => Some(it.to_nav(db)),
|
||||||
|
@ -236,7 +247,7 @@ impl TryToNav for Definition {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::ModuleDef {
|
impl TryToNav for hir::ModuleDef {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
match self {
|
match self {
|
||||||
hir::ModuleDef::Module(it) => Some(it.to_nav(db)),
|
hir::ModuleDef::Module(it) => Some(it.to_nav(db)),
|
||||||
hir::ModuleDef::Function(it) => it.try_to_nav(db),
|
hir::ModuleDef::Function(it) => it.try_to_nav(db),
|
||||||
|
@ -334,22 +345,26 @@ where
|
||||||
D: HasSource + ToNavFromAst + Copy + HasDocs + HirDisplay,
|
D: HasSource + ToNavFromAst + Copy + HasDocs + HirDisplay,
|
||||||
D::Ast: ast::HasName,
|
D::Ast: ast::HasName,
|
||||||
{
|
{
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let src = self.source(db)?;
|
let src = self.source(db)?;
|
||||||
let mut res = NavigationTarget::from_named(
|
Some(
|
||||||
|
NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
src.as_ref().map(|it| it as &dyn ast::HasName),
|
src.as_ref().map(|it| it as &dyn ast::HasName),
|
||||||
D::KIND,
|
D::KIND,
|
||||||
);
|
)
|
||||||
|
.map(|mut res| {
|
||||||
res.docs = self.docs(db);
|
res.docs = self.docs(db);
|
||||||
res.description = Some(self.display(db).to_string());
|
res.description = Some(self.display(db).to_string());
|
||||||
res.container_name = self.container_name(db);
|
res.container_name = self.container_name(db);
|
||||||
Some(res)
|
res
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToNav for hir::Module {
|
impl ToNav for hir::Module {
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
fn to_nav(&self, db: &RootDatabase) -> UpmappingResult<NavigationTarget> {
|
||||||
let InFile { file_id, value } = self.definition_source(db);
|
let InFile { file_id, value } = self.definition_source(db);
|
||||||
|
|
||||||
let name = self.name(db).map(|it| it.to_smol_str()).unwrap_or_default();
|
let name = self.name(db).map(|it| it.to_smol_str()).unwrap_or_default();
|
||||||
|
@ -358,13 +373,23 @@ impl ToNav for hir::Module {
|
||||||
ModuleSource::Module(node) => (node.syntax(), node.name()),
|
ModuleSource::Module(node) => (node.syntax(), node.name()),
|
||||||
ModuleSource::BlockExpr(node) => (node.syntax(), None),
|
ModuleSource::BlockExpr(node) => (node.syntax(), None),
|
||||||
};
|
};
|
||||||
let (file_id, full_range, focus_range) = orig_range_with_focus(db, file_id, syntax, focus);
|
|
||||||
NavigationTarget::from_syntax(file_id, name, focus_range, full_range, SymbolKind::Module)
|
orig_range_with_focus(db, file_id, syntax, focus).map(
|
||||||
|
|(FileRange { file_id, range: full_range }, focus_range)| {
|
||||||
|
NavigationTarget::from_syntax(
|
||||||
|
file_id,
|
||||||
|
name.clone(),
|
||||||
|
focus_range,
|
||||||
|
full_range,
|
||||||
|
SymbolKind::Module,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::Impl {
|
impl TryToNav for hir::Impl {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let InFile { file_id, value } = self.source(db)?;
|
let InFile { file_id, value } = self.source(db)?;
|
||||||
let derive_path = self.as_builtin_derive_path(db);
|
let derive_path = self.as_builtin_derive_path(db);
|
||||||
|
|
||||||
|
@ -373,26 +398,30 @@ impl TryToNav for hir::Impl {
|
||||||
None => (file_id, value.self_ty(), value.syntax()),
|
None => (file_id, value.self_ty(), value.syntax()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (file_id, full_range, focus_range) = orig_range_with_focus(db, file_id, syntax, focus);
|
Some(orig_range_with_focus(db, file_id, syntax, focus).map(
|
||||||
Some(NavigationTarget::from_syntax(
|
|(FileRange { file_id, range: full_range }, focus_range)| {
|
||||||
|
NavigationTarget::from_syntax(
|
||||||
file_id,
|
file_id,
|
||||||
"impl".into(),
|
"impl".into(),
|
||||||
focus_range,
|
focus_range,
|
||||||
full_range,
|
full_range,
|
||||||
SymbolKind::Impl,
|
SymbolKind::Impl,
|
||||||
|
)
|
||||||
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::ExternCrateDecl {
|
impl TryToNav for hir::ExternCrateDecl {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let src = self.source(db)?;
|
let src = self.source(db)?;
|
||||||
let InFile { file_id, value } = src;
|
let InFile { file_id, value } = src;
|
||||||
let focus = value
|
let focus = value
|
||||||
.rename()
|
.rename()
|
||||||
.map_or_else(|| value.name_ref().map(Either::Left), |it| it.name().map(Either::Right));
|
.map_or_else(|| value.name_ref().map(Either::Left), |it| it.name().map(Either::Right));
|
||||||
let (file_id, full_range, focus_range) =
|
|
||||||
orig_range_with_focus(db, file_id, value.syntax(), focus);
|
Some(orig_range_with_focus(db, file_id, value.syntax(), focus).map(
|
||||||
|
|(FileRange { file_id, range: full_range }, focus_range)| {
|
||||||
let mut res = NavigationTarget::from_syntax(
|
let mut res = NavigationTarget::from_syntax(
|
||||||
file_id,
|
file_id,
|
||||||
self.alias_or_name(db).unwrap_or_else(|| self.name(db)).to_smol_str(),
|
self.alias_or_name(db).unwrap_or_else(|| self.name(db)).to_smol_str(),
|
||||||
|
@ -404,51 +433,65 @@ impl TryToNav for hir::ExternCrateDecl {
|
||||||
res.docs = self.docs(db);
|
res.docs = self.docs(db);
|
||||||
res.description = Some(self.display(db).to_string());
|
res.description = Some(self.display(db).to_string());
|
||||||
res.container_name = container_name(db, *self);
|
res.container_name = container_name(db, *self);
|
||||||
Some(res)
|
res
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::Field {
|
impl TryToNav for hir::Field {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let src = self.source(db)?;
|
let src = self.source(db)?;
|
||||||
|
|
||||||
let field_source = match &src.value {
|
let field_source = match &src.value {
|
||||||
FieldSource::Named(it) => {
|
FieldSource::Named(it) => {
|
||||||
let mut res =
|
NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field).map(
|
||||||
NavigationTarget::from_named(db, src.with_value(it), SymbolKind::Field);
|
|mut res| {
|
||||||
res.docs = self.docs(db);
|
res.docs = self.docs(db);
|
||||||
res.description = Some(self.display(db).to_string());
|
res.description = Some(self.display(db).to_string());
|
||||||
res
|
res
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
FieldSource::Pos(it) => {
|
FieldSource::Pos(it) => orig_range(db, src.file_id, it.syntax()).map(
|
||||||
let FileRange { file_id, range } =
|
|(FileRange { file_id, range: full_range }, focus_range)| {
|
||||||
src.with_value(it.syntax()).original_file_range(db);
|
NavigationTarget::from_syntax(
|
||||||
NavigationTarget::from_syntax(file_id, "".into(), None, range, SymbolKind::Field)
|
file_id,
|
||||||
}
|
format!("{}", self.index()).into(),
|
||||||
|
focus_range,
|
||||||
|
full_range,
|
||||||
|
SymbolKind::Field,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
};
|
};
|
||||||
Some(field_source)
|
Some(field_source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::Macro {
|
impl TryToNav for hir::Macro {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let src = self.source(db)?;
|
let src = self.source(db)?;
|
||||||
let name_owner: &dyn ast::HasName = match &src.value {
|
let name_owner: &dyn ast::HasName = match &src.value {
|
||||||
Either::Left(it) => it,
|
Either::Left(it) => it,
|
||||||
Either::Right(it) => it,
|
Either::Right(it) => it,
|
||||||
};
|
};
|
||||||
let mut res = NavigationTarget::from_named(
|
Some(
|
||||||
|
NavigationTarget::from_named(
|
||||||
db,
|
db,
|
||||||
src.as_ref().with_value(name_owner),
|
src.as_ref().with_value(name_owner),
|
||||||
self.kind(db).into(),
|
self.kind(db).into(),
|
||||||
);
|
)
|
||||||
|
.map(|mut res| {
|
||||||
res.docs = self.docs(db);
|
res.docs = self.docs(db);
|
||||||
Some(res)
|
res
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::Adt {
|
impl TryToNav for hir::Adt {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
match self {
|
match self {
|
||||||
hir::Adt::Struct(it) => it.try_to_nav(db),
|
hir::Adt::Struct(it) => it.try_to_nav(db),
|
||||||
hir::Adt::Union(it) => it.try_to_nav(db),
|
hir::Adt::Union(it) => it.try_to_nav(db),
|
||||||
|
@ -458,7 +501,7 @@ impl TryToNav for hir::Adt {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::AssocItem {
|
impl TryToNav for hir::AssocItem {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
match self {
|
match self {
|
||||||
AssocItem::Function(it) => it.try_to_nav(db),
|
AssocItem::Function(it) => it.try_to_nav(db),
|
||||||
AssocItem::Const(it) => it.try_to_nav(db),
|
AssocItem::Const(it) => it.try_to_nav(db),
|
||||||
|
@ -468,7 +511,7 @@ impl TryToNav for hir::AssocItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::GenericParam {
|
impl TryToNav for hir::GenericParam {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
match self {
|
match self {
|
||||||
hir::GenericParam::TypeParam(it) => it.try_to_nav(db),
|
hir::GenericParam::TypeParam(it) => it.try_to_nav(db),
|
||||||
hir::GenericParam::ConstParam(it) => it.try_to_nav(db),
|
hir::GenericParam::ConstParam(it) => it.try_to_nav(db),
|
||||||
|
@ -478,7 +521,7 @@ impl TryToNav for hir::GenericParam {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToNav for LocalSource {
|
impl ToNav for LocalSource {
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
fn to_nav(&self, db: &RootDatabase) -> UpmappingResult<NavigationTarget> {
|
||||||
let InFile { file_id, value } = &self.source;
|
let InFile { file_id, value } = &self.source;
|
||||||
let file_id = *file_id;
|
let file_id = *file_id;
|
||||||
let local = self.local;
|
let local = self.local;
|
||||||
|
@ -487,8 +530,8 @@ impl ToNav for LocalSource {
|
||||||
Either::Right(it) => (it.syntax(), it.name()),
|
Either::Right(it) => (it.syntax(), it.name()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (file_id, full_range, focus_range) = orig_range_with_focus(db, file_id, node, name);
|
orig_range_with_focus(db, file_id, node, name).map(
|
||||||
|
|(FileRange { file_id, range: full_range }, focus_range)| {
|
||||||
let name = local.name(db).to_smol_str();
|
let name = local.name(db).to_smol_str();
|
||||||
let kind = if local.is_self(db) {
|
let kind = if local.is_self(db) {
|
||||||
SymbolKind::SelfParam
|
SymbolKind::SelfParam
|
||||||
|
@ -508,26 +551,26 @@ impl ToNav for LocalSource {
|
||||||
description: None,
|
description: None,
|
||||||
docs: None,
|
docs: None,
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToNav for hir::Local {
|
impl ToNav for hir::Local {
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
fn to_nav(&self, db: &RootDatabase) -> UpmappingResult<NavigationTarget> {
|
||||||
self.primary_source(db).to_nav(db)
|
self.primary_source(db).to_nav(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToNav for hir::Label {
|
impl ToNav for hir::Label {
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
fn to_nav(&self, db: &RootDatabase) -> UpmappingResult<NavigationTarget> {
|
||||||
let InFile { file_id, value } = self.source(db);
|
let InFile { file_id, value } = self.source(db);
|
||||||
let name = self.name(db).to_smol_str();
|
let name = self.name(db).to_smol_str();
|
||||||
|
|
||||||
let (file_id, full_range, focus_range) =
|
orig_range_with_focus(db, file_id, value.syntax(), value.lifetime()).map(
|
||||||
orig_range_with_focus(db, file_id, value.syntax(), value.lifetime());
|
|(FileRange { file_id, range: full_range }, focus_range)| NavigationTarget {
|
||||||
|
|
||||||
NavigationTarget {
|
|
||||||
file_id,
|
file_id,
|
||||||
name,
|
name: name.clone(),
|
||||||
alias: None,
|
alias: None,
|
||||||
kind: Some(SymbolKind::Label),
|
kind: Some(SymbolKind::Label),
|
||||||
full_range,
|
full_range,
|
||||||
|
@ -535,12 +578,13 @@ impl ToNav for hir::Label {
|
||||||
container_name: None,
|
container_name: None,
|
||||||
description: None,
|
description: None,
|
||||||
docs: None,
|
docs: None,
|
||||||
}
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::TypeParam {
|
impl TryToNav for hir::TypeParam {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let InFile { file_id, value } = self.merge().source(db)?;
|
let InFile { file_id, value } = self.merge().source(db)?;
|
||||||
let name = self.name(db).to_smol_str();
|
let name = self.name(db).to_smol_str();
|
||||||
|
|
||||||
|
@ -559,11 +603,10 @@ impl TryToNav for hir::TypeParam {
|
||||||
};
|
};
|
||||||
let focus = value.as_ref().either(|it| it.name(), |it| it.name());
|
let focus = value.as_ref().either(|it| it.name(), |it| it.name());
|
||||||
|
|
||||||
let (file_id, full_range, focus_range) = orig_range_with_focus(db, file_id, syntax, focus);
|
Some(orig_range_with_focus(db, file_id, syntax, focus).map(
|
||||||
|
|(FileRange { file_id, range: full_range }, focus_range)| NavigationTarget {
|
||||||
Some(NavigationTarget {
|
|
||||||
file_id,
|
file_id,
|
||||||
name,
|
name: name.clone(),
|
||||||
alias: None,
|
alias: None,
|
||||||
kind: Some(SymbolKind::TypeParam),
|
kind: Some(SymbolKind::TypeParam),
|
||||||
full_range,
|
full_range,
|
||||||
|
@ -571,39 +614,40 @@ impl TryToNav for hir::TypeParam {
|
||||||
container_name: None,
|
container_name: None,
|
||||||
description: None,
|
description: None,
|
||||||
docs: None,
|
docs: None,
|
||||||
})
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::TypeOrConstParam {
|
impl TryToNav for hir::TypeOrConstParam {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
self.split(db).try_to_nav(db)
|
self.split(db).try_to_nav(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::LifetimeParam {
|
impl TryToNav for hir::LifetimeParam {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let InFile { file_id, value } = self.source(db)?;
|
let InFile { file_id, value } = self.source(db)?;
|
||||||
let name = self.name(db).to_smol_str();
|
let name = self.name(db).to_smol_str();
|
||||||
|
|
||||||
let FileRange { file_id, range } =
|
Some(orig_range(db, file_id, value.syntax()).map(
|
||||||
InFile::new(file_id, value.syntax()).original_file_range(db);
|
|(FileRange { file_id, range: full_range }, focus_range)| NavigationTarget {
|
||||||
Some(NavigationTarget {
|
|
||||||
file_id,
|
file_id,
|
||||||
name,
|
name: name.clone(),
|
||||||
alias: None,
|
alias: None,
|
||||||
kind: Some(SymbolKind::LifetimeParam),
|
kind: Some(SymbolKind::LifetimeParam),
|
||||||
full_range: range,
|
full_range,
|
||||||
focus_range: Some(range),
|
focus_range,
|
||||||
container_name: None,
|
container_name: None,
|
||||||
description: None,
|
description: None,
|
||||||
docs: None,
|
docs: None,
|
||||||
})
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryToNav for hir::ConstParam {
|
impl TryToNav for hir::ConstParam {
|
||||||
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
|
fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> {
|
||||||
let InFile { file_id, value } = self.merge().source(db)?;
|
let InFile { file_id, value } = self.merge().source(db)?;
|
||||||
let name = self.name(db).to_smol_str();
|
let name = self.name(db).to_smol_str();
|
||||||
|
|
||||||
|
@ -615,11 +659,10 @@ impl TryToNav for hir::ConstParam {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let (file_id, full_range, focus_range) =
|
Some(orig_range_with_focus(db, file_id, value.syntax(), value.name()).map(
|
||||||
orig_range_with_focus(db, file_id, value.syntax(), value.name());
|
|(FileRange { file_id, range: full_range }, focus_range)| NavigationTarget {
|
||||||
Some(NavigationTarget {
|
|
||||||
file_id,
|
file_id,
|
||||||
name,
|
name: name.clone(),
|
||||||
alias: None,
|
alias: None,
|
||||||
kind: Some(SymbolKind::ConstParam),
|
kind: Some(SymbolKind::ConstParam),
|
||||||
full_range,
|
full_range,
|
||||||
|
@ -627,34 +670,169 @@ impl TryToNav for hir::ConstParam {
|
||||||
container_name: None,
|
container_name: None,
|
||||||
description: None,
|
description: None,
|
||||||
docs: None,
|
docs: None,
|
||||||
})
|
},
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct UpmappingResult<T> {
|
||||||
|
/// The macro call site.
|
||||||
|
pub call_site: T,
|
||||||
|
/// The macro definition site, if relevant.
|
||||||
|
pub def_site: Option<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> UpmappingResult<T> {
|
||||||
|
pub fn call_site(self) -> T {
|
||||||
|
self.call_site
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn collect<FI: FromIterator<T>>(self) -> FI {
|
||||||
|
FI::from_iter(self.into_iter())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> IntoIterator for UpmappingResult<T> {
|
||||||
|
type Item = T;
|
||||||
|
|
||||||
|
type IntoIter = <ArrayVec<T, 2> as IntoIterator>::IntoIter;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.def_site
|
||||||
|
.into_iter()
|
||||||
|
.chain(Some(self.call_site))
|
||||||
|
.collect::<ArrayVec<_, 2>>()
|
||||||
|
.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> UpmappingResult<T> {
|
||||||
|
fn map<U>(self, f: impl Fn(T) -> U) -> UpmappingResult<U> {
|
||||||
|
UpmappingResult { call_site: f(self.call_site), def_site: self.def_site.map(f) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the original range of the syntax node, and the range of the name mapped out of macro expansions
|
/// Returns the original range of the syntax node, and the range of the name mapped out of macro expansions
|
||||||
/// Additionally verifies that the name span is in bounds and related to the original range.
|
/// May return two results if the mapped node originates from a macro definition in which case the
|
||||||
|
/// second result is the creating macro call.
|
||||||
fn orig_range_with_focus(
|
fn orig_range_with_focus(
|
||||||
db: &RootDatabase,
|
db: &RootDatabase,
|
||||||
hir_file: HirFileId,
|
hir_file: HirFileId,
|
||||||
value: &SyntaxNode,
|
value: &SyntaxNode,
|
||||||
name: Option<impl AstNode>,
|
name: Option<impl AstNode>,
|
||||||
) -> (FileId, TextRange, Option<TextRange>) {
|
) -> UpmappingResult<(FileRange, Option<TextRange>)> {
|
||||||
let FileRange { file_id, range } =
|
let Some(name) = name else { return orig_range(db, hir_file, value) };
|
||||||
match InFile::new(hir_file, value).original_file_range_opt(db) {
|
|
||||||
Some((range, ctxt)) if ctxt.is_root() => range,
|
|
||||||
_ => db
|
|
||||||
.lookup_intern_macro_call(hir_file.macro_file().unwrap().macro_call_id)
|
|
||||||
.kind
|
|
||||||
.original_call_range(db),
|
|
||||||
};
|
|
||||||
let focus_range = name
|
|
||||||
.and_then(|it| InFile::new(hir_file, it.syntax()).original_file_range_opt(db))
|
|
||||||
.filter(|(frange, ctxt)| {
|
|
||||||
ctxt.is_root() && frange.file_id == file_id && frange.range.contains_range(frange.range)
|
|
||||||
})
|
|
||||||
.map(|(frange, _ctxt)| frange.range);
|
|
||||||
|
|
||||||
(file_id, range, focus_range)
|
let call_range = || {
|
||||||
|
db.lookup_intern_macro_call(hir_file.macro_file().unwrap().macro_call_id)
|
||||||
|
.kind
|
||||||
|
.original_call_range(db)
|
||||||
|
};
|
||||||
|
|
||||||
|
let def_range = || {
|
||||||
|
db.lookup_intern_macro_call(hir_file.macro_file().unwrap().macro_call_id)
|
||||||
|
.def
|
||||||
|
.definition_range(db)
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIXME What about include!d things
|
||||||
|
|
||||||
|
let value_range = InFile::new(hir_file, value).original_file_range_opt(db);
|
||||||
|
let ((call_site_range, call_site_focus), def_site) =
|
||||||
|
match InFile::new(hir_file, name.syntax()).original_file_range_opt(db) {
|
||||||
|
// call site name
|
||||||
|
Some((focus_range, ctxt)) if ctxt.is_root() => {
|
||||||
|
// Try to upmap the node as well, if it ends up in the def site, go back to the call site
|
||||||
|
(
|
||||||
|
(
|
||||||
|
match value_range {
|
||||||
|
// name is in the node in the macro input so we can return it
|
||||||
|
Some((range, ctxt))
|
||||||
|
if ctxt.is_root()
|
||||||
|
&& range.file_id == focus_range.file_id
|
||||||
|
&& range.range.contains_range(focus_range.range) =>
|
||||||
|
{
|
||||||
|
range
|
||||||
|
}
|
||||||
|
// name lies outside the node, so instead point to the macro call which
|
||||||
|
// *should* contain the name
|
||||||
|
_ => call_range(),
|
||||||
|
},
|
||||||
|
Some(focus_range),
|
||||||
|
),
|
||||||
|
// no def site relevant
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// def site name
|
||||||
|
// FIXME: This can be de improved
|
||||||
|
Some((focus_range, _ctxt)) => {
|
||||||
|
match value_range {
|
||||||
|
// but overall node is in macro input
|
||||||
|
Some((range, ctxt)) if ctxt.is_root() => (
|
||||||
|
// node mapped up in call site, show the node
|
||||||
|
(range, None),
|
||||||
|
// def site, if the name is in the (possibly) upmapped def site range, show the
|
||||||
|
// def site
|
||||||
|
{
|
||||||
|
let (def_site, _) = def_range().original_node_file_range(db);
|
||||||
|
(def_site.file_id == focus_range.file_id
|
||||||
|
&& def_site.range.contains_range(focus_range.range))
|
||||||
|
.then_some((def_site, Some(focus_range)))
|
||||||
|
},
|
||||||
|
),
|
||||||
|
// node is in macro def, just show the focus
|
||||||
|
_ => (
|
||||||
|
// show the macro call
|
||||||
|
(call_range(), None),
|
||||||
|
Some((focus_range, Some(focus_range))),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// lost name? can't happen for single tokens
|
||||||
|
None => return orig_range(db, hir_file, value),
|
||||||
|
};
|
||||||
|
|
||||||
|
UpmappingResult {
|
||||||
|
call_site: (
|
||||||
|
call_site_range,
|
||||||
|
call_site_focus.and_then(|FileRange { file_id, range }| {
|
||||||
|
if call_site_range.file_id == file_id && call_site_range.range.contains_range(range)
|
||||||
|
{
|
||||||
|
Some(range)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
def_site: def_site.map(|(def_site_range, def_site_focus)| {
|
||||||
|
(
|
||||||
|
def_site_range,
|
||||||
|
def_site_focus.and_then(|FileRange { file_id, range }| {
|
||||||
|
if def_site_range.file_id == file_id
|
||||||
|
&& def_site_range.range.contains_range(range)
|
||||||
|
{
|
||||||
|
Some(range)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn orig_range(
|
||||||
|
db: &RootDatabase,
|
||||||
|
hir_file: HirFileId,
|
||||||
|
value: &SyntaxNode,
|
||||||
|
) -> UpmappingResult<(FileRange, Option<TextRange>)> {
|
||||||
|
UpmappingResult {
|
||||||
|
call_site: (InFile::new(hir_file, value).original_file_range(db), None),
|
||||||
|
def_site: None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -45,11 +45,11 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
|
||||||
Some(module) => sema
|
Some(module) => sema
|
||||||
.to_def(&module)
|
.to_def(&module)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|module| NavigationTarget::from_module_to_decl(db, module))
|
.flat_map(|module| NavigationTarget::from_module_to_decl(db, module))
|
||||||
.collect(),
|
.collect(),
|
||||||
None => sema
|
None => sema
|
||||||
.to_module_defs(position.file_id)
|
.to_module_defs(position.file_id)
|
||||||
.map(|module| NavigationTarget::from_module_to_decl(db, module))
|
.flat_map(|module| NavigationTarget::from_module_to_decl(db, module))
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
//! at the index that the match starts at and its tree parent is
|
//! at the index that the match starts at and its tree parent is
|
||||||
//! resolved to the search element definition, we get a reference.
|
//! resolved to the search element definition, we get a reference.
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use hir::{DescendPreference, PathResolution, Semantics};
|
use hir::{DescendPreference, PathResolution, Semantics};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::FileId,
|
base_db::FileId,
|
||||||
|
@ -60,19 +62,6 @@ pub(crate) fn find_all_refs(
|
||||||
let syntax = sema.parse(position.file_id).syntax().clone();
|
let syntax = sema.parse(position.file_id).syntax().clone();
|
||||||
let make_searcher = |literal_search: bool| {
|
let make_searcher = |literal_search: bool| {
|
||||||
move |def: Definition| {
|
move |def: Definition| {
|
||||||
let declaration = match def {
|
|
||||||
Definition::Module(module) => {
|
|
||||||
Some(NavigationTarget::from_module_to_decl(sema.db, module))
|
|
||||||
}
|
|
||||||
def => def.try_to_nav(sema.db),
|
|
||||||
}
|
|
||||||
.map(|nav| {
|
|
||||||
let decl_range = nav.focus_or_full_range();
|
|
||||||
Declaration {
|
|
||||||
is_mut: decl_mutability(&def, sema.parse(nav.file_id).syntax(), decl_range),
|
|
||||||
nav,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let mut usages =
|
let mut usages =
|
||||||
def.usages(sema).set_scope(search_scope.as_ref()).include_self_refs().all();
|
def.usages(sema).set_scope(search_scope.as_ref()).include_self_refs().all();
|
||||||
|
|
||||||
|
@ -80,7 +69,7 @@ pub(crate) fn find_all_refs(
|
||||||
retain_adt_literal_usages(&mut usages, def, sema);
|
retain_adt_literal_usages(&mut usages, def, sema);
|
||||||
}
|
}
|
||||||
|
|
||||||
let references = usages
|
let mut references = usages
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(file_id, refs)| {
|
.map(|(file_id, refs)| {
|
||||||
(
|
(
|
||||||
|
@ -91,8 +80,30 @@ pub(crate) fn find_all_refs(
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect::<HashMap<_, Vec<_>, _>>();
|
||||||
|
let declaration = match def {
|
||||||
|
Definition::Module(module) => {
|
||||||
|
Some(NavigationTarget::from_module_to_decl(sema.db, module))
|
||||||
|
}
|
||||||
|
def => def.try_to_nav(sema.db),
|
||||||
|
}
|
||||||
|
.map(|nav| {
|
||||||
|
let (nav, extra_ref) = match nav.def_site {
|
||||||
|
Some(call) => (call, Some(nav.call_site)),
|
||||||
|
None => (nav.call_site, None),
|
||||||
|
};
|
||||||
|
if let Some(extra_ref) = extra_ref {
|
||||||
|
references
|
||||||
|
.entry(extra_ref.file_id)
|
||||||
|
.or_default()
|
||||||
|
.push((extra_ref.focus_or_full_range(), None));
|
||||||
|
}
|
||||||
|
let decl_range = nav.focus_or_full_range();
|
||||||
|
Declaration {
|
||||||
|
is_mut: decl_mutability(&def, sema.parse(nav.file_id).syntax(), decl_range),
|
||||||
|
nav,
|
||||||
|
}
|
||||||
|
});
|
||||||
ReferenceSearchResult { declaration, references }
|
ReferenceSearchResult { declaration, references }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -882,7 +893,7 @@ pub(super) struct Foo$0 {
|
||||||
|
|
||||||
check_with_scope(
|
check_with_scope(
|
||||||
code,
|
code,
|
||||||
Some(SearchScope::single_file(FileId(2))),
|
Some(SearchScope::single_file(FileId::from_raw(2))),
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
quux Function FileId(0) 19..35 26..30
|
quux Function FileId(0) 19..35 26..30
|
||||||
|
|
||||||
|
@ -1181,7 +1192,7 @@ fn foo<'a, 'b: 'a>(x: &'a$0 ()) -> &'a () where &'a (): Foo<'a> {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
'a LifetimeParam FileId(0) 55..57 55..57
|
'a LifetimeParam FileId(0) 55..57
|
||||||
|
|
||||||
FileId(0) 63..65
|
FileId(0) 63..65
|
||||||
FileId(0) 71..73
|
FileId(0) 71..73
|
||||||
|
@ -1199,7 +1210,7 @@ fn foo<'a, 'b: 'a>(x: &'a$0 ()) -> &'a () where &'a (): Foo<'a> {
|
||||||
type Foo<'a, T> where T: 'a$0 = &'a T;
|
type Foo<'a, T> where T: 'a$0 = &'a T;
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
'a LifetimeParam FileId(0) 9..11 9..11
|
'a LifetimeParam FileId(0) 9..11
|
||||||
|
|
||||||
FileId(0) 25..27
|
FileId(0) 25..27
|
||||||
FileId(0) 31..33
|
FileId(0) 31..33
|
||||||
|
@ -1221,7 +1232,7 @@ impl<'a> Foo<'a> for &'a () {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
'a LifetimeParam FileId(0) 47..49 47..49
|
'a LifetimeParam FileId(0) 47..49
|
||||||
|
|
||||||
FileId(0) 55..57
|
FileId(0) 55..57
|
||||||
FileId(0) 64..66
|
FileId(0) 64..66
|
||||||
|
|
|
@ -335,7 +335,8 @@ pub(crate) fn runnable_fn(
|
||||||
sema.db,
|
sema.db,
|
||||||
def.source(sema.db)?.as_ref().map(|it| it as &dyn ast::HasName),
|
def.source(sema.db)?.as_ref().map(|it| it as &dyn ast::HasName),
|
||||||
SymbolKind::Function,
|
SymbolKind::Function,
|
||||||
);
|
)
|
||||||
|
.call_site();
|
||||||
let cfg = def.attrs(sema.db).cfg();
|
let cfg = def.attrs(sema.db).cfg();
|
||||||
Some(Runnable { use_name_in_title: false, nav, kind, cfg })
|
Some(Runnable { use_name_in_title: false, nav, kind, cfg })
|
||||||
}
|
}
|
||||||
|
@ -357,7 +358,7 @@ pub(crate) fn runnable_mod(
|
||||||
|
|
||||||
let attrs = def.attrs(sema.db);
|
let attrs = def.attrs(sema.db);
|
||||||
let cfg = attrs.cfg();
|
let cfg = attrs.cfg();
|
||||||
let nav = NavigationTarget::from_module_to_decl(sema.db, def);
|
let nav = NavigationTarget::from_module_to_decl(sema.db, def).call_site();
|
||||||
Some(Runnable { use_name_in_title: false, nav, kind: RunnableKind::TestMod { path }, cfg })
|
Some(Runnable { use_name_in_title: false, nav, kind: RunnableKind::TestMod { path }, cfg })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +371,7 @@ pub(crate) fn runnable_impl(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let cfg = attrs.cfg();
|
let cfg = attrs.cfg();
|
||||||
let nav = def.try_to_nav(sema.db)?;
|
let nav = def.try_to_nav(sema.db)?.call_site();
|
||||||
let ty = def.self_ty(sema.db);
|
let ty = def.self_ty(sema.db);
|
||||||
let adt_name = ty.as_adt()?.name(sema.db);
|
let adt_name = ty.as_adt()?.name(sema.db);
|
||||||
let mut ty_args = ty.generic_parameters(sema.db).peekable();
|
let mut ty_args = ty.generic_parameters(sema.db).peekable();
|
||||||
|
@ -407,7 +408,7 @@ fn runnable_mod_outline_definition(
|
||||||
match def.definition_source(sema.db).value {
|
match def.definition_source(sema.db).value {
|
||||||
hir::ModuleSource::SourceFile(_) => Some(Runnable {
|
hir::ModuleSource::SourceFile(_) => Some(Runnable {
|
||||||
use_name_in_title: false,
|
use_name_in_title: false,
|
||||||
nav: def.to_nav(sema.db),
|
nav: def.to_nav(sema.db).call_site(),
|
||||||
kind: RunnableKind::TestMod { path },
|
kind: RunnableKind::TestMod { path },
|
||||||
cfg,
|
cfg,
|
||||||
}),
|
}),
|
||||||
|
@ -465,7 +466,8 @@ fn module_def_doctest(db: &RootDatabase, def: Definition) -> Option<Runnable> {
|
||||||
let mut nav = match def {
|
let mut nav = match def {
|
||||||
Definition::Module(def) => NavigationTarget::from_module_to_decl(db, def),
|
Definition::Module(def) => NavigationTarget::from_module_to_decl(db, def),
|
||||||
def => def.try_to_nav(db)?,
|
def => def.try_to_nav(db)?,
|
||||||
};
|
}
|
||||||
|
.call_site();
|
||||||
nav.focus_range = None;
|
nav.focus_range = None;
|
||||||
nav.description = None;
|
nav.description = None;
|
||||||
nav.docs = None;
|
nav.docs = None;
|
||||||
|
|
|
@ -13,6 +13,7 @@ use ide_db::{
|
||||||
use syntax::{AstNode, SyntaxKind::*, TextRange, T};
|
use syntax::{AstNode, SyntaxKind::*, TextRange, T};
|
||||||
|
|
||||||
use crate::inlay_hints::InlayFieldsToResolve;
|
use crate::inlay_hints::InlayFieldsToResolve;
|
||||||
|
use crate::navigation_target::UpmappingResult;
|
||||||
use crate::{
|
use crate::{
|
||||||
hover::hover_for_definition,
|
hover::hover_for_definition,
|
||||||
inlay_hints::AdjustmentHintsMode,
|
inlay_hints::AdjustmentHintsMode,
|
||||||
|
@ -166,9 +167,8 @@ impl StaticIndex<'_> {
|
||||||
} else {
|
} else {
|
||||||
let it = self.tokens.insert(TokenStaticData {
|
let it = self.tokens.insert(TokenStaticData {
|
||||||
hover: hover_for_definition(&sema, file_id, def, &node, &hover_config),
|
hover: hover_for_definition(&sema, file_id, def, &node, &hover_config),
|
||||||
definition: def.try_to_nav(self.db).map(|it| FileRange {
|
definition: def.try_to_nav(self.db).map(UpmappingResult::call_site).map(|it| {
|
||||||
file_id: it.file_id,
|
FileRange { file_id: it.file_id, range: it.focus_or_full_range() }
|
||||||
range: it.focus_or_full_range(),
|
|
||||||
}),
|
}),
|
||||||
references: vec![],
|
references: vec![],
|
||||||
moniker: current_crate.and_then(|cc| def_to_moniker(self.db, def, cc)),
|
moniker: current_crate.and_then(|cc| def_to_moniker(self.db, def, cc)),
|
||||||
|
@ -179,7 +179,7 @@ impl StaticIndex<'_> {
|
||||||
let token = self.tokens.get_mut(id).unwrap();
|
let token = self.tokens.get_mut(id).unwrap();
|
||||||
token.references.push(ReferenceData {
|
token.references.push(ReferenceData {
|
||||||
range: FileRange { range, file_id },
|
range: FileRange { range, file_id },
|
||||||
is_definition: match def.try_to_nav(self.db) {
|
is_definition: match def.try_to_nav(self.db).map(UpmappingResult::call_site) {
|
||||||
Some(it) => it.file_id == file_id && it.focus_or_full_range() == range,
|
Some(it) => it.file_id == file_id && it.focus_or_full_range() == range,
|
||||||
None => false,
|
None => false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -147,8 +147,10 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn fixture_token_tree() -> Subtree<SpanData> {
|
fn fixture_token_tree() -> Subtree<SpanData> {
|
||||||
let anchor =
|
let anchor = SpanAnchor {
|
||||||
SpanAnchor { file_id: FileId(0), ast_id: ErasedFileAstId::from_raw(RawIdx::from(0)) };
|
file_id: FileId::from_raw(0),
|
||||||
|
ast_id: ErasedFileAstId::from_raw(RawIdx::from(0)),
|
||||||
|
};
|
||||||
let mut subtree = Subtree {
|
let mut subtree = Subtree {
|
||||||
delimiter: Delimiter {
|
delimiter: Delimiter {
|
||||||
open: SpanData {
|
open: SpanData {
|
||||||
|
|
|
@ -58,7 +58,7 @@ fn load_cargo_with_sysroot(
|
||||||
&mut {
|
&mut {
|
||||||
|path| {
|
|path| {
|
||||||
let len = file_map.len();
|
let len = file_map.len();
|
||||||
Some(*file_map.entry(path.to_path_buf()).or_insert(FileId(len as u32)))
|
Some(*file_map.entry(path.to_path_buf()).or_insert(FileId::from_raw(len as u32)))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
|
@ -142,7 +142,7 @@ fn to_crate_graph(project_workspace: ProjectWorkspace) -> (CrateGraph, ProcMacro
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
move |_path| {
|
move |_path| {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
Some(FileId(counter))
|
Some(FileId::from_raw(counter))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
|
|
|
@ -1438,7 +1438,7 @@ pub(crate) fn handle_inlay_hints_resolve(
|
||||||
};
|
};
|
||||||
|
|
||||||
let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
|
let resolve_data: lsp_ext::InlayHintResolveData = serde_json::from_value(data)?;
|
||||||
let file_id = FileId(resolve_data.file_id);
|
let file_id = FileId::from_raw(resolve_data.file_id);
|
||||||
anyhow::ensure!(snap.file_exists(file_id), "Invalid LSP resolve data");
|
anyhow::ensure!(snap.file_exists(file_id), "Invalid LSP resolve data");
|
||||||
|
|
||||||
let line_index = snap.file_line_index(file_id)?;
|
let line_index = snap.file_line_index(file_id)?;
|
||||||
|
|
|
@ -457,7 +457,7 @@ pub(crate) fn inlay_hint(
|
||||||
inlay_hint.text_edit.map(|it| text_edit_vec(line_index, it))
|
inlay_hint.text_edit.map(|it| text_edit_vec(line_index, it))
|
||||||
};
|
};
|
||||||
let data = if needs_resolve && something_to_resolve {
|
let data = if needs_resolve && something_to_resolve {
|
||||||
Some(to_value(lsp_ext::InlayHintResolveData { file_id: file_id.0 }).unwrap())
|
Some(to_value(lsp_ext::InlayHintResolveData { file_id: file_id.index() }).unwrap())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,12 +22,17 @@ use crate::{syntax_node::RustLanguage, AstNode, SyntaxNode};
|
||||||
pub type SyntaxNodePtr = rowan::ast::SyntaxNodePtr<RustLanguage>;
|
pub type SyntaxNodePtr = rowan::ast::SyntaxNodePtr<RustLanguage>;
|
||||||
|
|
||||||
/// Like `SyntaxNodePtr`, but remembers the type of node.
|
/// Like `SyntaxNodePtr`, but remembers the type of node.
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct AstPtr<N: AstNode> {
|
pub struct AstPtr<N: AstNode> {
|
||||||
raw: SyntaxNodePtr,
|
raw: SyntaxNodePtr,
|
||||||
_ty: PhantomData<fn() -> N>,
|
_ty: PhantomData<fn() -> N>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<N: AstNode + std::fmt::Debug> std::fmt::Debug for AstPtr<N> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_tuple("AstPtr").field(&self.raw).finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<N: AstNode> Clone for AstPtr<N> {
|
impl<N: AstNode> Clone for AstPtr<N> {
|
||||||
fn clone(&self) -> AstPtr<N> {
|
fn clone(&self) -> AstPtr<N> {
|
||||||
AstPtr { raw: self.raw.clone(), _ty: PhantomData }
|
AstPtr { raw: self.raw.clone(), _ty: PhantomData }
|
||||||
|
|
|
@ -60,11 +60,21 @@ pub use paths::{AbsPath, AbsPathBuf};
|
||||||
///
|
///
|
||||||
/// Most functions in rust-analyzer use this when they need to refer to a file.
|
/// Most functions in rust-analyzer use this when they need to refer to a file.
|
||||||
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
||||||
pub struct FileId(pub u32);
|
pub struct FileId(u32);
|
||||||
|
|
||||||
impl FileId {
|
impl FileId {
|
||||||
/// Think twice about using this outside of tests. If this ends up in a wrong place it will cause panics!
|
/// Think twice about using this outside of tests. If this ends up in a wrong place it will cause panics!
|
||||||
pub const BOGUS: FileId = FileId(u32::MAX);
|
pub const BOGUS: FileId = FileId(0xe4e4e);
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn from_raw(raw: u32) -> FileId {
|
||||||
|
FileId(raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn index(self) -> u32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// safe because `FileId` is a newtype of `u32`
|
/// safe because `FileId` is a newtype of `u32`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue