-
Notifications
You must be signed in to change notification settings - Fork 139
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
feat: improve auto_show flexibility #697
Conversation
This PR gives more control over when and where we show automatic completion. It does this with two public-facing changes: 1. `completion.menu.auto_show` can now be either a function in addition to a constant boolean. This gives users the ability to make more complex decisions about whether to automatically show completions. 2. `blink.cmp.Context` contains a new field -- `update_type`. This field provides additional information on what triggered the update. This allows users to vary behavior when completion is manually triggered (as opposed to being automatically triggered by keywords or trigger characters).
5fd7ac5
to
496e428
Compare
|
||
-- check if we've entered insert mode on a trigger character | ||
elseif insert_enter_on_trigger_character then | ||
trigger.context = nil | ||
trigger.show({ trigger_character = char_under_cursor }) | ||
trigger.show({ trigger_character = char_under_cursor, update_type = 'auto_show_trigger_char' }) |
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.
We could have a separate update type for this -- interested in thoughts on whether that would actually be useful.
I believe the global |
2631f4b
to
9b4b7af
Compare
I've also added an should_show_items = function(ctx) ctx.trigger.initial_kind ~= 'trigger_character' end |
Thank you! |
This code was reduced by a line before merging PR Saghen#697, but it's now hitting the case where the Lua 'ternary' doesn't behave like a proper ternary operator. Specifically, when the `auto_show` function returns false, the result of ```lua auto_show = type(auto_show) == "function" and auto_show(...) or auto_show ``` becomes ```lua auto_show = (true and false) or <function> ``` which is the truthy function reference itself.
This code was reduced by a line before merging PR #697, but it's now hitting the case where the Lua 'ternary' doesn't behave like a proper ternary operator. Specifically, when the `auto_show` function returns false, the result of ```lua auto_show = type(auto_show) == "function" and auto_show(...) or auto_show ``` becomes ```lua auto_show = (true and false) or <function> ``` which is the truthy function reference itself.
This PR gives more control over when and where we show automatic completion. It does this with two public-facing changes:
completion.menu.auto_show
can now be either a function or a constant boolean. This gives users the ability to make more complex decisions about whether to automatically show completions.blink.cmp.Context
contains a new field --update_type
. This field provides additional information on what triggered the update. This allows users to vary behavior when completion is manually triggered (as opposed to being automatically triggered by keywords or trigger characters).