diff --git a/crates/ark/src/lsp/completions/completion_item.rs b/crates/ark/src/lsp/completions/completion_item.rs index cb789a5a9..650d14fea 100644 --- a/crates/ark/src/lsp/completions/completion_item.rs +++ b/crates/ark/src/lsp/completions/completion_item.rs @@ -31,6 +31,7 @@ use stdext::*; use tower_lsp::lsp_types::Command; use tower_lsp::lsp_types::CompletionItem; use tower_lsp::lsp_types::CompletionItemKind; +use tower_lsp::lsp_types::CompletionItemLabelDetails; use tower_lsp::lsp_types::CompletionTextEdit; use tower_lsp::lsp_types::Documentation; use tower_lsp::lsp_types::InsertTextFormat; @@ -175,8 +176,9 @@ pub(super) fn completion_item_from_function>( item.kind = Some(CompletionItemKind::FUNCTION); - let detail = format!("{}({})", name, parameters.joined(", ")); - item.detail = Some(detail); + let detail = format!("({})", parameters.joined(", ")); + let label_details = item_details(Some(detail), package); + item.label_details = Some(label_details); let insert_text = sym_quote_invalid(name); item.insert_text_format = Some(InsertTextFormat::SNIPPET); @@ -192,6 +194,21 @@ pub(super) fn completion_item_from_function>( return Ok(item); } +fn item_details(_detail: Option, package: Option<&str>) -> CompletionItemLabelDetails { + let description = package.map(|p| { + // Environments from the search path often have a "package:" prefix. + // Remove it from display. This creates some rare ambiguities but + // improves the display generally. + let p = p.strip_prefix("package:").unwrap_or(p); + format!("{{{p}}}") + }); + + CompletionItemLabelDetails { + detail: None, // Currently ignored. Make it configurable? + description, + } +} + // TODO pub(super) unsafe fn completion_item_from_dataset(name: &str) -> Result { let mut item = completion_item(name.to_string(), CompletionData::Unknown)?; @@ -250,7 +267,8 @@ pub(super) unsafe fn completion_item_from_object( name: name.to_string(), })?; - item.detail = Some("(Object)".to_string()); + let detail = Some("(Object)".to_string()); + item.label_details = Some(item_details(detail, package)); item.kind = Some(CompletionItemKind::STRUCT); if !is_symbol_valid(name) {