From 9763d9e8c4ca01a4df0d70877020ec7351403b75 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 15 Mar 2021 09:32:06 +0100 Subject: Enable searching for builtin types --- crates/ide_db/src/defs.rs | 2 +- crates/ide_db/src/search.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index ff612b7d0..f86e5ce93 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs @@ -70,7 +70,7 @@ impl Definition { hir::ModuleDef::Static(it) => it.name(db)?, hir::ModuleDef::Trait(it) => it.name(db), hir::ModuleDef::TypeAlias(it) => it.name(db), - hir::ModuleDef::BuiltinType(_) => return None, + hir::ModuleDef::BuiltinType(it) => it.name(), }, Definition::SelfType(_) => return None, Definition::Local(it) => it.name(db)?, diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index ddcfbd3f3..1615d407e 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -6,7 +6,7 @@ use std::{convert::TryInto, mem}; -use base_db::{FileId, FileRange, SourceDatabaseExt}; +use base_db::{FileId, FileRange, SourceDatabase, SourceDatabaseExt}; use hir::{DefWithBody, HasSource, Module, ModuleSource, Semantics, Visibility}; use once_cell::unsync::Lazy; use rustc_hash::FxHashMap; @@ -134,6 +134,20 @@ impl IntoIterator for SearchScope { impl Definition { fn search_scope(&self, db: &RootDatabase) -> SearchScope { let _p = profile::span("search_scope"); + + if let Definition::ModuleDef(hir::ModuleDef::BuiltinType(_)) = self { + let mut res = FxHashMap::default(); + + let graph = db.crate_graph(); + for krate in graph.iter() { + let root_file = graph[krate].root_file_id; + let source_root_id = db.file_source_root(root_file); + let source_root = db.source_root(source_root_id); + res.extend(source_root.iter().map(|id| (id, None))); + } + return SearchScope::new(res); + } + let module = match self.module(db) { Some(it) => it, None => return SearchScope::empty(), -- cgit v1.2.3