CompletionContext

class CompletionContext(**properties: Any)

Superclasses: Object

Implemented Interfaces: ListModel

The context of a completion.

GtkSourceCompletionContext contains information about an attept to display completion proposals to the user based on typed text in the View.

When typing, Completion may use registered CompletionProvider to determine if there may be results which could be displayed. If so, a GtkSourceCompletionContext is created with information that is provided to the CompletionProvider to populate results which might be useful to the user.

CompletionProvider are expected to provide ListModel with CompletionProposal which may be joined together in a list of results for the user. They are also responsible for how the contents are displayed using CompletionCell which allows for some level of customization.

Methods

class CompletionContext
get_activation() CompletionActivation

Gets the mode for which the context was activated.

get_bounds() tuple[bool, TextIter, TextIter]

Gets the bounds for the completion, which is the beginning of the current word (taking break characters into account) to the current insertion cursor.

If begin is non-None, it will be set to the start position of the current word being completed.

If end is non-None, it will be set to the insertion cursor for the current word being completed.

get_buffer() Buffer | None

Gets the underlying buffer used by the context.

This is a convenience function to get the buffer via the Completion property.

get_busy() bool

Gets the “busy” property. This is set to True while the completion context is actively fetching proposals from registered CompletionProvider’s.

get_completion() Completion | None

Gets the Completion that created the context.

get_empty() bool

Checks if any proposals have been provided to the context.

Out of convenience, this function will return True if self is None.

get_language() Language | None

Gets the language of the underlying buffer, if any.

get_proposals_for_provider(provider: CompletionProvider) ListModel | None

Gets the ListModel associated with the provider.

You can connect to CompletionContext::model-changed to receive notifications about when the model has been replaced by a new model.

Added in version 5.6.

Parameters:

provider – a CompletionProvider

get_view() View | None

Gets the text view for the context.

get_word() str

Gets the word that is being completed up to the position of the insert mark.

list_providers() ListModel

Gets the providers that are associated with the context.

Added in version 5.6.

set_proposals_for_provider(provider: CompletionProvider, results: ListModel | None = None) None

This function allows providers to update their results for a context outside of a call to populate_async.

This can be used to immediately return results for a provider while it does additional asynchronous work. Doing so will allow the completions to update while the operation is in progress.

Parameters:

Properties

class CompletionContext
props.busy: bool

The “busy” property is True while the completion context is populating completion proposals.

props.completion: Completion

The “completion” is the Completion that was used to create the context.

props.empty: bool

The “empty” property is True when there are no results.

It will be notified when the first result is added or the last result is removed.

Signals

class CompletionContext.signals
provider_model_changed(provider: CompletionProvider, model: ListModel | None = None) None

Emitted when a provider changes a model.

This signal is primarily useful for CompletionProvider’s that want to track other providers in context. For example, it can be used to create a “top results” provider.

Added in version 5.6.

Parameters: