Skip to content

Commit

Permalink
Add package information in completions
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Oct 31, 2024
1 parent dc5b37a commit b4b1fc8
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions crates/ark/src/lsp/completions/completion_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,8 +176,9 @@ pub(super) fn completion_item_from_function<T: AsRef<str>>(

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);
Expand All @@ -192,6 +194,21 @@ pub(super) fn completion_item_from_function<T: AsRef<str>>(
return Ok(item);
}

fn item_details(_detail: Option<String>, 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<CompletionItem> {
let mut item = completion_item(name.to_string(), CompletionData::Unknown)?;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b4b1fc8

Please sign in to comment.