Skip to main content

CompletionProvider

Struct CompletionProvider 

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

Completion provider

Implementations§

Source§

impl CompletionProvider

Source

pub fn new_with_index( ast: &Node, workspace_index: Option<Arc<WorkspaceIndex>>, ) -> CompletionProvider

Create a new completion provider from parsed AST for Perl script analysis

§Arguments
  • ast - Parsed AST from Perl script content during LSP Parse stage
  • workspace_index - Optional workspace-wide symbol index for cross-file completion
§Returns

A configured completion provider ready for Perl parsing workflow analysis

§Examples
use perl_parser_core::Parser;
use perl_lsp_completion::CompletionProvider;

let mut parser = Parser::new("my $var = 42; sub hello { print $var; }");
let ast = parser.parse()?;
let provider = CompletionProvider::new_with_index(&ast, None);
// Provider ready for Perl script completion analysis

Arguments: ast, workspace_index.

Source

pub fn new_with_index_and_source( ast: &Node, source: &str, workspace_index: Option<Arc<WorkspaceIndex>>, ) -> CompletionProvider

Create a new completion provider from parsed AST and source with workspace integration

Constructs a completion provider with full workspace symbol information for comprehensive completion suggestions during Perl script editing within the LSP workflow. Integrates local AST symbols with workspace-wide indexing.

§Arguments
  • ast - Parsed AST containing local scope symbols and structure
  • source - Original source code for position-based context analysis
  • workspace_index - Optional workspace symbol index for cross-file completions
§Returns

A configured completion provider ready for LSP completion requests with both local and workspace symbol coverage for Perl script development.

§Examples
use perl_parser_core::Parser;
use perl_lsp_completion::CompletionProvider;
use perl_workspace_index::workspace_index::WorkspaceIndex;
use std::sync::Arc;

let script = "package EmailProcessor; sub filter_spam { my $var; }";
let mut parser = Parser::new(script);
let ast = parser.parse()?;

let workspace_idx = Arc::new(WorkspaceIndex::new());
let provider = CompletionProvider::new_with_index_and_source(
    &ast, script, Some(workspace_idx)
);
// Provider ready for cross-file Perl script completions

Arguments: ast, source, workspace_index. Returns: A configured completion provider. Example: CompletionProvider::new_with_index_and_source(&ast, source, None).

Source

pub fn new(ast: &Node) -> CompletionProvider

Create a new completion provider from parsed AST without workspace context

Constructs a basic completion provider using only local scope symbols from provided AST. Suitable for simple Perl script editing without cross-file dependencies in LSP workflow.

§Arguments
  • ast - Parsed AST containing local symbols for completion
§Returns

A completion provider configured for local-only completions without workspace symbol integration.

§Examples
use perl_parser_core::Parser;
use perl_lsp_completion::CompletionProvider;

let script = "my $email_count = 0; my $";
let mut parser = Parser::new(script);
let ast = parser.parse()?;

let provider = CompletionProvider::new(&ast);
// Provider ready for local variable completions

Arguments: ast. Returns: A completion provider configured for local-only symbols.

Source

pub fn get_completions_with_path( &self, source: &str, position: usize, filepath: Option<&str>, ) -> Vec<CompletionItem>

Get completions at a given position with optional filepath for enhanced context

Provides completion suggestions based on cursor position within Perl script source code. Uses filepath context to enable enhanced completions for test files and specific Perl parsing patterns within LSP workflows.

§Arguments
  • source - Email script source code for analysis
  • position - Byte offset cursor position for completion
  • filepath - Optional file path for context-aware completion enhancement
§Returns

Vector of completion items sorted by relevance for current context, including local variables, functions, and workspace symbols when available.

§Examples
use perl_parser_core::Parser;
use perl_lsp_completion::CompletionProvider;

let script = "my $var = 42; sub hello { print $var; }";
let mut parser = Parser::new(script);
let ast = parser.parse()?;

let provider = CompletionProvider::new(&ast);
let completions = provider.get_completions_with_path(
    script, script.len(), Some("/path/to/data_processor.pl")
);
assert!(!completions.is_empty());

See also Self::get_completions_with_path_cancellable for cancellation support and Self::get_completions for simple completions without filepath context. Arguments: source, position, filepath. Returns: A list of completion items for the current context. Example: provider.get_completions_with_path(source, pos, Some(path)).

Source

pub fn get_completions_with_path_cancellable( &self, source: &str, position: usize, filepath: Option<&str>, is_cancelled: &dyn Fn() -> bool, ) -> Vec<CompletionItem>

Get completions at a given position with cancellation support for responsive editing

Provides completion suggestions with cancellation capability for responsive Perl script editing during large workspace operations. Optimized for large-scale LSP environments where completion requests may need to be interrupted for better user experience.

§Arguments
  • source - Email script source code for completion analysis
  • position - Byte offset cursor position within the source
  • filepath - Optional file path for enhanced context detection
  • is_cancelled - Cancellation callback for responsive completion
§Returns

Vector of completion items or empty vector if operation was cancelled, sorted by relevance for optimal Perl script development experience.

§Performance
  • Respects cancellation for operations exceeding typical response times
  • Optimized for large Perl script files in large Perl codebase processing workflows
  • Provides partial results when possible before cancellation
§Examples
use perl_parser_core::Parser;
use perl_lsp_completion::CompletionProvider;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

let script = "package EmailHandler; sub process_emails { }";
let mut parser = Parser::new(script);
let ast = parser.parse()?;

let provider = CompletionProvider::new(&ast);
let cancelled = Arc::new(AtomicBool::new(false));
let cancel_fn = || cancelled.load(Ordering::Relaxed);

let completions = provider.get_completions_with_path_cancellable(
    script, script.len(), Some("email_handler.pl"), &cancel_fn
);

Arguments: source, position, filepath, is_cancelled. Returns: A list of completion items or an empty list when cancelled. Example: provider.get_completions_with_path_cancellable(source, pos, None, &|| false).

Source

pub fn get_completions( &self, source: &str, position: usize, ) -> Vec<CompletionItem>

Get completions at a given position for Perl script development

Provides basic completion suggestions at specified cursor position within Perl script source code. This is the primary interface for LSP completion requests during Perl parsing workflow development.

§Arguments
  • source - Email script source code for completion analysis
  • position - Byte offset cursor position where completions are requested
§Returns

Vector of completion items including local variables, functions, keywords, and built-in Perl constructs relevant to Perl parsing workflows.

§Examples
use perl_parser_core::Parser;
use perl_lsp_completion::CompletionProvider;

let script = "my $email_count = scalar(@emails); $email_c";
let mut parser = Parser::new(script);
let ast = parser.parse()?;

let provider = CompletionProvider::new(&ast);
let completions = provider.get_completions(script, script.len());

// Should include completion for $email_count variable
assert!(completions.iter().any(|c| c.label.contains("email_count")));

See also Self::get_completions_with_path for enhanced context-aware completions. Arguments: source, position. Returns: A list of completion items for the current context. Example: provider.get_completions(source, pos).

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