Skip to main content

WorkspaceIndex

Struct WorkspaceIndex 

Source
pub struct WorkspaceIndex { /* private fields */ }
Expand description

Unified multi-crate index for a cargo workspace or multi-index directory.

Implementations§

Source§

impl WorkspaceIndex

Source

pub fn find_def_at_in_reader<'a>( &'a self, reader_idx: usize, file_id: u32, line: u32, col: u32, inner_ref: Option<&'a RefEntry>, ) -> Option<ResolvedDefinition<'a>>

Resolves a definition at (file_id, line, col) in reader_idx. A pre-looked-up inner_ref answers unless a definition at the cursor lies inside its span (an item written inside a macro invocation or a generated call whose reference spans it); without a reference the smallest definition containing the cursor answers.

Source

pub fn definition_inside_reference_at( &self, reader_idx: usize, file_id: u32, line: u32, col: u32, r: &RefEntry, ) -> Option<&DefEntry>

The smallest definition of reader_idx at (file_id, line, col) whose span lies inside the span of the reference r, when r is wide enough to enclose one. Such a definition takes precedence over the reference at the cursor.

Source

pub fn find_definition_at<'a>( &'a self, file: &str, line: u32, col: u32, ) -> Option<ResolvedDefinition<'a>>

Finds a definition at a cursor location, seamlessly resolving cross-crate references.

Source§

impl WorkspaceIndex

Source

pub fn auto_discover() -> Result<Self>

Auto-discovers .ridx indices starting from current directory up to root or target/ridx.

Source

pub fn auto_discover_with( index_dir_env: Option<&str>, cur: &Path, ) -> Result<Self>

Auto-discovers .ridx indices using explicit environment and working directory parameters.

Source§

impl WorkspaceIndex

Source

pub fn resolved_reader_file_ids(&self, file: &str) -> Vec<(usize, u32)>

Returns prioritized (reader_idx, file_id) pairs for file (library targets first).

Source

pub fn target_file_for_reader<'a>( &self, reader_idx: usize, file: &'a str, ) -> Option<Cow<'a, str>>

Resolves file (absolute, relative to the workspace root, or relative to the reader’s source root) to the path string the reader at reader_idx stores for it, or None when this reader does not index the file. Every string returned is accepted by that reader’s exact find_file_id: the input is re-expressed in the reader’s coordinates (relative to the workspace root or to the source root) and compared whole, never by suffix.

Source

pub fn candidate_reader_indices_for_file(&self, file: &str) -> Vec<usize>

Returns reader indices prioritized for querying items in file: matching readers first (ordered with library targets before tests/benchmarks), followed by any remaining workspace readers.

Source§

impl WorkspaceIndex

Source

pub fn reader_index_for_file(&self, file_path: &str) -> Option<usize>

Returns the index in self.readers for the crate that contains or owns the specified file path.

Source

pub fn file_in_bin_only(&self, file_path: &str) -> bool

Whether file_path is compiled into a binary target (src/main.rs, a module of it, a [[bin]] path) and not into the package’s library: its crate:: is the binary, the library is another crate to it.

Source

pub fn target_kind_at(&self, idx: usize) -> Option<TargetKind>

Returns the target kind for the reader at index idx if known.

Source

pub fn reader_indices_for_file(&self, file_path: &str) -> Vec<usize>

Returns the indices in self.readers for all crate units that contain or own the specified file path. Employs longest prefix matching on source_roots so that subpackage targets are returned rather than broader ancestor workspace roots, invariant to reader insertion order.

Source

pub fn extern_crate_names_for_file(&self, file_path: &str) -> Option<Vec<&str>>

The names under which the compilation unit of file_path links other crates (its extern names), when the index records them; None when it does not.

Source

pub fn module_of_file(&self, file_path: &str) -> Option<String>

The crate-relative module file_path is (flags::complete::fish, "" for the crate root), read from the module-level items the index holds for it (functions, types, traits, consts, statics, modules): the shallowest of their parents, so an inline mod tests { … } of the file does not stand for it. None when the file declares no such item.

