Skip to content

Commit 087d42d

Browse files
committed
[ty] Enforce sort order of completions
We achieve this by setting the "sort text" field of every completion. Since we are trying to be smart about the order, we want the client to respect our order. Prior to this change, VS Code was re-sorting completions in lexicographic order. This in turn resulted in dunder attributes appearing before "normal" attributes.
1 parent 0edbd6c commit 087d42d

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

crates/ty_server/src/server/api/requests/completion.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler {
5151
return Ok(None);
5252
}
5353

54+
let max_index = completions.len().saturating_sub(1);
5455
let items: Vec<CompletionItem> = completions
5556
.into_iter()
56-
.map(|comp| CompletionItem {
57+
.enumerate()
58+
.map(|(i, comp)| CompletionItem {
5759
label: comp.label,
60+
sort_text: Some(format!("{i:-pad$}", pad = max_index)),
5861
..Default::default()
5962
})
6063
.collect();

0 commit comments

Comments
 (0)