Skip to main content

build_package_completion

Function build_package_completion 

Source
pub fn build_package_completion(
    metadata: &dyn Metadata,
    insert_range: Range,
) -> Option<CompletionItem>
Expand description

Builds a completion item for a package name.

Creates a properly formatted LSP CompletionItem with documentation, version information, and links to repository/docs.

§Arguments

  • metadata - Package metadata from registry search
  • insert_range - LSP range where the completion should be inserted

§Returns

Some(CompletionItem) ready to send to the LSP client, or None when metadata.name() fails crate::is_safe_package_name — a malicious/compromised registry search result must not reach the manifest as an unsanitized label, insert_text, text_edit, sort_text, or filter_text, so the item is dropped rather than built with unsafe text.

§Examples

use deps_core::completion::build_package_completion;
use tower_lsp_server::ls_types::Range;

let range = Range::default(); // Use actual range from context
let item = build_package_completion(metadata, range).unwrap();
assert_eq!(item.label, metadata.name().as_str());