Source

pub fn module_path_for_file(&self, file_path: &str) -> Option<String>

Returns the canonical module path corresponding to file_path in the owning crate (e.g. serde::de::impls for serde/src/de/impls.rs).

Source§

impl WorkspaceIndex

Source

pub fn direct_blast_radius( &self, def: &ResolvedDefinition<'_>, ) -> DirectBlastRadius

Returns the direct-reference blast radius for def across workspace shards (O(1) via precomputed BlastRadiusIndex, falling back to HashSet scan when the index is unbuilt).

Source§

impl WorkspaceIndex

Source

pub fn collect_reexport_aliases(&self, target_path: &str) -> Vec<String>

Collects any known re-export alias paths for a symbol within the workspace.

Source

pub fn has_unmerged_reexport_references( &self, target_path: &str, found_refs: &[WorkspaceReference<'_>], ) -> bool

Checks whether there are references to a re-export of target_path that are not included in found_refs.

Source§

impl WorkspaceIndex

Source

pub fn find_trait_item_declaration<'a>( &'a self, def: &ResolvedDefinition<'a>, ) -> Option<ResolvedDefinition<'a>>

Resolves the trait declaration for an associated item defined inside a trait impl.

Source

pub fn external_trait_for_def( &self, def: &ResolvedDefinition<'_>, ) -> Option<String>

Source

pub fn external_trait_for_impl_item( &self, loc_refs: &LocationReferences<'_>, ) -> Option<String>

Source§

impl WorkspaceIndex

Source

pub fn is_decl_externally_pub( &self, reader_idx: Option<usize>, file: &str, line_1b: u32, short_name: &str, ) -> bool

Checks the source declaration header to distinguish unrestricted pub from private or pub(...) items.

Source§

impl WorkspaceIndex

Source

pub fn exact_symbols_by_name<'a>( &'a self, ident: &str, ) -> Vec<WorkspaceSymbol<'a>>

O(1) exact bare-identifier lookup across all indexed definitions (including dependencies).

Source

pub fn exact_local_symbols_by_name<'a>( &'a self, ident: &str, ) -> Vec<WorkspaceSymbol<'a>>

O(1) exact bare-identifier lookup across local (non-dependency) workspace definitions.

Source

pub fn exact_symbols_filtered<'a, F>( &'a self, ident: &str, filter: F, ) -> Vec<WorkspaceSymbol<'a>>
where F: FnMut(usize) -> bool,

O(1) exact bare-identifier lookup filtered by shard reader index.

Source§

impl WorkspaceIndex

Source

pub fn has_compiler_impl_defs(&self) -> bool

Returns true if any workspace shard contains compiler-emitted DefKind::Impl definitions.

Source

pub fn find_implementations<'a>( &'a self, def: &ResolvedDefinition<'a>, _file: &Path, ) -> Vec<WorkspaceReference<'a>>

Finds all implementations for a nominal type, trait, or trait associated item.

Source§

impl WorkspaceIndex

Source

pub fn find_references<'a>( &'a self, target_path: &str, ) -> Vec<WorkspaceReference<'a>>

Finds all references to a symbol across every crate in the workspace.

Source

pub fn type_at(&self, file: &str, line: u32, col: u32) -> Option<&str>

Inferred expression type at cursor location.

Source

pub fn type_entry_at( &self, file: &str, line: u32, col: u32, ) -> Option<(&str, Option<&str>)>

Inferred expression type and optional canonical owner path at cursor location.

Source

pub fn types_in_lines( &self, file: &str, start_line: u32, end_line: u32, ) -> Vec<((u32, u32), (u32, u32), &'_ str)>

Every recorded type whose span starts on lines start_line..=end_line (1-based) of file, as ((start_line, start_col), (end_line, end_col), type) with 1-based columns. Every shard compiling the file contributes (a library and its test harness compile different cfg regions); for a span recorded by several, the first shard’s type is kept.

Source

pub fn find_definitions_by_owner<'a>( &'a self, owner: &str, ) -> Vec<ResolvedDefinition<'a>>

Finds all definitions belonging to an owner (canonical type path or module path) across the workspace.

Source

pub fn find_definitions_by_owner_for_file<'a>( &'a self, file: &str, owner: &str, ) -> Vec<ResolvedDefinition<'a>>

