Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir/src/symbols.rs145
-rw-r--r--crates/ide-db/src/symbol_index.rs183
-rw-r--r--crates/ide-db/src/test_data/test_doc_alias.txt112
-rw-r--r--crates/ide-db/src/test_data/test_symbol_index_collection.txt422
-rw-r--r--crates/ide-db/src/test_data/test_symbols_exclude_imports.txt12
-rw-r--r--crates/ide-db/src/test_data/test_symbols_with_imports.txt24
-rw-r--r--crates/ide/src/navigation_target.rs4
-rw-r--r--crates/mbe/src/expander/matcher.rs5
-rw-r--r--crates/rust-analyzer/tests/slow-tests/main.rs44
-rw-r--r--crates/syntax/src/ptr.rs2
10 files changed, 505 insertions, 448 deletions
diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs
index 544c759ed3..f9002f31fd 100644
--- a/crates/hir/src/symbols.rs
+++ b/crates/hir/src/symbols.rs
@@ -21,12 +21,9 @@ use hir_ty::{
};
use intern::Symbol;
use rustc_hash::FxHashMap;
-use syntax::{
- AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, ToSmolStr,
- ast::{HasModuleItem, HasName},
-};
+use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName};
-use crate::{Crate, HasCrate, Module, ModuleDef, Semantics};
+use crate::{HasCrate, Module, ModuleDef, Semantics};
/// The actual data that is stored in the index. It should be as compact as
/// possible.
@@ -44,14 +41,14 @@ pub struct FileSymbol<'db> {
_marker: PhantomData<&'db ()>,
}
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct DeclarationLocation {
/// The file id for both the `ptr` and `name_ptr`.
pub hir_file_id: HirFileId,
/// This points to the whole syntax node of the declaration.
pub ptr: SyntaxNodePtr,
/// This points to the [`syntax::ast::Name`] identifier of the declaration.
- pub name_ptr: AstPtr<Either<syntax::ast::Name, syntax::ast::NameRef>>,
+ pub name_ptr: Option<AstPtr<Either<syntax::ast::Name, syntax::ast::NameRef>>>,
}
impl DeclarationLocation {
@@ -61,70 +58,6 @@ impl DeclarationLocation {
}
}
-impl<'db> FileSymbol<'db> {
- /// Create a `FileSymbol` representing a crate's root module.
- /// This is used for crate search queries like `::` or `::foo`.
- pub fn for_crate_root(db: &'db dyn HirDatabase, krate: Crate) -> Option<FileSymbol<'db>> {
- let display_name = krate.display_name(db)?;
- let crate_name = display_name.crate_name();
- let root_module = krate.root_module(db);
- let def_map = crate_def_map(db, krate.into());
- let module_data = &def_map[root_module.into()];
-
- // Get the definition source (the source file for crate roots)
- let definition = module_data.origin.definition_source(db);
- let hir_file_id = definition.file_id;
-
- // For a crate root, the "declaration" is the source file itself
- // We use the entire file's syntax node as the location
- let syntax_node = definition.value.node();
- let ptr = SyntaxNodePtr::new(&syntax_node);
-
- // For the name, we need to create a synthetic name pointer.
- // We'll use the first token of the file as a placeholder since crate roots
- // don't have an explicit name in the source.
- // We create a name_ptr pointing to the start of the file.
- let name_ptr = match &definition.value {
- crate::ModuleSource::SourceFile(sf) => {
- // Try to find the first item with a name as a reasonable location for focus
- // This is a bit of a hack but works for navigation purposes
- let first_item: Option<syntax::ast::Item> = sf.items().next();
- if let Some(item) = first_item {
- if let Some(name) = item.syntax().children().find_map(syntax::ast::Name::cast) {
- AstPtr::new(&name).wrap_left()
- } else {
- // No name found, try to use a NameRef instead
- if let Some(name_ref) =
- item.syntax().descendants().find_map(syntax::ast::NameRef::cast)
- {
- AstPtr::new(&name_ref).wrap_right()
- } else {
- return None;
- }
- }
- } else {
- return None;
- }
- }
- _ => return None,
- };
-
- let loc = DeclarationLocation { hir_file_id, ptr, name_ptr };
-
- Some(FileSymbol {
- name: Symbol::intern(crate_name.as_str()),
- def: ModuleDef::Module(root_module),
- loc,
- container_name: None,
- is_alias: false,
- is_assoc: false,
- is_import: false,
- do_not_complete: Complete::Yes,
- _marker: PhantomData,
- })
- }
-}
-
/// Represents an outstanding module that the symbol collector must collect symbols from.
#[derive(Debug)]
struct SymbolCollectorWork {
@@ -167,6 +100,11 @@ impl<'a> SymbolCollector<'a> {
let _p = tracing::info_span!("SymbolCollector::collect", ?module).entered();
tracing::info!(?module, "SymbolCollector::collect");
+ // If this is a crate root module, add a symbol for the crate itself
+ if module.is_crate_root(self.db) {
+ self.push_crate_root(module);
+ }
+
// The initial work is the root module we're collecting, additional work will
// be populated as we traverse the module's definitions.
self.work.push(SymbolCollectorWork { module_id: module.into(), parent: None });
@@ -176,6 +114,51 @@ impl<'a> SymbolCollector<'a> {
}
}
+ /// Push a symbol for a crate's root module.
+ /// This allows crate roots to appear in the symbol index for queries like `::` or `::foo`.
+ fn push_crate_root(&mut self, module: Module) {
+ let krate = module.krate(self.db);
+ let Some(display_name) = krate.display_name(self.db) else { return };
+ let crate_name = display_name.crate_name();
+ let canonical_name = display_name.canonical_name();
+
+ let def_map = crate_def_map(self.db, krate.into());
+ let module_data = &def_map[def_map.crate_root(self.db)];
+
+ let definition = module_data.origin.definition_source(self.db);
+ let hir_file_id = definition.file_id;
+ let syntax_node = definition.value.node();
+ let ptr = SyntaxNodePtr::new(&syntax_node);
+
+ let loc = DeclarationLocation { hir_file_id, ptr, name_ptr: None };
+
+ self.symbols.insert(FileSymbol {
+ name: crate_name.symbol().clone(),
+ def: ModuleDef::Module(module),
+ loc,
+ container_name: None,
+ is_alias: false,
+ is_assoc: false,
+ is_import: false,
+ do_not_complete: Complete::Yes,
+ _marker: PhantomData,
+ });
+
+ if canonical_name != crate_name.symbol() {
+ self.symbols.insert(FileSymbol {
+ name: canonical_name.clone(),
+ def: ModuleDef::Module(module),
+ loc,
+ container_name: None,
+ is_alias: false,
+ is_assoc: false,
+ is_import: false,
+ do_not_complete: Complete::Yes,
+ _marker: PhantomData,
+ });
+ }
+ }
+
pub fn finish(self) -> Box<[FileSymbol<'a>]> {
self.symbols.into_iter().collect()
}
@@ -277,7 +260,7 @@ impl<'a> SymbolCollector<'a> {
let dec_loc = DeclarationLocation {
hir_file_id: source.file_id,
ptr: SyntaxNodePtr::new(use_tree_src.syntax()),
- name_ptr: AstPtr::new(&name_syntax),
+ name_ptr: Some(AstPtr::new(&name_syntax)),
};
this.symbols.insert(FileSymbol {
name: name.symbol().clone(),
@@ -312,7 +295,7 @@ impl<'a> SymbolCollector<'a> {
let dec_loc = DeclarationLocation {
hir_file_id: source.file_id,
ptr: SyntaxNodePtr::new(source.value.syntax()),
- name_ptr: AstPtr::new(&name_syntax),
+ name_ptr: Some(AstPtr::new(&name_syntax)),
};
this.symbols.insert(FileSymbol {
name: name.symbol().clone(),
@@ -477,10 +460,10 @@ impl<'a> SymbolCollector<'a> {
let source = loc.source(self.db);
let Some(name_node) = source.value.name() else { return Complete::Yes };
let def = ModuleDef::from(id.into());
- let dec_loc = DeclarationLocation {
+ let loc = DeclarationLocation {
hir_file_id: source.file_id,
ptr: SyntaxNodePtr::new(source.value.syntax()),
- name_ptr: AstPtr::new(&name_node).wrap_left(),
+ name_ptr: Some(AstPtr::new(&name_node).wrap_left()),
};
let mut do_not_complete = Complete::Yes;
@@ -495,7 +478,7 @@ impl<'a> SymbolCollector<'a> {
self.symbols.insert(FileSymbol {
name: alias.clone(),
def,
- loc: dec_loc.clone(),
+ loc,
container_name: self.current_container_name.clone(),
is_alias: true,
is_assoc,
@@ -510,7 +493,7 @@ impl<'a> SymbolCollector<'a> {
name: name.symbol().clone(),
def,
container_name: self.current_container_name.clone(),
- loc: dec_loc,
+ loc,
is_alias: false,
is_assoc,
is_import: false,
@@ -527,10 +510,10 @@ impl<'a> SymbolCollector<'a> {
let Some(declaration) = module_data.origin.declaration() else { return };
let module = declaration.to_node(self.db);
let Some(name_node) = module.name() else { return };
- let dec_loc = DeclarationLocation {
+ let loc = DeclarationLocation {
hir_file_id: declaration.file_id,
ptr: SyntaxNodePtr::new(module.syntax()),
- name_ptr: AstPtr::new(&name_node).wrap_left(),
+ name_ptr: Some(AstPtr::new(&name_node).wrap_left()),
};
let def = ModuleDef::Module(module_id.into());
@@ -543,7 +526,7 @@ impl<'a> SymbolCollector<'a> {
self.symbols.insert(FileSymbol {
name: alias.clone(),
def,
- loc: dec_loc.clone(),
+ loc,
container_name: self.current_container_name.clone(),
is_alias: true,
is_assoc: false,
@@ -558,7 +541,7 @@ impl<'a> SymbolCollector<'a> {
name: name.symbol().clone(),
def: ModuleDef::Module(module_id.into()),
container_name: self.current_container_name.clone(),
- loc: dec_loc,
+ loc,
is_alias: false,
is_assoc: false,
is_import: false,
diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs
index ca0d5ec1e5..05c3f360fa 100644
--- a/crates/ide-db/src/symbol_index.rs
+++ b/crates/ide-db/src/symbol_index.rs
@@ -129,58 +129,19 @@ impl Query {
/// - `anchor_to_crate`: Whether the first segment must be a crate name
fn parse_path_query(query: &str) -> (Vec<String>, String, bool) {
// Check for leading :: (absolute path / crate search)
- let anchor_to_crate = query.starts_with("::");
- let query = if anchor_to_crate { &query[2..] } else { query };
-
- // Handle sole "::" - return all crates
- if query.is_empty() && anchor_to_crate {
- return (vec![], String::new(), true);
- }
-
- // Check for trailing :: (module browsing - returns all items in module)
- let return_all_in_module = query.ends_with("::");
- let query = if return_all_in_module { query.trim_end_matches("::") } else { query };
-
- if !query.contains("::") {
- // No path separator - single segment
- if anchor_to_crate && !return_all_in_module {
- // "::foo" - fuzzy search crate names only
- return (vec![], query.to_string(), true);
- }
- if return_all_in_module {
- // "foo::" - browse all items in module "foo"
- // path_filter = ["foo"], query = "", anchor_to_crate = false/true
- return (vec![query.to_string()], String::new(), anchor_to_crate);
- }
- // Plain "foo" - normal fuzzy search
- return (vec![], query.to_string(), false);
- }
-
- // Filter out empty segments (e.g., "foo::::bar" -> "foo::bar")
- let segments: Vec<&str> = query.split("::").filter(|s| !s.is_empty()).collect();
-
- if segments.is_empty() {
- return (vec![], String::new(), anchor_to_crate);
- }
+ let (query, anchor_to_crate) = match query.strip_prefix("::") {
+ Some(q) => (q, true),
+ None => (query, false),
+ };
- let path: Vec<String> =
- segments[..segments.len() - 1].iter().map(|s| s.to_string()).collect();
- let item = if return_all_in_module {
- // All segments go to path, item is empty
- let mut path = path;
- path.push(segments.last().unwrap().to_string());
- return (path, String::new(), anchor_to_crate);
- } else {
- segments.last().unwrap_or(&"").to_string()
+ let Some((prefix, query)) = query.rsplit_once("::") else {
+ return (vec![], query.to_owned(), anchor_to_crate);
};
- (path, item, anchor_to_crate)
- }
+ let prefix: Vec<_> =
+ prefix.split("::").filter(|s| !s.is_empty()).map(ToOwned::to_owned).collect();
- /// Returns true if this query should return all items in a module
- /// (i.e., the original query ended with `::`)
- fn is_module_browsing(&self) -> bool {
- self.query.is_empty() && !self.path_filter.is_empty()
+ (prefix, query.to_owned(), anchor_to_crate)
}
/// Returns true if this query is searching for crates
@@ -245,11 +206,14 @@ pub fn crate_symbols(db: &dyn HirDatabase, krate: Crate) -> Box<[&SymbolIndex<'_
// That is, `#` switches from "types" to all symbols, `*` switches from the current
// workspace to dependencies.
//
-// Note that filtering does not currently work in VSCode due to the editor never
-// sending the special symbols to the language server. Instead, you can configure
-// the filtering via the `rust-analyzer.workspace.symbol.search.scope` and
-// `rust-analyzer.workspace.symbol.search.kind` settings. Symbols prefixed
-// with `__` are hidden from the search results unless configured otherwise.
+// This also supports general Rust path syntax with the usual rules.
+//
+// Note that paths do not currently work in VSCode due to the editor never
+// sending the special symbols to the language server. Some other editors might not support the # or
+// * search either, instead, you can configure the filtering via the
+// `rust-analyzer.workspace.symbol.search.scope` and `rust-analyzer.workspace.symbol.search.kind`
+// settings. Symbols prefixed with `__` are hidden from the search results unless configured
+// otherwise.
//
// | Editor | Shortcut |
// |---------|-----------|
@@ -257,12 +221,11 @@ pub fn crate_symbols(db: &dyn HirDatabase, krate: Crate) -> Box<[&SymbolIndex<'_
pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol<'_>> {
let _p = tracing::info_span!("world_symbols", query = ?query.query).entered();
- // Handle special case: "::" alone or "::foo" for crate search
if query.is_crate_search() {
return search_crates(db, &query);
}
- // If we have a path filter, resolve it to target modules first
+ // If we have a path filter, resolve it to target modules
let indices: Vec<_> = if !query.path_filter.is_empty() {
let target_modules = resolve_path_to_modules(
db,
@@ -272,13 +235,11 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol<'_>> {
);
if target_modules.is_empty() {
- return vec![]; // Path doesn't resolve to any module
+ return vec![];
}
- // Get symbol indices only for the resolved modules
target_modules.iter().map(|&module| SymbolIndex::module_symbols(db, module)).collect()
} else if query.libs {
- // Original behavior for non-path queries searching libs
LibraryRoots::get(db)
.roots(db)
.par_iter()
@@ -289,7 +250,6 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol<'_>> {
.map(|&root| SymbolIndex::library_symbols(db, root))
.collect()
} else {
- // Original behavior for non-path queries searching local crates
let mut crates = Vec::new();
for &root in LocalRoots::get(db).roots(db).iter() {
@@ -303,23 +263,11 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol<'_>> {
let mut res = vec![];
- // For module browsing (empty query, non-empty path_filter), return all symbols
- if query.is_module_browsing() {
- for index in &indices {
- for symbol in index.symbols.iter() {
- // Apply existing filters (only_types, assoc_mode, exclude_imports, etc.)
- if query.matches_symbol_filters(symbol) {
- res.push(symbol.clone());
- }
- }
- }
- } else {
- // Normal search: use FST to match item name
- query.search::<()>(&indices, |f| {
- res.push(f.clone());
- ControlFlow::Continue(())
- });
- }
+ // Normal search: use FST to match item name
+ query.search::<()>(&indices, |f| {
+ res.push(f.clone());
+ ControlFlow::Continue(())
+ });
res
}
@@ -341,9 +289,15 @@ fn search_crates<'db>(db: &'db RootDatabase, query: &Query) -> Vec<FileSymbol<'d
};
if matches {
- // Create a FileSymbol for the crate's root module
- if let Some(symbol) = hir::symbols::FileSymbol::for_crate_root(db, krate) {
- res.push(symbol);
+ // Get the crate root module's symbol index and find the root module symbol
+ let root_module = krate.root_module(db);
+ let index = SymbolIndex::module_symbols(db, root_module);
+ // Find the module symbol itself (representing the crate)
+ for symbol in index.symbols.iter() {
+ if matches!(symbol.def, hir::ModuleDef::Module(m) if m == root_module) {
+ res.push(symbol.clone());
+ break;
+ }
}
}
}
@@ -398,10 +352,10 @@ fn resolve_path_to_modules(
for &krate in db.source_root_crates(root).iter() {
let root_module = Crate::from(krate).root_module(db);
for child in root_module.children(db) {
- if let Some(name) = child.name(db) {
- if names_match(name.as_str(), first_segment) {
- candidate_modules.push(child);
- }
+ if let Some(name) = child.name(db)
+ && names_match(name.as_str(), first_segment)
+ {
+ candidate_modules.push(child);
}
}
}
@@ -684,41 +638,6 @@ impl Query {
(true, AssocSearchMode::Exclude) | (false, AssocSearchMode::AssocItemsOnly)
)
}
-
- /// Check if a symbol passes all filters except name matching.
- /// Used for module browsing where we want all items in a module.
- fn matches_symbol_filters(&self, symbol: &FileSymbol<'_>) -> bool {
- // Check only_types filter
- if self.only_types
- && !matches!(
- symbol.def,
- hir::ModuleDef::Adt(..)
- | hir::ModuleDef::TypeAlias(..)
- | hir::ModuleDef::BuiltinType(..)
- | hir::ModuleDef::Trait(..)
- )
- {
- return false;
- }
-
- // Check assoc_mode filter
- if !self.matches_assoc_mode(symbol.is_assoc) {
- return false;
- }
-
- // Check exclude_imports filter
- if self.exclude_imports && symbol.is_import {
- return false;
- }
-
- // Check underscore prefix
- let ignore_underscore_prefixed = !self.query.starts_with("__");
- if ignore_underscore_prefixed && symbol.name.as_str().starts_with("__") {
- return false;
- }
-
- true
- }
}
#[cfg(test)]
@@ -940,34 +859,6 @@ pub struct Foo;
}
#[test]
- fn test_query_modes() {
- // Test is_module_browsing
- let query = Query::new("foo::".to_owned());
- assert!(query.is_module_browsing());
- assert!(!query.is_crate_search());
-
- // Test is_crate_search with sole ::
- let query = Query::new("::".to_owned());
- assert!(!query.is_module_browsing());
- assert!(query.is_crate_search());
-
- // Test is_crate_search with ::foo
- let query = Query::new("::foo".to_owned());
- assert!(!query.is_module_browsing());
- assert!(query.is_crate_search());
-
- // Normal query should be neither
- let query = Query::new("foo".to_owned());
- assert!(!query.is_module_browsing());
- assert!(!query.is_crate_search());
-
- // Path query should be neither
- let query = Query::new("foo::bar".to_owned());
- assert!(!query.is_module_browsing());
- assert!(!query.is_crate_search());
- }
-
- #[test]
fn test_path_search() {
let (mut db, _) = RootDatabase::with_many_files(
r#"
diff --git a/crates/ide-db/src/test_data/test_doc_alias.txt b/crates/ide-db/src/test_data/test_doc_alias.txt
index 5783d97564..71680699b7 100644
--- a/crates/ide-db/src/test_data/test_doc_alias.txt
+++ b/crates/ide-db/src/test_data/test_doc_alias.txt
@@ -27,11 +27,13 @@
kind: STRUCT,
range: 83..119,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 109..118,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 109..118,
+ },
+ ),
),
},
container_name: None,
@@ -62,11 +64,13 @@
kind: STRUCT,
range: 0..81,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 74..80,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 74..80,
+ },
+ ),
),
},
container_name: None,
@@ -97,11 +101,13 @@
kind: STRUCT,
range: 0..81,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 74..80,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 74..80,
+ },
+ ),
),
},
container_name: None,
@@ -132,11 +138,13 @@
kind: STRUCT,
range: 0..81,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 74..80,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 74..80,
+ },
+ ),
),
},
container_name: None,
@@ -147,6 +155,34 @@
_marker: PhantomData<&()>,
},
FileSymbol {
+ name: "ra_test_fixture",
+ def: Module(
+ Module {
+ id: ModuleIdLt {
+ [salsa id]: Id(3800),
+ },
+ },
+ ),
+ loc: DeclarationLocation {
+ hir_file_id: FileId(
+ EditionedFileId(
+ Id(3000),
+ ),
+ ),
+ ptr: SyntaxNodePtr {
+ kind: SOURCE_FILE,
+ range: 0..128,
+ },
+ name_ptr: None,
+ },
+ container_name: None,
+ is_alias: false,
+ is_assoc: false,
+ is_import: false,
+ do_not_complete: Yes,
+ _marker: PhantomData<&()>,
+ },
+ FileSymbol {
name: "s1",
def: Adt(
Struct(
@@ -167,11 +203,13 @@
kind: STRUCT,
range: 0..81,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 74..80,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 74..80,
+ },
+ ),
),
},
container_name: None,
@@ -202,11 +240,13 @@
kind: STRUCT,
range: 83..119,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 109..118,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 109..118,
+ },
+ ),
),
},
container_name: None,
@@ -237,11 +277,13 @@
kind: STRUCT,
range: 0..81,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 74..80,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 74..80,
+ },
+ ),
),
},
container_name: None,
diff --git a/crates/ide-db/src/test_data/test_symbol_index_collection.txt b/crates/ide-db/src/test_data/test_symbol_index_collection.txt
index 7692a7d61a..2d62a56fe2 100644
--- a/crates/ide-db/src/test_data/test_symbol_index_collection.txt
+++ b/crates/ide-db/src/test_data/test_symbol_index_collection.txt
@@ -25,11 +25,13 @@
kind: VARIANT,
range: 201..202,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 201..202,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 201..202,
+ },
+ ),
),
},
container_name: Some(
@@ -60,11 +62,13 @@
kind: TYPE_ALIAS,
range: 470..490,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 475..480,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 475..480,
+ },
+ ),
),
},
container_name: None,
@@ -93,11 +97,13 @@
kind: VARIANT,
range: 204..205,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 204..205,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 204..205,
+ },
+ ),
),
},
container_name: Some(
@@ -128,11 +134,13 @@
kind: CONST,
range: 413..434,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 419..424,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 419..424,
+ },
+ ),
),
},
container_name: None,
@@ -161,11 +169,13 @@
kind: CONST,
range: 593..665,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 599..615,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 599..615,
+ },
+ ),
),
},
container_name: None,
@@ -196,11 +206,13 @@
kind: ENUM,
range: 185..207,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 190..194,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 190..194,
+ },
+ ),
),
},
container_name: None,
@@ -231,11 +243,13 @@
kind: USE_TREE,
range: 727..749,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 736..749,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 736..749,
+ },
+ ),
),
},
container_name: None,
@@ -266,11 +280,13 @@
kind: MACRO_DEF,
range: 153..168,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 159..164,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 159..164,
+ },
+ ),
),
},
container_name: None,
@@ -299,11 +315,13 @@
kind: STATIC,
range: 435..469,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 442..448,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 442..448,
+ },
+ ),
),
},
container_name: None,
@@ -334,11 +352,13 @@
kind: STRUCT,
range: 170..184,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 177..183,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 177..183,
+ },
+ ),
),
},
container_name: None,
@@ -369,11 +389,13 @@
kind: STRUCT,
range: 0..22,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 6..21,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 6..21,
+ },
+ ),
),
},
container_name: None,
@@ -404,11 +426,13 @@
kind: STRUCT,
range: 391..409,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 398..408,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 398..408,
+ },
+ ),
),
},
container_name: Some(
@@ -441,11 +465,13 @@
kind: STRUCT,
range: 628..654,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 635..653,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 635..653,
+ },
+ ),
),
},
container_name: Some(
@@ -478,11 +504,13 @@
kind: STRUCT,
range: 552..580,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 559..579,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 559..579,
+ },
+ ),
),
},
container_name: None,
@@ -513,11 +541,13 @@
kind: STRUCT,
range: 261..279,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 268..275,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 268..275,
+ },
+ ),
),
},
container_name: None,
@@ -546,11 +576,13 @@
kind: TRAIT,
range: 334..373,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 340..345,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 340..345,
+ },
+ ),
),
},
container_name: None,
@@ -581,11 +613,13 @@
kind: USE_TREE,
range: 755..769,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 764..769,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 764..769,
+ },
+ ),
),
},
container_name: None,
@@ -616,11 +650,13 @@
kind: UNION,
range: 208..222,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 214..219,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 214..219,
+ },
+ ),
),
},
container_name: None,
@@ -649,11 +685,13 @@
kind: MODULE,
range: 492..530,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 496..501,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 496..501,
+ },
+ ),
),
},
container_name: None,
@@ -682,11 +720,13 @@
kind: MODULE,
range: 667..677,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 671..676,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 671..676,
+ },
+ ),
),
},
container_name: None,
@@ -717,11 +757,13 @@
kind: MACRO_RULES,
range: 51..131,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 64..77,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 64..77,
+ },
+ ),
),
},
container_name: None,
@@ -750,11 +792,13 @@
kind: FN,
range: 307..330,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 310..325,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 310..325,
+ },
+ ),
),
},
container_name: Some(
@@ -785,11 +829,13 @@
kind: FN,
range: 242..257,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 245..252,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 245..252,
+ },
+ ),
),
},
container_name: Some(
@@ -822,11 +868,13 @@
kind: MACRO_RULES,
range: 1..48,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 14..31,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 14..31,
+ },
+ ),
),
},
container_name: None,
@@ -855,12 +903,42 @@
kind: FN,
range: 375..411,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 378..382,
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 378..382,
+ },
+ ),
+ ),
+ },
+ container_name: None,
+ is_alias: false,
+ is_assoc: false,
+ is_import: false,
+ do_not_complete: Yes,
+ _marker: PhantomData<&()>,
+ },
+ FileSymbol {
+ name: "ra_test_fixture",
+ def: Module(
+ Module {
+ id: ModuleIdLt {
+ [salsa id]: Id(3800),
},
+ },
+ ),
+ loc: DeclarationLocation {
+ hir_file_id: FileId(
+ EditionedFileId(
+ Id(3000),
+ ),
),
+ ptr: SyntaxNodePtr {
+ kind: SOURCE_FILE,
+ range: 0..793,
+ },
+ name_ptr: None,
},
container_name: None,
is_alias: false,
@@ -890,11 +968,13 @@
kind: USE_TREE,
range: 684..721,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 701..721,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 701..721,
+ },
+ ),
),
},
container_name: None,
@@ -923,11 +1003,13 @@
kind: FN,
range: 352..371,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 355..363,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 355..363,
+ },
+ ),
),
},
container_name: Some(
@@ -969,11 +1051,13 @@
kind: STRUCT,
range: 508..528,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 515..527,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 515..527,
+ },
+ ),
),
},
container_name: None,
@@ -1011,11 +1095,13 @@
kind: USE_TREE,
range: 141..173,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 157..173,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 157..173,
+ },
+ ),
),
},
container_name: None,
@@ -1046,11 +1132,13 @@
kind: USE_TREE,
range: 141..173,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 157..173,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 157..173,
+ },
+ ),
),
},
container_name: None,
@@ -1081,11 +1169,13 @@
kind: STRUCT,
range: 0..20,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 7..19,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 7..19,
+ },
+ ),
),
},
container_name: None,
@@ -1116,11 +1206,13 @@
kind: USE_TREE,
range: 35..69,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 51..69,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 51..69,
+ },
+ ),
),
},
container_name: None,
@@ -1151,11 +1243,13 @@
kind: USE_TREE,
range: 85..125,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 115..125,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 115..125,
+ },
+ ),
),
},
container_name: None,
diff --git a/crates/ide-db/src/test_data/test_symbols_exclude_imports.txt b/crates/ide-db/src/test_data/test_symbols_exclude_imports.txt
index 6f5f8f889c..87f0c7d9a8 100644
--- a/crates/ide-db/src/test_data/test_symbols_exclude_imports.txt
+++ b/crates/ide-db/src/test_data/test_symbols_exclude_imports.txt
@@ -20,11 +20,13 @@
kind: STRUCT,
range: 0..15,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 11..14,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 11..14,
+ },
+ ),
),
},
container_name: None,
diff --git a/crates/ide-db/src/test_data/test_symbols_with_imports.txt b/crates/ide-db/src/test_data/test_symbols_with_imports.txt
index 5d3fe4d265..e96aa889ba 100644
--- a/crates/ide-db/src/test_data/test_symbols_with_imports.txt
+++ b/crates/ide-db/src/test_data/test_symbols_with_imports.txt
@@ -20,11 +20,13 @@
kind: STRUCT,
range: 0..15,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME,
- range: 11..14,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME,
+ range: 11..14,
+ },
+ ),
),
},
container_name: None,
@@ -55,11 +57,13 @@
kind: USE_TREE,
range: 17..25,
},
- name_ptr: AstPtr(
- SyntaxNodePtr {
- kind: NAME_REF,
- range: 22..25,
- },
+ name_ptr: Some(
+ AstPtr(
+ SyntaxNodePtr {
+ kind: NAME_REF,
+ range: 22..25,
+ },
+ ),
),
},
container_name: None,
diff --git a/crates/ide/src/navigation_target.rs b/crates/ide/src/navigation_target.rs
index a271cac6fc..047df309ec 100644
--- a/crates/ide/src/navigation_target.rs
+++ b/crates/ide/src/navigation_target.rs
@@ -19,7 +19,7 @@ use ide_db::{
};
use stdx::never;
use syntax::{
- AstNode, SyntaxNode, TextRange,
+ AstNode, AstPtr, SyntaxNode, TextRange,
ast::{self, HasName},
};
@@ -253,7 +253,7 @@ impl<'db> TryToNav for FileSymbol<'db> {
db,
self.loc.hir_file_id,
self.loc.ptr.text_range(),
- Some(self.loc.name_ptr.text_range()),
+ self.loc.name_ptr.map(AstPtr::text_range),
)
.map(|(FileRange { file_id, range: full_range }, focus_range)| {
NavigationTarget {
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs
index 8f6627a60f..fe01fb1f10 100644
--- a/crates/mbe/src/expander/matcher.rs
+++ b/crates/mbe/src/expander/matcher.rs
@@ -414,8 +414,9 @@ fn match_loop_inner<'t>(
}
// Check if we need a separator.
- if item.sep.is_some() && !item.sep_matched {
- let sep = item.sep.as_ref().unwrap();
+ if let Some(sep) = &item.sep
+ && !item.sep_matched
+ {
let mut fork = src.clone();
if expect_separator(&mut fork, sep) {
// HACK: here we use `meta_result` to pass `TtIter` back to caller because
diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs
index eb1b8c5dd0..9f3c6742d6 100644
--- a/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -1447,7 +1447,27 @@ foo = { path = "../foo" }
.server()
.wait_until_workspace_is_loaded();
- server.request::<WorkspaceSymbolRequest>(Default::default(), json!([]));
+ server.request::<WorkspaceSymbolRequest>(
+ Default::default(),
+ json!([
+ {
+ "name": "bar",
+ "kind": 2,
+ "location": {
+ "uri": "file:///[..]bar/src/lib.rs",
+ "range": {
+ "start": {
+ "line": 0,
+ "character": 0
+ },
+ "end": {
+ "line": 0,
+ "character": 0
+ }
+ }
+ }
+ }]),
+ );
let server = Project::with_fixture(
r#"
@@ -1486,7 +1506,27 @@ version = "0.0.0"
.server()
.wait_until_workspace_is_loaded();
- server.request::<WorkspaceSymbolRequest>(Default::default(), json!([]));
+ server.request::<WorkspaceSymbolRequest>(
+ Default::default(),
+ json!([
+ {
+ "name": "baz",
+ "kind": 2,
+ "location": {
+ "uri": "file:///[..]baz/src/lib.rs",
+ "range": {
+ "start": {
+ "line": 0,
+ "character": 0
+ },
+ "end": {
+ "line": 0,
+ "character": 0
+ }
+ }
+ }
+ }]),
+ );
}
#[test]
diff --git a/crates/syntax/src/ptr.rs b/crates/syntax/src/ptr.rs
index 34c07598d2..c4979b8e3a 100644
--- a/crates/syntax/src/ptr.rs
+++ b/crates/syntax/src/ptr.rs
@@ -68,7 +68,7 @@ impl<N: AstNode> AstPtr<N> {
self.raw
}
- pub fn text_range(&self) -> TextRange {
+ pub fn text_range(self) -> TextRange {
self.raw.text_range()
}