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, range } => {
// Search registry and build completions, replacing `range`
vec![]
}
CompletionContext::Version { package_name, prefix } => {
// Fetch versions and build completions
vec![]
}
_ => vec![],
}
}Structs§
- Completions
- Result of
Ecosystem::generate_completions. - Version
Display Item - Display metadata for a single version in LSP responses.
Enums§
- Completion
Context - Context for completion request based on cursor position.
Constants§
- COMPLETION_
SEARCH_ TIMEOUT - Wall-clock budget
deps-lsp’s completion handler gives an ecosystem’sgenerate_completionsbefore treating it as a timeout.
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.
- byte_
to_ utf16_ offset - Converts a byte offset within
sto a UTF-16 code unit offset (LSPPosition.character). - complete_
package_ names_ generic - Generic package name completion using any
Registryimplementation. - complete_
versions_ at_ position - Version completion resolved by cursor position, not by package name (issue #593).
- complete_
versions_ generic - Generic version completion logic used by all ecosystems.
- complete_
versions_ generic_ from - Like
complete_versions_generic, but resolves throughcrate::Registry::get_versions_from. - detect_
completion_ context - Detects the completion context based on cursor position.
- extract_
feature_ prefix - Extracts the partial feature name typed at the cursor position.
- extract_
prefix - Extracts the prefix text from content at a position within a range.
- is_
valid_ completion_ prefix_ len - Checks whether
prefixhas an acceptable length (2 to 200 characters, inclusive) for triggering a package-name completion search. - 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.