CompletionProvider#
- class CompletionProvider(*args, **kwargs)#
Implementations: CompletionSnippets
, CompletionWords
Completion provider interface.
You must implement this interface to provide proposals to Completion
.
In most cases, implementations of this interface will want to use
populate_async
to asynchronously populate the results
to avoid blocking the main loop.
Methods#
- class CompletionProvider
- activate(context: CompletionContext, proposal: CompletionProposal) None #
This function requests
proposal
to be activated by theCompletionProvider
.What the provider does to activate the proposal is specific to that provider. Many providers may choose to insert a
Snippet
with edit points the user may cycle through.See also:
Snippet
,SnippetChunk
,push_snippet
- Parameters:
context – a
CompletionContext
proposal – a
CompletionProposal
- display(context: CompletionContext, proposal: CompletionProposal, cell: CompletionCell) None #
This function requests that the
CompletionProvider
preparescell
to display the contents ofproposal
.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).
- Parameters:
context – a
CompletionContext
proposal – a
CompletionProposal
cell – a
CompletionCell
- get_priority(context: CompletionContext) int #
This function should return the priority of
self
incontext
.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.
- Parameters:
context – a
CompletionContext
- 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-
None
.
- is_trigger(iter: 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
TextBuffer
while the completion list is visible and a proposal is selected. Incremental key-presses (like shift, control, or alt) are not triggerable.- Parameters:
iter – a
TextIter
ch – a
gunichar
of the character inserted
- key_activates(context: CompletionContext, proposal: CompletionProposal, keyval: int, state: 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.
- Parameters:
context – a
CompletionContext
proposal – a
CompletionProposal
keyval – a keyval such as
KEY_period
state – a
ModifierType
or 0
- list_alternates(context: CompletionContext, proposal: CompletionProposal) list[CompletionProposal] | None #
Providers should return a list of alternates to
proposal
orNone
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.
- Parameters:
context – a
CompletionContext
proposal – a
CompletionProposal
- populate_async(context: CompletionContext, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously requests that the provider populates the completion results for
context
.For providers that would like to populate a
ListModel
while those results are displayed to the user,set_proposals_for_provider
may be used to reduce latency until the user sees results.- Parameters:
context – a
CompletionContext
cancellable – a
Cancellable
orNone
callback – a callback to execute upon completion
user_data – closure data for
callback
- populate_finish(result: AsyncResult) ListModel #
Completes an asynchronous operation to populate a completion provider.
- Parameters:
result – a
AsyncResult
provided to callback
- refilter(context: CompletionContext, model: ListModel) None #
This function can be used to filter results previously provided to the
CompletionContext
by theCompletionProvider
.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
ListModel
of results.- Parameters:
context – a
CompletionContext
model – a
ListModel
Virtual Methods#
- class CompletionProvider
- do_activate(context: CompletionContext, proposal: CompletionProposal) None #
This function requests
proposal
to be activated by theCompletionProvider
.What the provider does to activate the proposal is specific to that provider. Many providers may choose to insert a
Snippet
with edit points the user may cycle through.See also:
Snippet
,SnippetChunk
,push_snippet
- Parameters:
context – a
CompletionContext
proposal – a
CompletionProposal
- do_display(context: CompletionContext, proposal: CompletionProposal, cell: CompletionCell) None #
This function requests that the
CompletionProvider
preparescell
to display the contents ofproposal
.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).
- Parameters:
context – a
CompletionContext
proposal – a
CompletionProposal
cell – a
CompletionCell
- do_get_priority(context: CompletionContext) int #
This function should return the priority of
self
incontext
.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.
- Parameters:
context – a
CompletionContext
- 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-
None
.
- do_is_trigger(iter: 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
TextBuffer
while the completion list is visible and a proposal is selected. Incremental key-presses (like shift, control, or alt) are not triggerable.- Parameters:
iter – a
TextIter
ch – a
gunichar
of the character inserted
- do_key_activates(context: CompletionContext, proposal: CompletionProposal, keyval: int, state: 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.
- Parameters:
context – a
CompletionContext
proposal – a
CompletionProposal
keyval – a keyval such as
KEY_period
state – a
ModifierType
or 0
- do_list_alternates(context: CompletionContext, proposal: CompletionProposal) list[CompletionProposal] | None #
Providers should return a list of alternates to
proposal
orNone
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.
- Parameters:
context – a
CompletionContext
proposal – a
CompletionProposal
- do_populate_async(context: CompletionContext, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously requests that the provider populates the completion results for
context
.For providers that would like to populate a
ListModel
while those results are displayed to the user,set_proposals_for_provider
may be used to reduce latency until the user sees results.- Parameters:
context – a
CompletionContext
cancellable – a
Cancellable
orNone
callback – a callback to execute upon completion
user_data – closure data for
callback
- do_populate_finish(result: AsyncResult) ListModel #
Completes an asynchronous operation to populate a completion provider.
- Parameters:
result – a
AsyncResult
provided to callback
- do_refilter(context: CompletionContext, model: ListModel) None #
This function can be used to filter results previously provided to the
CompletionContext
by theCompletionProvider
.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
ListModel
of results.- Parameters:
context – a
CompletionContext
model – a
ListModel