Finds all definitions belonging to an owner within the scope accessible from file.

Non-library targets (benchmarks, tests, examples, binaries) that do not contain file are excluded from the search to prevent symbol leakage into standard library and crate queries.

Source

pub fn resolve_deref_chain(&self, source: &str, max_depth: usize) -> Vec<&str>

Resolves the autoderef chain starting from source up to max_depth steps across the workspace. Handles multiple supertraits across workspace readers via breadth-first search.

Source

pub fn resolve_deref_chain_canonical( &self, source: &str, max_depth: usize, ) -> Vec<String>

Self::resolve_deref_chain with every target as a full path. A shard records a target inside its own crate relative to that crate (parser::Parser in winnow); read bare, it can name another crate’s item (the parser crate’s Parser struct). Such targets get the recording crate’s name in front.

Source§

impl WorkspaceIndex

Source

pub fn find_references_for_unit<'a>( &'a self, target_path: &str, target_unit_key: Option<&str>, ) -> Vec<WorkspaceReference<'a>>

Finds all references to a symbol, optionally scoped to a target dependency unit.

Source§

impl WorkspaceIndex

Source

pub fn cargo_main_entrypoint( &self, file_path: &Path, ) -> Option<(String, String)>

Returns (target_kind, target_name) if file_path is a Cargo target root whose entrypoint is fn main.

Source

pub fn check_rename_refusal_for_def( &self, def: &ResolvedDefinition<'_>, precomputed_refs: Option<&[WorkspaceReference<'_>]>, ) -> Result<(), RenameRefusal>

Evaluates all workspace-level semantic rename refusal rules for def.

Source

pub fn check_prepare_rename_at<'a>( &'a self, file: &str, line: u32, col: u32, ) -> Option<Result<ResolvedDefinition<'a>, RenameRefusal>>

Lightweight validation for textDocument/prepareRename without expanding full workspace edits.

Source

pub fn unindexed_symbol_owner_info( &self, reader_idx: Option<usize>, kind: DefKind, path: &str, file: &str, start_line: u32, ) -> (String, String, bool, bool, bool)

Returns (def_crate, owner_short, is_trait_owner, has_self, is_externally_visible) for semantic resolution in unindexed Cargo targets.

Source

pub fn try_find_rename_references_at<'a>( &'a self, file: &str, line: u32, col: u32, ) -> Option<Result<LocationReferences<'a>, RenameRefusal>>

Resolves and expands all workspace rename references at (file, line, col), returning an explicit RenameRefusal if renaming the target symbol is semantically unsafe or disallowed.

Source§

impl WorkspaceIndex

Source

pub fn search_symbols<'a>(&'a self, query: &str) -> Vec<WorkspaceSymbol<'a>>

Substring symbol search across all definitions in the workspace.

Source

pub fn search_local_symbols<'a>( &'a self, query: &str, ) -> Vec<WorkspaceSymbol<'a>>

Substring symbol search across non-dependency definitions in the workspace.

Source

pub fn search_symbols_filtered<'a, F>( &'a self, query: &str, filter: F, ) -> Vec<WorkspaceSymbol<'a>>
where F: FnMut(usize, &IndexReader<Mmap>) -> bool,

Substring symbol search with custom reader predicate.

Source

