Skip to main content

WorkspaceIndex

Struct WorkspaceIndex 

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

Workspace indexing and refactoring orchestration. Thread-safe workspace index

Implementations§

Source§

impl WorkspaceIndex

Source

pub fn new() -> WorkspaceIndex

Create a new empty index

§Returns

A workspace index with empty file and symbol tables.

§Examples
use perl_parser::workspace_index::WorkspaceIndex;

let index = WorkspaceIndex::new();
assert!(!index.has_symbols());
Source

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 document
  • text - 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.

Source

pub fn remove_file(&self, uri: &str)

Remove a file from the index

§Arguments
  • uri - File URI (string form) to remove
§Returns

Nothing. The index is updated in-place.

§Examples
use perl_parser::workspace_index::WorkspaceIndex;

let index = WorkspaceIndex::new();
index.remove_file("file:///example.pl");
Source

pub fn remove_file_url(&self, uri: &Url)

Remove a file from the index (URL variant for compatibility)

§Arguments
  • uri - File URI as a parsed Url
§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);
Source

pub fn clear_file(&self, uri: &str)

Clear a file from the index (alias for remove_file)

§Arguments
  • uri - File URI (string form) to remove
§Returns

Nothing. The index is updated in-place.

§Examples
use perl_parser::workspace_index::WorkspaceIndex;

let index = WorkspaceIndex::new();
index.clear_file("file:///example.pl");
Source

pub fn clear_file_url(&self, uri: &Url)

Clear a file from the index (URL variant for compatibility)

§Arguments
  • uri - File URI as a parsed Url
§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);
Source

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 { }")?;
Source

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.

Source

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");
Source

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.

Source

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");
Source

pub fn all_symbols(&self) -> Vec<WorkspaceSymbol>

Get all symbols in the workspace

§Returns

A vector containing every symbol currently indexed.

§Examples
use perl_parser::workspace_index::WorkspaceIndex;

let index = WorkspaceIndex::new();
let _symbols = index.all_symbols();
Source

pub fn clear(&self)

Clear all indexed files and symbols from the workspace.

Source

pub fn file_count(&self) -> usize

Return the number of indexed files in the workspace

Source

pub fn symbol_count(&self) -> usize

Return the total number of symbols across all indexed files

Source

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());
Source

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");
Source

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");
Source

pub fn file_symbols(&self, uri: &str) -> Vec<WorkspaceSymbol>

Get symbols in a specific file

§Arguments
  • uri - File URI to inspect
§Returns

All symbols indexed for the requested file.

§Examples
use perl_parser::workspace_index::WorkspaceIndex;

let index = WorkspaceIndex::new();
let _symbols = index.file_symbols("file:///example.pl");
Source

pub fn file_dependencies(&self, uri: &str) -> HashSet<String>

Get dependencies of a file

§Arguments
  • uri - File URI to inspect
§Returns

A set of module names imported by the file.

§Examples
use perl_parser::workspace_index::WorkspaceIndex;

let index = WorkspaceIndex::new();
let _deps = index.file_dependencies("file:///example.pl");
Source

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");
Source

pub fn document_store(&self) -> &DocumentStore

Get the document store

§Returns

A reference to the in-memory document store.

§Examples
use perl_parser::workspace_index::WorkspaceIndex;

let index = WorkspaceIndex::new();
let _store = index.document_store();
Source

pub fn find_unused_symbols(&self) -> Vec<WorkspaceSymbol>

Find unused symbols in the workspace

§Returns

Symbols that have no non-definition references in the workspace.

§Examples
use perl_parser::workspace_index::WorkspaceIndex;

let index = WorkspaceIndex::new();
let _unused = index.find_unused_symbols();
Source

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");
Source

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);
Source

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);

Trait Implementations§

Source§

impl Default for WorkspaceIndex

Source§

fn default() -> WorkspaceIndex

Returns the “default value” for a type. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more