pub fn build_version_completion(
display_item: &VersionDisplayItem,
insert_range: Option<Range>,
now: PublishTime,
freshness_enabled: bool,
) -> CompletionItemExpand description
Builds a completion item for a version string.
Creates a properly formatted LSP CompletionItem with version metadata in a simplified format matching Code Actions (Cmd+.) style.
§Arguments
display_item- Version display metadata with label, description, and flagsinsert_range- Optional LSP range where the completion should replace text. IfNone, the completion will insert at cursor position without replacing.now- Current instant, injected explicitly rather than read internally, so every item in the same completion response has its age computed against one consistent instant instead of drifting mid-request.
§Returns
A complete CompletionItem with simple index-based sorting and preselect.
§Format
- Label:
"version"or"version (latest)"for the latest version - Detail:
"Update package_name to version" - Label details: a greyed-out relative age (e.g.
"2 hours ago") whendisplay_item.published_atis known andfreshness_enabledistrue; omitted entirely otherwise - Preselect:
truefor latest version,falseotherwise - Sort: Index-based (00000, 00001, etc.)
§Examples
use deps_core::completion::{build_version_completion, VersionDisplayItem};
use deps_core::PackageName;
use tower_lsp_server::ls_types::Range;
let now = deps_core::PublishTime::now();
// Without range - insert at cursor
let display_item = VersionDisplayItem::new(version, &PackageName::new("serde"), 0, true);
let item = build_version_completion(&display_item, None, now, true);
assert_eq!(item.label, display_item.label);
// With range - replace existing text
let range = Range::default();
let item = build_version_completion(&display_item, Some(range), now, true);