pub fn find_first_symbol<'a, F>( &'a self, query: &str, predicate: F, ) -> Option<WorkspaceSymbol<'a>>
where F: FnMut(&WorkspaceSymbol<'a>) -> bool,

Finds the first symbol matching query and predicate without eagerly collecting all matches.

Source

pub fn for_each_symbol_ascii<F>( &self, needle_lower: &[u8], preferred_crate: Option<&str>, cb: F, ) -> bool
where F: FnMut(&IndexReader<Mmap>, &DefEntry) -> bool,

Iterates over matching definitions across workspace readers without eager allocation, searching preferred crate first and stopping when cb returns false or scan budget is exhausted.

Source

pub fn for_each_symbol_in_crate<F>( &self, target_crate: &str, needle_lower: &[u8], cb: F, ) -> bool
where F: FnMut(&IndexReader<Mmap>, &DefEntry) -> bool,

Iterates over matching definitions specifically for a single target crate without eager allocation.

Source

pub fn has_crate(&self, target_crate: &str) -> bool

Returns true if any index reader in the workspace has the given crate name.

Source

pub fn find_direct_references_at<'a>( &'a self, file: &str, line: u32, col: u32, ) -> Option<LocationReferences<'a>>

Finds all direct references to the symbol at cursor location without expanding across trait/impl containers.

Source

pub fn resolve_definitions_at<'a>( &'a self, file: &str, positions: &[(u32, u32)], ) -> Vec<Option<ResolvedDefinition<'a>>>

The definitions the symbols at positions in file refer to, as Self::find_direct_references_at resolves them, without collecting their references. The file is located among the index’s units once.

Source

pub fn resolve_definitions_in<'a>( &'a self, pairs: &[(usize, u32)], file: &str, positions: &[(u32, u32)], ) -> Vec<Option<ResolvedDefinition<'a>>>

Self::resolve_definitions_at with the file’s (reader, file id) pairs from Self::resolved_reader_file_ids, for callers that resolve in one file many times.

Source

pub fn find_references_at<'a>( &'a self, file: &str, line: u32, col: u32, ) -> Option<LocationReferences<'a>>

Finds all references to the symbol at cursor location across the workspace, including container-scoped trait/impl links for associated items.

Source

pub fn find_rename_references_at<'a>( &'a self, file: &str, line: u32, col: u32, ) -> Option<LocationReferences<'a>>

Finds all references and sibling trait/impl declarations required to rename the symbol at cursor.

Source

pub fn hover_at<'a>( &'a self, file: &str, line: u32, col: u32, ) -> Option<WorkspaceHover<'a>>

Complete hover information (definition + signature + inferred type) at cursor location.

Source§

impl WorkspaceIndex

Source

pub fn search_workspace_symbols<'a>( &'a self, query: &str, limit: usize, ) -> Vec<WorkspaceSymbol<'a>>

Workspace symbol search. A plain query follows rust-analyzer (see search_workspace_symbols_like_ra); an empty query or a path query (a::b) keeps the local-first substring search.

Source§

impl WorkspaceIndex

Source

pub fn find_definition_by_path<'a>( &'a self, path: &str, ) -> Option<ResolvedDefinition<'a>>

Finds a definition by full or relative canonical path across the workspace.

Source

pub fn crate_source_root(&self, crate_name: &str) -> Option<&Path>

Returns the source root path for a loaded crate, if it is an external dependency.

Source

pub fn crate_name_for_file(&self, file_path: &str) -> Option<&str>

Returns the crate name that contains or owns the specified file path, if known.

Source

pub fn resolve_path_for_crate(&self, crate_name: &str, file: &str) -> PathBuf

Resolves a file path for a given crate. If the path is relative and the crate is an external dependency with a source root, joins the source root with the relative path.

Source

pub fn find_type_param_in_scope<'a>( &'a self, file: &str, name: &str, line: u32, col: u32, ) -> Option<ResolvedDefinition<'a>>

Finds a generic type parameter (DefKind::TyParam) in scope at (file, line, col).

Source

pub fn find_owners_of_definition<'a>( &'a self, def: &ResolvedDefinition<'a>, ) -> Vec<&'a str>

