-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Disable auto-complete on comments #5089
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
Disable auto-complete on comments #5089
Conversation
I think only keyword completion is triggered in comments, so let’s at least move the check to keywords. All the other completion contributors are more specific, and just don’t match comments at all. I wonder why keywords match thoug? Perhaps there’s some bug? What I am getting at is that “should this completion be triggered here” check is supposed to be precise, if keywords trigger in comments, there might be some additional cases where they falsely trigger, and we need to avoid that as well. |
Good call. Somehow it didn't occur to me as odd that only one set of checks ( However, I still think explicitly checking if we are on a comment in if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent {
add_keyword(ctx, acc, "const", "const ");
add_keyword(ctx, acc, "type", "type ");
} It's easy to see that something like: fn foo() {
x = 2 // A comment<|>
} will still add Because the rules to add keywords in |
scoping is comment check to only keywords seems fine by me! |
e06671c
to
c03deed
Compare
c03deed
to
cc77bdf
Compare
@matklad I changed the implementation to just check if the current token is a comment in Hope it's ok to do a direct token comparison here. I can't see another way to check if it's a comment. Also, it looks like |
bors r+ |
Resolves #4907 by disabling any auto-completion on comments.
As flodiebold pointed out, in the future we may want to support some form of auto-completion within doc comments, but for now it was suggested to just disable auto-completion on them entirely.
The implementation involves adding a new field
is_comment
toCompletionContext
and checking if the immediate token we auto-completed on is a comment. I couldn't see a case where we need to check any of the ancestors, but let me know if this is not sufficient. I also wasn't sure if it was necessary to add a new field to this struct, but I decided it's probably the best option if we want to potentially do auto-completion on doc comments in the future.Finally, the three tests I added should I think ideally not filter results by
CompletionKind::Keyword
, but if I want to get unfiltered results, I need access to a non-public function get_all_completion_items which I don't know if I should make public just for this.