pub struct WorkspaceIndex { /* private fields */ }Expand description
Workspace indexing and refactoring orchestration. Thread-safe workspace index
Implementations§
Source§impl WorkspaceIndex
impl WorkspaceIndex
Sourcepub fn new() -> WorkspaceIndex
pub fn new() -> WorkspaceIndex
Sourcepub fn index_file(&self, uri: Url, text: String) -> Result<(), String>
pub fn index_file(&self, uri: Url, text: String) -> Result<(), String>
Index a file from its URI and text content
§Arguments
uri- File URI identifying the documenttext- Full Perl source text for indexing
§Returns
Ok(()) when indexing succeeds, or an error message otherwise.
§Errors
Returns an error if parsing fails or the document store cannot be updated.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
use url::Url;
let index = WorkspaceIndex::new();
let uri = Url::parse("file:///example.pl")?;
index.index_file(uri, "sub hello { return 1; }".to_string())?;Returns: Ok(()) when indexing succeeds, otherwise an error string.
Sourcepub fn remove_file(&self, uri: &str)
pub fn remove_file(&self, uri: &str)
Sourcepub fn remove_file_url(&self, uri: &Url)
pub fn remove_file_url(&self, uri: &Url)
Remove a file from the index (URL variant for compatibility)
§Arguments
uri- File URI as a parsedUrl
§Returns
Nothing. The index is updated in-place.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
use url::Url;
let index = WorkspaceIndex::new();
let uri = Url::parse("file:///example.pl")?;
index.remove_file_url(&uri);Sourcepub fn clear_file(&self, uri: &str)
pub fn clear_file(&self, uri: &str)
Sourcepub fn clear_file_url(&self, uri: &Url)
pub fn clear_file_url(&self, uri: &Url)
Clear a file from the index (URL variant for compatibility)
§Arguments
uri- File URI as a parsedUrl
§Returns
Nothing. The index is updated in-place.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
use url::Url;
let index = WorkspaceIndex::new();
let uri = Url::parse("file:///example.pl")?;
index.clear_file_url(&uri);Sourcepub fn index_file_str(&self, uri: &str, text: &str) -> Result<(), String>
pub fn index_file_str(&self, uri: &str, text: &str) -> Result<(), String>
Index a file from a URI string for the Index/Analyze workflow.
Accepts either a file:// URI or a filesystem path. Not available on
wasm32 targets (requires filesystem path conversion).
§Arguments
uri- File URI string or filesystem path.text- Full Perl source text for indexing.
§Returns
Ok(()) when indexing succeeds, or an error message otherwise.
§Errors
Returns an error if the URI is invalid or parsing fails.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
let index = WorkspaceIndex::new();
index.index_file_str("file:///example.pl", "sub hello { }")?;Sourcepub fn index_files_batch(
&self,
files_to_index: Vec<(Url, String)>,
) -> Vec<String>
pub fn index_files_batch( &self, files_to_index: Vec<(Url, String)>, ) -> Vec<String>
Index multiple files in a single batch operation.
This is significantly faster than calling index_file in a loop for
initial workspace scans because it defers the global symbol cache
rebuild to a single pass at the end.
Phase 1: Parse all files without holding locks. Phase 2: Bulk-insert file indices and rebuild the symbol cache once.
Sourcepub fn find_references(&self, symbol_name: &str) -> Vec<Location>
pub fn find_references(&self, symbol_name: &str) -> Vec<Location>
Find all references to a symbol using dual indexing strategy
This function searches for both exact matches and bare name matches when the symbol is qualified. For example, when searching for “Utils::process_data”:
- First searches for exact “Utils::process_data” references
- Then searches for bare “process_data” references that might refer to the same function
This dual approach handles cases where functions are called both as:
- Qualified:
Utils::process_data() - Unqualified:
process_data()(when in the same package or imported)
§Arguments
symbol_name- Symbol name or qualified name to search
§Returns
All reference locations found for the requested symbol.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
let index = WorkspaceIndex::new();
let _refs = index.find_references("Utils::process_data");Sourcepub fn count_usages(&self, symbol_name: &str) -> usize
pub fn count_usages(&self, symbol_name: &str) -> usize
Count non-definition references (usages) of a symbol.
Like find_references but excludes ReferenceKind::Definition entries,
returning only actual usage sites. This is used by code lens to show
“N references” where N means call sites, not the definition itself.
Sourcepub fn find_definition(&self, symbol_name: &str) -> Option<Location>
pub fn find_definition(&self, symbol_name: &str) -> Option<Location>
Find the definition of a symbol
§Arguments
symbol_name- Symbol name or qualified name to resolve
§Returns
The first matching definition location, if found.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
let index = WorkspaceIndex::new();
let _def = index.find_definition("MyPackage::example");Sourcepub fn all_symbols(&self) -> Vec<WorkspaceSymbol>
pub fn all_symbols(&self) -> Vec<WorkspaceSymbol>
Sourcepub fn file_count(&self) -> usize
pub fn file_count(&self) -> usize
Return the number of indexed files in the workspace
Sourcepub fn symbol_count(&self) -> usize
pub fn symbol_count(&self) -> usize
Return the total number of symbols across all indexed files
Sourcepub fn has_symbols(&self) -> bool
pub fn has_symbols(&self) -> bool
Check if the workspace index has symbols (soft readiness check)
Returns true if the index contains any symbols, indicating that at least some files have been indexed and the workspace is ready for symbol-based operations like completion.
§Returns
true if any symbols are indexed, otherwise false.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
let index = WorkspaceIndex::new();
assert!(!index.has_symbols());Sourcepub fn search_symbols(&self, query: &str) -> Vec<WorkspaceSymbol>
pub fn search_symbols(&self, query: &str) -> Vec<WorkspaceSymbol>
Search for symbols by query
§Arguments
query- Substring to match against symbol names
§Returns
Symbols whose names or qualified names contain the query string.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
let index = WorkspaceIndex::new();
let _results = index.search_symbols("example");Sourcepub fn find_symbols(&self, query: &str) -> Vec<WorkspaceSymbol>
pub fn find_symbols(&self, query: &str) -> Vec<WorkspaceSymbol>
Find symbols by query (alias for search_symbols for compatibility)
§Arguments
query- Substring to match against symbol names
§Returns
Symbols whose names or qualified names contain the query string.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
let index = WorkspaceIndex::new();
let _results = index.find_symbols("example");Sourcepub fn file_symbols(&self, uri: &str) -> Vec<WorkspaceSymbol>
pub fn file_symbols(&self, uri: &str) -> Vec<WorkspaceSymbol>
Sourcepub fn file_dependencies(&self, uri: &str) -> HashSet<String>
pub fn file_dependencies(&self, uri: &str) -> HashSet<String>
Sourcepub fn find_dependents(&self, module_name: &str) -> Vec<String>
pub fn find_dependents(&self, module_name: &str) -> Vec<String>
Find all files that depend on a module
§Arguments
module_name- Module name to search for in file dependencies
§Returns
A list of file URIs that import or depend on the module.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
let index = WorkspaceIndex::new();
let _files = index.find_dependents("My::Module");Sourcepub fn document_store(&self) -> &DocumentStore
pub fn document_store(&self) -> &DocumentStore
Sourcepub fn find_unused_symbols(&self) -> Vec<WorkspaceSymbol>
pub fn find_unused_symbols(&self) -> Vec<WorkspaceSymbol>
Sourcepub fn get_package_members(&self, package_name: &str) -> Vec<WorkspaceSymbol>
pub fn get_package_members(&self, package_name: &str) -> Vec<WorkspaceSymbol>
Get all symbols that belong to a specific package
§Arguments
package_name- Package name to match (e.g.,My::Package)
§Returns
Symbols defined within the requested package.
§Examples
use perl_parser::workspace_index::WorkspaceIndex;
let index = WorkspaceIndex::new();
let _members = index.get_package_members("My::Package");Sourcepub fn find_def(&self, key: &SymbolKey) -> Option<Location>
pub fn find_def(&self, key: &SymbolKey) -> Option<Location>
Find the definition location for a symbol key during Index/Navigate stages.
§Arguments
key- Normalized symbol key to resolve.
§Returns
The definition location for the symbol, if found.
§Examples
use perl_parser::workspace_index::{SymKind, SymbolKey, WorkspaceIndex};
use std::sync::Arc;
let index = WorkspaceIndex::new();
let key = SymbolKey { pkg: Arc::from("My::Package"), name: Arc::from("example"), sigil: None, kind: SymKind::Sub };
let _def = index.find_def(&key);Sourcepub fn find_refs(&self, key: &SymbolKey) -> Vec<Location>
pub fn find_refs(&self, key: &SymbolKey) -> Vec<Location>
Find reference locations for a symbol key using dual indexing.
Searches both qualified and bare names to support Navigate/Analyze workflows.
§Arguments
key- Normalized symbol key to search for.
§Returns
All reference locations for the symbol, excluding the definition.
§Examples
use perl_parser::workspace_index::{SymKind, SymbolKey, WorkspaceIndex};
use std::sync::Arc;
let index = WorkspaceIndex::new();
let key = SymbolKey { pkg: Arc::from("main"), name: Arc::from("example"), sigil: None, kind: SymKind::Sub };
let _refs = index.find_refs(&key);