Module completion

Module completion 

Source
Expand description

Core completion infrastructure for deps-lsp.

This module provides generic completion functionality that works across all package ecosystems (Cargo, npm, PyPI, etc.). It handles:

  • Context detection - determining what type of completion is appropriate
  • Prefix extraction - getting the text typed so far
  • CompletionItem builders - creating LSP completion responses

§Architecture

The completion system uses trait objects (dyn Dependency, dyn ParseResult, dyn Version, dyn Metadata) to work generically across ecosystems.

§Examples

use deps_core::completion::{detect_completion_context, CompletionContext};
use tower_lsp_server::ls_types::Position;

// In your ecosystem's generate_completions implementation:
async fn generate_completions(
    parse_result: &dyn deps_core::ParseResult,
    position: Position,
    content: &str,
) -> Vec<tower_lsp_server::ls_types::CompletionItem> {
    let context = detect_completion_context(parse_result, position, content);

    match context {
        CompletionContext::PackageName { prefix } => {
            // Search registry and build completions
            vec![]
        }
        CompletionContext::Version { package_name, prefix } => {
            // Fetch versions and build completions
            vec![]
        }
        _ => vec![],
    }
}

Structs§

VersionDisplayItem
Display metadata for a single version in LSP responses.

Enums§

CompletionContext
Context for completion request based on cursor position.

Functions§

build_feature_completion
Builds a completion item for a feature flag.
build_package_completion
Builds a completion item for a package name.
build_version_completion
Builds a completion item for a version string.
complete_versions_generic
Generic version completion logic used by all ecosystems.
detect_completion_context
Detects the completion context based on cursor position.
extract_prefix
Extracts the prefix text from content at a position within a range.
prepare_version_display_items
Filters and formats versions for LSP display.
utf16_to_byte_offset
Converts UTF-16 offset to byte offset in a string.