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§
- Version
Display Item - Display metadata for a single version in LSP responses.
Enums§
- Completion
Context - 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.