Finds all owners/bounds associated with a definition.

Source§

impl WorkspaceIndex

Source

pub fn note_at( &self, file: &str, line: u32, col: u32, kind: u32, ) -> Option<&str>

The kind note whose span starts at (line, col) of file (an absolute or workspace path).

Source

pub fn note_at_definition( &self, d: &ResolvedDefinition<'_>, kind: u32, ) -> Option<&str>

The kind note at the name of definition d, read from the shard that defines it.

Source§

impl WorkspaceIndex

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Opens a single .ridx file or scans a directory containing .ridx files.

Source

pub fn open_with_cache_dir( path: impl AsRef<Path>, cache_dir: impl AsRef<Path>, ) -> Result<Self>

Opens a single .ridx file or directory using an explicit global cache directory.

Source§

impl WorkspaceIndex

Source

pub fn shard_mtime_for_file(&self, file_path: &str) -> Option<SystemTime>

Returns the file modification timestamp of the index shard containing the given source file.

Source

pub fn units_agree_on_source(&self, file_path: &str) -> bool

Whether every compilation unit recording a source hash for file_path recorded the same one. A failed build of one unit (lib test with an error in mod tests) leaves that unit’s data from the text before while the units that built record the new text: no single text then matches all of the file’s data.

Source

pub fn source_hash_for_file(&self, file_path: &str) -> Option<u64>

Returns the compiled source hash (from rustc compilation provenance) for a file if available.

Source§

impl WorkspaceIndex

Source

pub fn resolve_qualifier<'a>( &'a self, file: &str, qual: &str, ) -> Option<ResolvedDefinition<'a>>

Resolves a qualifier path in the lexical and module scope of file.

Source§

impl WorkspaceIndex

Source

pub fn reload_manifest_if_modified(&mut self) -> Result<bool>

Fast sub-microsecond check: verifies if ridx_manifest.json mtime/size/hash has changed. If manifest is unchanged, returns Ok(false) immediately with zero shard filesystem syscalls. If manifest was updated or switched, triggers full shard reload and returns Ok(true).

Source

pub fn reload_if_modified(&mut self) -> Result<bool>

Checks timestamps of indexed files and reloads any that have changed. Also scans directory for newly generated .ridx files and removes deleted ones. If an active variant manifest exists and was switched, atomically reloads the new variant’s reader set. Returns true if any index was updated, added, removed, or switched.

Source

pub fn reload_if_modified_with_cache_dir( &mut self, cache_dir: impl AsRef<Path>, ) -> Result<bool>

Checks timestamps of indexed files and reloads any that have changed, using an explicit cache directory.

Source

pub fn is_file_reloaded(&self, file_path: &str) -> bool

Checks if a file path belongs to any shard that was newly reloaded or published in the last reload.

Source§

impl WorkspaceIndex

Source

pub fn rename_cache(&self) -> Arc<RenameWorkspaceCache> ⓘ

Returns the shared workspace rename cache for the current generation.

Source§

impl WorkspaceIndex

Source

pub fn has_sysroot(&self) -> bool

Returns true if sysroot shards (core) are attached to the workspace.

Source

pub fn lang_item(&self, kind: LangItemKind) -> Option<(usize, LangItemView)>

Resolves kind across attached shards (core, alloc, workspace), returning (reader_idx, view).

Source

pub fn attach_sysroot_shards_for_key(&mut self, cas_key: &str)

Attaches cached sysroot shards for the given cas_key to the workspace if not already present.

Source

pub fn attach_sysroot_shards_for_key_in( &mut self, base_cache: &Path, cas_key: &str, )

Attaches cached sysroot shards for the given cas_key located in base_cache.

Source

pub fn attach_shard_paths(&mut self, shards: &[PathBuf])

Source§

impl WorkspaceIndex

Source

pub fn is_reader_in_dep_graph( &self, source_readers: &[usize], target_reader_idx: usize, ) -> bool

