Repository navigation
Deduplicate object completions across sources deterministically - #1455
Conversation
samclark2015
left a comment
There was a problem hiding this comment.
LGTM! One comment below, a possible improvement on behavior. Good to merge with or without.
BTW - It looks like this (at least partially) addresses #813, in addition to the Positron issue 👀
| if item.kind == Some(CompletionItemKind::VARIABLE) && | ||
| existing.item.kind != Some(CompletionItemKind::VARIABLE) | ||
| { | ||
| existing.item.kind = item.kind; | ||
| existing.item.sort_text = item.sort_text; | ||
| } | ||
| } |
There was a problem hiding this comment.
This promotes the document-level definition, but it drops some useful data. For instance, documentation ("Defined in this document on line N.") is missing, and label_details points to the shadowed definition's package source. With letters <- 1:3 unrun, you get letters {base}.
Could we replace the item, instead of just updating these two attributes? I think that resolves the letters known limitation, since the search-path item doesn't carry docs for objects. It'd also cover function parameters (function(letters) lett), which hit the same merge but never get fixed by running code.
There was a problem hiding this comment.
Thanks, that is a great point! Added in a53afb4.
Addresses posit-dev/positron#12098.
When you type an object name like
outPathagain and again, ark now returns one completion item for it, with the same icon and position each time:Before this change, the icon and the position of the item changed between requests.
The cause was in the composite completion merger in
composite.rs. The same R object comes back from three sources with three different kinds:VARIABLEfrom the document,STRUCTfrom the search path, andVALUEfrom the workspace. The dedupe key was(label, kind), so all three items survived. The merger kept them in aHashMap, so their order was random. 😱 Positron dedupes completions byinsertTextand keeps the first item with equal priority (seesrc/vs/editor/contrib/suggest/browser/suggest.ts). As a result, Positron showed a different one of the three items on each request.Changes
VARIABLE,STRUCTandVALUEnow share one dedupe class. Object items also key on their insert text, so a quoted subset column ("x") and a global objectxstay separate. All other kinds stay distinct. For example,foras a keyword andforas a snippet both remain, and so doglue::andglue().{package}label.VARIABLEkind andsort_text. The user sees the variable icon, as the reporter expected, and the item stays in the variable sort bin. A pipe or subset column is already aVARIABLE, so it keeps its ownsort_text.IndexMapin place of aHashMap, so the merge order is deterministic now. 😅 This addsindexmaptocrates/ark/Cargo.toml.Known limitations
letters <- 1:3that you did not run yet. The user then sees oneletters {base}item with the variable icon and the docs from base. Before this change, Positron picked one of the two items at random.`my var`) are not deduplicated. The document label includes the backticks, but the search path label does not.Testing
VARIABLEkind andsort_texttakeover, different insert text, keyword and snippet, and package and function.get_completions_at_cursor. One test asks for completions five times in a row to copy the retype behavior. It expects the same single item each time. Other tests cover an object that is only in the document, a pipe column, and a subset column.outPath <- "myDirectory".out. Then delete it and type it again. Do this a few times.outPathchanged. After this change, you see oneoutPathitem with the variable icon, in the same position each time.Positron Release Notes
New Features
Bug Fixes