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
proposalto be activated by theCompletionProvider.What the provider does to activate the proposal is specific to that provider. Many providers may choose to insert a
Snippetwith edit points the user may cycle through.See also:
Snippet,SnippetChunk,push_snippet- Parameters:
context – a
CompletionContextproposal – a
CompletionProposal
- display(context: CompletionContext, proposal: CompletionProposal, cell: CompletionCell) None#
This function requests that the
CompletionProviderpreparescellto display the contents ofproposal.Based on
cellscolumn 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
CompletionContextproposal – a
CompletionProposalcell – a
CompletionCell
- get_priority(context: CompletionContext) int#
This function should return the priority of
selfincontext.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
TextBufferwhile the completion list is visible and a proposal is selected. Incremental key-presses (like shift, control, or alt) are not triggerable.- Parameters:
iter – a
TextIterch – a
gunicharof 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
CompletionContextproposal – a
CompletionProposalkeyval – a keyval such as
KEY_periodstate – a
ModifierTypeor 0
- list_alternates(context: CompletionContext, proposal: CompletionProposal) list[CompletionProposal] | None#
Providers should return a list of alternates to
proposalorNoneif 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
CompletionContextproposal – a
CompletionProposal
- async populate_async(self, context: CompletionContext) ListModel#
This is the awaitable version of
populate_async().- Parameters:
context – a
CompletionContext
- 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
ListModelwhile those results are displayed to the user,set_proposals_for_providermay be used to reduce latency until the user sees results.- Parameters:
context – a
CompletionContextcancellable – a
CancellableorNonecallback – 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
AsyncResultprovided to callback
- refilter(context: CompletionContext, model: ListModel) None#
This function can be used to filter results previously provided to the
CompletionContextby 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
ListModelof results.- Parameters:
context – a
CompletionContextmodel – a
ListModel
Virtual Methods#
- class CompletionProvider
- do_activate(context: CompletionContext, proposal: CompletionProposal) None#
This function requests
proposalto be activated by theCompletionProvider.What the provider does to activate the proposal is specific to that provider. Many providers may choose to insert a
Snippetwith edit points the user may cycle through.See also:
Snippet,SnippetChunk,push_snippet- Parameters:
context – a
CompletionContextproposal – a
CompletionProposal
- do_display(context: CompletionContext, proposal: CompletionProposal, cell: CompletionCell) None#
This function requests that the
CompletionProviderpreparescellto display the contents ofproposal.Based on
cellscolumn 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
CompletionContextproposal – a
CompletionProposalcell – a
CompletionCell
- do_get_priority(context: CompletionContext) int#
This function should return the priority of
selfincontext.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
TextBufferwhile the completion list is visible and a proposal is selected. Incremental key-presses (like shift, control, or alt) are not triggerable.- Parameters:
iter – a
TextIterch – a
gunicharof 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
CompletionContextproposal – a
CompletionProposalkeyval – a keyval such as
KEY_periodstate – a
ModifierTypeor 0
- do_list_alternates(context: CompletionContext, proposal: CompletionProposal) list[CompletionProposal] | None#
Providers should return a list of alternates to
proposalorNoneif 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
CompletionContextproposal – 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
ListModelwhile those results are displayed to the user,set_proposals_for_providermay be used to reduce latency until the user sees results.- Parameters:
context – a
CompletionContextcancellable – a
CancellableorNonecallback – 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
AsyncResultprovided to callback
- do_refilter(context: CompletionContext, model: ListModel) None#
This function can be used to filter results previously provided to the
CompletionContextby 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
ListModelof results.- Parameters:
context – a
CompletionContextmodel – a
ListModel