build_version_completion

Function build_version_completion 

Source
pub fn build_version_completion(
    display_item: &VersionDisplayItem,
    insert_range: Option<Range>,
) -> CompletionItem
Expand 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 flags
  • insert_range - Optional LSP range where the completion should replace text. If None, the completion will insert at cursor position without replacing.

§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"
  • Preselect: true for latest version, false otherwise
  • Sort: Index-based (00000, 00001, etc.)

§Examples

use deps_core::completion::{build_version_completion, VersionDisplayItem};
use tower_lsp_server::ls_types::Range;

// Without range - insert at cursor
let display_item = VersionDisplayItem::new(version, "serde", 0, true);
let item = build_version_completion(&display_item, None);
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));