Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/static_index.rs')
-rw-r--r--crates/ide/src/static_index.rs81
1 files changed, 68 insertions, 13 deletions
diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs
index eaccee08e8..1cbe8c62a8 100644
--- a/crates/ide/src/static_index.rs
+++ b/crates/ide/src/static_index.rs
@@ -10,6 +10,7 @@ use ide_db::{
helpers::get_definition,
FileId, FileRange, FxHashMap, FxHashSet, RootDatabase,
};
+use span::Edition;
use syntax::{AstNode, SyntaxKind::*, SyntaxNode, TextRange, T};
use crate::inlay_hints::InlayFieldsToResolve;
@@ -116,7 +117,16 @@ fn documentation_for_definition(
_ => None,
};
- def.docs(sema.db, famous_defs.as_ref())
+ def.docs(
+ sema.db,
+ famous_defs.as_ref(),
+ def.krate(sema.db).map(|it| it.edition(sema.db)).unwrap_or(Edition::CURRENT),
+ )
+}
+
+pub enum VendoredLibrariesConfig<'a> {
+ Included { workspace_root: &'a VfsPath },
+ Excluded,
}
impl StaticIndex<'_> {
@@ -161,6 +171,8 @@ impl StaticIndex<'_> {
// hovers
let sema = hir::Semantics::new(self.db);
let tokens_or_nodes = sema.parse_guess_edition(file_id).syntax().clone();
+ let edition =
+ sema.attach_first_edition(file_id).map(|it| it.edition()).unwrap_or(Edition::CURRENT);
let tokens = tokens_or_nodes.descendants_with_tokens().filter_map(|it| match it {
syntax::NodeOrToken::Node(_) => None,
syntax::NodeOrToken::Token(it) => Some(it),
@@ -201,17 +213,20 @@ impl StaticIndex<'_> {
&node,
None,
&hover_config,
+ edition,
)),
definition: def.try_to_nav(self.db).map(UpmappingResult::call_site).map(|it| {
FileRange { file_id: it.file_id, range: it.focus_or_full_range() }
}),
references: vec![],
moniker: current_crate.and_then(|cc| def_to_moniker(self.db, def, cc)),
- display_name: def.name(self.db).map(|name| name.display(self.db).to_string()),
+ display_name: def
+ .name(self.db)
+ .map(|name| name.display(self.db, edition).to_string()),
enclosing_moniker: current_crate
.zip(def.enclosing_definition(self.db))
.and_then(|(cc, enclosing_def)| def_to_moniker(self.db, enclosing_def, cc)),
- signature: Some(def.label(self.db)),
+ signature: Some(def.label(self.db, edition)),
kind: def_to_kind(self.db, def),
});
self.def_map.insert(def, it);
@@ -230,15 +245,22 @@ impl StaticIndex<'_> {
self.files.push(result);
}
- pub fn compute<'a>(analysis: &'a Analysis, workspace_root: &VfsPath) -> StaticIndex<'a> {
+ pub fn compute<'a>(
+ analysis: &'a Analysis,
+ vendored_libs_config: VendoredLibrariesConfig<'_>,
+ ) -> StaticIndex<'a> {
let db = &*analysis.db;
let work = all_modules(db).into_iter().filter(|module| {
let file_id = module.definition_source_file_id(db).original_file(db);
let source_root = db.file_source_root(file_id.into());
let source_root = db.source_root(source_root);
- let is_vendored = source_root
- .path_for_file(&file_id.into())
- .is_some_and(|module_path| module_path.starts_with(workspace_root));
+ let is_vendored = match vendored_libs_config {
+ VendoredLibrariesConfig::Included { workspace_root } => source_root
+ .path_for_file(&file_id.into())
+ .is_some_and(|module_path| module_path.starts_with(workspace_root)),
+ VendoredLibrariesConfig::Excluded => false,
+ };
+
!source_root.is_library || is_vendored
});
let mut this = StaticIndex {
@@ -268,10 +290,11 @@ mod tests {
use ide_db::{base_db::VfsPath, FileRange, FxHashSet};
use syntax::TextSize;
- fn check_all_ranges(ra_fixture: &str) {
+ use super::VendoredLibrariesConfig;
+
+ fn check_all_ranges(ra_fixture: &str, vendored_libs_config: VendoredLibrariesConfig<'_>) {
let (analysis, ranges) = fixture::annotations_without_marker(ra_fixture);
- let s =
- StaticIndex::compute(&analysis, &VfsPath::new_virtual_path("/workspace".to_owned()));
+ let s = StaticIndex::compute(&analysis, vendored_libs_config);
let mut range_set: FxHashSet<_> = ranges.iter().map(|it| it.0).collect();
for f in s.files {
for (range, _) in f.tokens {
@@ -288,10 +311,9 @@ mod tests {
}
#[track_caller]
- fn check_definitions(ra_fixture: &str) {
+ fn check_definitions(ra_fixture: &str, vendored_libs_config: VendoredLibrariesConfig<'_>) {
let (analysis, ranges) = fixture::annotations_without_marker(ra_fixture);
- let s =
- StaticIndex::compute(&analysis, &VfsPath::new_virtual_path("/workspace".to_owned()));
+ let s = StaticIndex::compute(&analysis, vendored_libs_config);
let mut range_set: FxHashSet<_> = ranges.iter().map(|it| it.0).collect();
for (_, t) in s.tokens.iter() {
if let Some(t) = t.definition {
@@ -319,6 +341,9 @@ struct Foo;
enum E { X(Foo) }
//^ ^ ^^^
"#,
+ VendoredLibrariesConfig::Included {
+ workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()),
+ },
);
check_definitions(
r#"
@@ -327,6 +352,9 @@ struct Foo;
enum E { X(Foo) }
//^ ^
"#,
+ VendoredLibrariesConfig::Included {
+ workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()),
+ },
);
}
@@ -349,6 +377,9 @@ pub func() {
}
"#,
+ VendoredLibrariesConfig::Included {
+ workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()),
+ },
);
}
@@ -367,10 +398,31 @@ struct ExternalLibrary(i32);
struct VendoredLibrary(i32);
//^^^^^^^^^^^^^^^ ^^^
"#,
+ VendoredLibrariesConfig::Included {
+ workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()),
+ },
);
}
#[test]
+ fn vendored_crate_excluded() {
+ check_all_ranges(
+ r#"
+//- /workspace/main.rs crate:main deps:external,vendored
+struct Main(i32);
+ //^^^^ ^^^
+
+//- /external/lib.rs new_source_root:library crate:[email protected],https://a.b/foo.git library
+struct ExternalLibrary(i32);
+
+//- /workspace/vendored/lib.rs new_source_root:library crate:[email protected],https://a.b/bar.git library
+struct VendoredLibrary(i32);
+"#,
+ VendoredLibrariesConfig::Excluded,
+ )
+ }
+
+ #[test]
fn derives() {
check_all_ranges(
r#"
@@ -384,6 +436,9 @@ pub macro Copy {}
struct Hello(i32);
//^^^^^ ^^^
"#,
+ VendoredLibrariesConfig::Included {
+ workspace_root: &VfsPath::new_virtual_path("/workspace".to_owned()),
+ },
);
}
}