Skip to content

Commit 1461137

Browse files
authored
[ty] Enforce sort order of completions (#18917)
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 47653ca commit 1461137

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_len = completions.len().saturating_sub(1).to_string().len();
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:-max_index_len$}")),
5861
..Default::default()
5962
})
6063
.collect();

0 commit comments

Comments
 (0)