:right-sidebar: True CompletionProvider =================================================================== .. currentmodule:: gi.repository.GtkSource .. class:: CompletionProvider(*args, **kwargs) :no-contents-entry: Implementations: :class:`~gi.repository.GtkSource.CompletionSnippets`, :class:`~gi.repository.GtkSource.CompletionWords` Completion provider interface. You must implement this interface to provide proposals to :obj:`~gi.repository.GtkSource.Completion`. In most cases, implementations of this interface will want to use :obj:`~gi.repository.CompletionProvider.populate_async` to asynchronously populate the results to avoid blocking the main loop. Methods ------- .. rst-class:: interim-class .. class:: CompletionProvider :no-index: .. method:: activate(context: ~gi.repository.GtkSource.CompletionContext, proposal: ~gi.repository.GtkSource.CompletionProposal) -> None This function requests ``proposal`` to be activated by the :obj:`~gi.repository.GtkSource.CompletionProvider`. What the provider does to activate the proposal is specific to that provider. Many providers may choose to insert a :obj:`~gi.repository.GtkSource.Snippet` with edit points the user may cycle through. See also: :obj:`~gi.repository.GtkSource.Snippet`, :obj:`~gi.repository.GtkSource.SnippetChunk`, :obj:`~gi.repository.View.push_snippet` :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param proposal: a :obj:`~gi.repository.GtkSource.CompletionProposal` .. method:: display(context: ~gi.repository.GtkSource.CompletionContext, proposal: ~gi.repository.GtkSource.CompletionProposal, cell: ~gi.repository.GtkSource.CompletionCell) -> None This function requests that the :obj:`~gi.repository.GtkSource.CompletionProvider` prepares ``cell`` to display the contents of ``proposal``. Based on ``cells`` column type, you may want to display different information. This allows for columns of information among completion proposals resulting in better alignment of similar content (icons, return types, method names, and parameter lists). :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param proposal: a :obj:`~gi.repository.GtkSource.CompletionProposal` :param cell: a :obj:`~gi.repository.GtkSource.CompletionCell` .. method:: get_priority(context: ~gi.repository.GtkSource.CompletionContext) -> int This function should return the priority of ``self`` in ``context``. The priority is used to sort groups of completion proposals by provider so that higher priority providers results are shown above lower priority providers. Higher value indicates higher priority. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` .. method:: get_title() -> str | None Gets the title of the completion provider, if any. Currently, titles are not displayed in the completion results, but may be at some point in the future when non-:const:`None`. .. method:: is_trigger(iter: ~gi.repository.Gtk.TextIter, ch: str) -> bool This function is used to determine if a character inserted into the text editor should cause a new completion request to be triggered. An example would be period '.' which might indicate that the user wants to complete method or field names of an object. This method will only trigger when text is inserted into the :obj:`~gi.repository.Gtk.TextBuffer` while the completion list is visible and a proposal is selected. Incremental key-presses (like shift, control, or alt) are not triggerable. :param iter: a :obj:`~gi.repository.Gtk.TextIter` :param ch: a :obj:`~gi.repository.gunichar` of the character inserted .. method:: key_activates(context: ~gi.repository.GtkSource.CompletionContext, proposal: ~gi.repository.GtkSource.CompletionProposal, keyval: int, state: ~gi.repository.Gdk.ModifierType) -> bool This function is used to determine if a key typed by the user should activate ``proposal`` (resulting in committing the text to the editor). This is useful when using languages where convention may lead to less typing by the user. One example may be the use of "." or "-" to expand a field access in the C programming language. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param proposal: a :obj:`~gi.repository.GtkSource.CompletionProposal` :param keyval: a keyval such as :obj:`~gi.repository.Gdk.KEY_period` :param state: a :obj:`~gi.repository.Gdk.ModifierType` or 0 .. method:: list_alternates(context: ~gi.repository.GtkSource.CompletionContext, proposal: ~gi.repository.GtkSource.CompletionProposal) -> list[~gi.repository.GtkSource.CompletionProposal] | None Providers should return a list of alternates to ``proposal`` or :const:`None` if there are no alternates available. This can be used by the completion view to allow the user to move laterally through similar proposals, such as overrides of methods by the same name. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param proposal: a :obj:`~gi.repository.GtkSource.CompletionProposal` .. method:: populate_async(context: ~gi.repository.GtkSource.CompletionContext, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[...], None] | None = None, *user_data: ~typing.Any) -> None Asynchronously requests that the provider populates the completion results for ``context``. For providers that would like to populate a :obj:`~gi.repository.Gio.ListModel` while those results are displayed to the user, :obj:`~gi.repository.CompletionContext.set_proposals_for_provider` may be used to reduce latency until the user sees results. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` or :const:`None` :param callback: a callback to execute upon completion :param user_data: closure data for ``callback`` .. method:: populate_finish(result: ~gi.repository.Gio.AsyncResult) -> ~gi.repository.Gio.ListModel Completes an asynchronous operation to populate a completion provider. :param result: a :obj:`~gi.repository.Gio.AsyncResult` provided to callback .. method:: refilter(context: ~gi.repository.GtkSource.CompletionContext, model: ~gi.repository.Gio.ListModel) -> None This function can be used to filter results previously provided to the :obj:`~gi.repository.GtkSource.CompletionContext` by the :obj:`~gi.repository.GtkSource.CompletionProvider`. This can happen as the user types additional text onto the word so that previously matched items may be removed from the list instead of generating new :obj:`~gi.repository.Gio.ListModel` of results. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param model: a :obj:`~gi.repository.Gio.ListModel` Virtual Methods --------------- .. rst-class:: interim-class .. class:: CompletionProvider :no-index: .. method:: do_activate(context: ~gi.repository.GtkSource.CompletionContext, proposal: ~gi.repository.GtkSource.CompletionProposal) -> None This function requests ``proposal`` to be activated by the :obj:`~gi.repository.GtkSource.CompletionProvider`. What the provider does to activate the proposal is specific to that provider. Many providers may choose to insert a :obj:`~gi.repository.GtkSource.Snippet` with edit points the user may cycle through. See also: :obj:`~gi.repository.GtkSource.Snippet`, :obj:`~gi.repository.GtkSource.SnippetChunk`, :obj:`~gi.repository.View.push_snippet` :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param proposal: a :obj:`~gi.repository.GtkSource.CompletionProposal` .. method:: do_display(context: ~gi.repository.GtkSource.CompletionContext, proposal: ~gi.repository.GtkSource.CompletionProposal, cell: ~gi.repository.GtkSource.CompletionCell) -> None This function requests that the :obj:`~gi.repository.GtkSource.CompletionProvider` prepares ``cell`` to display the contents of ``proposal``. Based on ``cells`` column type, you may want to display different information. This allows for columns of information among completion proposals resulting in better alignment of similar content (icons, return types, method names, and parameter lists). :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param proposal: a :obj:`~gi.repository.GtkSource.CompletionProposal` :param cell: a :obj:`~gi.repository.GtkSource.CompletionCell` .. method:: do_get_priority(context: ~gi.repository.GtkSource.CompletionContext) -> int This function should return the priority of ``self`` in ``context``. The priority is used to sort groups of completion proposals by provider so that higher priority providers results are shown above lower priority providers. Higher value indicates higher priority. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` .. method:: do_get_title() -> str | None Gets the title of the completion provider, if any. Currently, titles are not displayed in the completion results, but may be at some point in the future when non-:const:`None`. .. method:: do_is_trigger(iter: ~gi.repository.Gtk.TextIter, ch: str) -> bool This function is used to determine if a character inserted into the text editor should cause a new completion request to be triggered. An example would be period '.' which might indicate that the user wants to complete method or field names of an object. This method will only trigger when text is inserted into the :obj:`~gi.repository.Gtk.TextBuffer` while the completion list is visible and a proposal is selected. Incremental key-presses (like shift, control, or alt) are not triggerable. :param iter: a :obj:`~gi.repository.Gtk.TextIter` :param ch: a :obj:`~gi.repository.gunichar` of the character inserted .. method:: do_key_activates(context: ~gi.repository.GtkSource.CompletionContext, proposal: ~gi.repository.GtkSource.CompletionProposal, keyval: int, state: ~gi.repository.Gdk.ModifierType) -> bool This function is used to determine if a key typed by the user should activate ``proposal`` (resulting in committing the text to the editor). This is useful when using languages where convention may lead to less typing by the user. One example may be the use of "." or "-" to expand a field access in the C programming language. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param proposal: a :obj:`~gi.repository.GtkSource.CompletionProposal` :param keyval: a keyval such as :obj:`~gi.repository.Gdk.KEY_period` :param state: a :obj:`~gi.repository.Gdk.ModifierType` or 0 .. method:: do_list_alternates(context: ~gi.repository.GtkSource.CompletionContext, proposal: ~gi.repository.GtkSource.CompletionProposal) -> list[~gi.repository.GtkSource.CompletionProposal] | None Providers should return a list of alternates to ``proposal`` or :const:`None` if there are no alternates available. This can be used by the completion view to allow the user to move laterally through similar proposals, such as overrides of methods by the same name. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param proposal: a :obj:`~gi.repository.GtkSource.CompletionProposal` .. method:: do_populate_async(context: ~gi.repository.GtkSource.CompletionContext, cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[...], None] | None = None, *user_data: ~typing.Any) -> None Asynchronously requests that the provider populates the completion results for ``context``. For providers that would like to populate a :obj:`~gi.repository.Gio.ListModel` while those results are displayed to the user, :obj:`~gi.repository.CompletionContext.set_proposals_for_provider` may be used to reduce latency until the user sees results. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` or :const:`None` :param callback: a callback to execute upon completion :param user_data: closure data for ``callback`` .. method:: do_populate_finish(result: ~gi.repository.Gio.AsyncResult) -> ~gi.repository.Gio.ListModel Completes an asynchronous operation to populate a completion provider. :param result: a :obj:`~gi.repository.Gio.AsyncResult` provided to callback .. method:: do_refilter(context: ~gi.repository.GtkSource.CompletionContext, model: ~gi.repository.Gio.ListModel) -> None This function can be used to filter results previously provided to the :obj:`~gi.repository.GtkSource.CompletionContext` by the :obj:`~gi.repository.GtkSource.CompletionProvider`. This can happen as the user types additional text onto the word so that previously matched items may be removed from the list instead of generating new :obj:`~gi.repository.Gio.ListModel` of results. :param context: a :obj:`~gi.repository.GtkSource.CompletionContext` :param model: a :obj:`~gi.repository.Gio.ListModel`