Returns true if target_reader_idx is directly or transitively (up to 6 hops) referenced in extern_units or dependencies of any reader in source_readers.

Source

pub fn find_enclosing_impl_or_trait_def( &self, reader_idx: usize, file_id: u32, line: u32, ) -> Option<&DefEntry>

Finds the nearest preceding Impl, AssocFn, AssocTy, AssocConst, or Trait definition in (reader_idx, file_id) at or before line via binary search on defs_by_pos.

Source

pub fn find_type_param_in_reader<'a>( &'a self, reader_idx: usize, file_id: u32, name: &str, line: u32, col: u32, ) -> Option<ResolvedDefinition<'a>>

Finds a generic type parameter (DefKind::TyParam) in (reader_idx, file_id) matching name whose enclosing item span contains (line, col) via binary search on defs_by_pos.

Source§

impl WorkspaceIndex

Source

pub fn warm_background_caches(&self)

Spawns a background thread to warm the reachability bitset cache and workspace assoc-item indices.

Source§

impl WorkspaceIndex

Source

pub fn crate_count(&self) -> usize

Number of crates loaded in this workspace index.

Source

pub fn unit_match(&self) -> &UnitMatchIndex

Reference to the internal unit matching index.

Source

pub fn readers(&self) -> &[IndexReader<Mmap>]

Slice of crate index readers.

Source

pub fn paths(&self) -> &[PathBuf]

Paths to the loaded .ridx index files.

Source

pub fn generation_at(&self, idx: usize) -> Option<&str>

Returns the snapshot generation for reader at index i.

Source

pub fn meta_path_at(&self, idx: usize) -> Option<&Path>

Returns the sidecar metadata path for reader at index i.

Source

pub fn meta_mtime_at(&self, idx: usize) -> Option<SystemTime>

Returns the sidecar metadata modification time for reader at index i.

Source

pub fn source_root_at(&self, idx: usize) -> Option<&Path>

Returns the source root path for reader at index i, if known.

Source

pub fn stats(&self) -> WorkspaceStats

Aggregated statistics across all crates in the workspace.

Source

pub fn active_variant_id(&self) -> Option<&str>

Currently active build variant ID, if loaded from a variant manifest.

Source

pub fn sysroot_cas_key(&self) -> Option<&str>

Returns the sysroot CAS key from the active variant manifest, if present.

Source

pub fn workspace_root(&self) -> Option<&Path>

Root directory of the workspace if known.

Source

pub fn set_workspace_root(&mut self, root: Option<PathBuf>)

Sets or overrides the workspace root directory.

Source

pub fn is_external_target( &self, target_file: &str, target_path: &Path, target_unit_key: Option<&str>, ) -> bool

Checks whether a target file, path, or unit key belongs to an external dependency or outside the workspace.

Source

pub fn is_external_path(&self, path: &Path) -> bool

Checks whether an arbitrary path belongs to an external dependency or outside the workspace.

Source

pub fn is_reader_dependency(&self, idx: usize) -> bool

Returns whether the reader at index idx is marked as a dependency.

Source

pub fn is_reader_external(&self, idx: usize) -> bool

Checks whether the reader at index idx belongs to an external dependency or outside the workspace.

Source

pub fn are_sibling_workspace_units(&self, idx1: usize, idx2: usize) -> bool

Checks whether two readers represent sibling units of the same workspace package (e.g. lib and lib test shards of the same package).

Sibling units share the same non-external source root and crate name, but may have distinct unit keys (e.g. unit_lib vs unit_test).

Source

pub fn instance_id(&self) -> u64

Returns the unique instance ID for this workspace.

Source

pub fn generation(&self) -> u64

Returns the current index generation counter. Incremented on each index reload or modification.

Source

pub fn bump_generation(&mut self) -> u64

Explicitly bumps the index generation counter.

Trait Implementations§

Source§

impl Debug for WorkspaceIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.