-
Notifications
You must be signed in to change notification settings - Fork 43
improve completions sorting #798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is turning out GREAT! 🤩
I am very supportive of going this direction and iterating to finetune the behavior in the future.
I do notice a few difference in R completions, but I am not sure with my current level of review whether we should change what happens in ark or here in this logic. Just in case you might already know, an immediate noticeable difference I am seeing is that R packages show up in the visual editor but not the source editor:

It's the bslib
and jquerylib
entries there.
I am not sure either. If we can identify issues with R completions, I would now say it shouldn't be difficult to address them here. Tangential discussion, but: note that since ark always gives like 2500+ completions, and since sorting and filtering is done in the UI process, processing completions is consistently slightly slow in R code and makes the UI feel slightly less responsive. I might try moving a bunch of the filtering to the LSP so its not in the UI process. I feel like ideally ark would do some basic filtering on their side(such as inclusion of what the user is typing in the proposed completions) for performance.
I noticed these! I didn't know what they were but I played around with them and they seem useful? |
I wonder if I should just do another quick pass over this then go to merge it. I can't think of another step forward. Maybe I should get someone who uses R in Positron to try it out. |
I will have the ark team outline some changes we could make to the completions offered, but I think that slightly slow completions in R is totally fine for an initial PR. 👍 I would love to see if we could address those package/namespace completions that appear (i.e. One other note, I would keep the completions turned off (i.e. that code that is commented out right now) until we can get Tab fixed up to accept a suggestion. It is pretty surprising not to be able to accept with Tab! 😅 I am totally fine to merge this in, if completions stay turned off! I think the things I would like to see before we turn completions on are:
|
Thank you @juliasilge, totally clarifying. |
I also have code based on this PR that fixes position miscalculations that result in snippets often being filtered out of completions. After I fixed that, I found out that snippets with nested fields are somewhat broken in codemirror's autocomplete extension. I raised an issue in their repo here: codemirror/dev#1607 |
@juliasilge I have added
The PR is ready! |
It looks like you may want to merge #801 into this branch. Do you want to do that before I review? Or an additional review afterwards? Just let me know! |
@juliasilge I feel that #801 is blocked on being able to upgrade to the last codemirror/autocomplete version. This version fixes snippets with nested fields (which seem to be common in R). I attempted to upgrade but failed due to Quarto monorepo things that I don't understand. @juliasilge please review this one and we can merge it, then rebase #801 on main. I don't want #801 to block this one (they solve separate problems). |
@juliasilge asked me to summarise a potential change we may make on the ark side regarding completions It's mostly this comment: posit-dev/positron#4489 (comment) With the TLDR being that completions can be thought of in two ways:
Right now Ark's initial set sends everything relevant over and we rely fully on the frontend for all filtering. This results in a model where:
RStudio's model is:
I think people would enjoy if Positron moved towards this model as well. We'd accomplish this by making Ark send over an initial set of completions that have been filtered to only a (roughly) strict subset of what the user has typed. So if the user has typed The benefits are that we get a model that works a bit more like RStudio, which I do like. The downsides are that ark itself is muddying the waters a bit about how completions should be filtered in Positron. There are a lot of existing options in Positron related to sorting and filtering completions, and if ark pre-filters completions then it might make the experience feel a bit inconsistent. But I don't think that is a huge worry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is such an incredible improvement! Having Tab set up to accept completions is such a relief. 😅 I think we should merge and move forward!
I do think we're going to get reports of differences in the completions in visual vs. editor mode, but we can log those and address them moving forward. Maybe we can even set up some testing infrastructure so we can test completions for the visual editor, to specify the expected behavior via tests? Like unit tests for the editor-codemirror
package here?
@DavisVaughan Thank you for outlining those thoughts. Should we log any of that additional detail at posit-dev/ark#900?
// if this is Positron, no visual editor completions | ||
// TODO: fix LSP issues for visual editor in Positron: | ||
// https://github.com/posit-dev/positron/issues/1805 | ||
if (hasHooks()) { | ||
return { | ||
items: [], | ||
isIncomplete: false | ||
}; | ||
} | ||
// if (hasHooks()) { | ||
// return { | ||
// items: [], | ||
// isIncomplete: false | ||
// }; | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this code before we merge!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
// no namespaces | ||
if (vsKindToType(item.kind) === 'namespace') return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly recommend not wholesale removing namespaces
Namespaces are included in both RStudio and Positron's console and it is very important to be able to complete these


@juliasilge had made a comment about bslib not showing up when she typed lib
in source mode, but I think that just has to do with how VS Code itself filters based on the text and doesn't have anything to do with the type of completion in question.
For example, if I do the same thing i see lightgbm pop up in the positron console, which suggests that namespace completions are definitely still there

So I vote we just remove this because keeping it would make for a worse experience overall
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I am OK with that, and we can log a new issue to address the specific filtering that happens in this type of case. I do think we need to get some unit tests set up for completions so we can specify the behavior we expect in a fairly low-burden way, and then can iterate moving forward without regressing on various cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juliasilge FWIW if we do #798 (comment) then your experience here would be massively improved because only things starting with dpl
or lib
would be provided by ark in the initial set of completions
(I think that's a better way to improve the experience over turning off namespaces here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove the filtering of namespaces for now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@juliasilge I made an issue to capture the differences in filtering in the case of namespaces #808
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @vezwork!
I was originally planning to copy completions sorting code from VSCode, but it is incredibly complex and cannot be directly copied&pasted (because we probably don't want to rewrite CodeMirror's Autocompletion from scratch). If I was going to copy VSCode's completion code, at the very least I would first have to understand how CodeMirror Autocompletion API works...
So, in this PR I have
Upon initial testing, the completions are good in both Python and R in Positron and VSCode with the Python Jedi language server. It may be best to go with this simple fix for now. In the future it would be good if we can understand more what is happening in VSCode completions, but I have realized that could be quite a bit of work outside of my domain.