Completion
Superclasses: Object
Main Completion Object.
The completion system helps the user when they writes some text, such as words, command names, functions, and suchlike. Proposals can be shown, to complete the text the user is writing. Each proposal can contain an additional piece of information (for example documentation), that is displayed when the “Details” button is clicked.
Proposals are created via a CompletionProvider
. There can
be for example a provider to complete words (see CompletionWords
),
another provider for the completion of
function names, etc. To add a provider, call
add_provider
.
The CompletionProposal
interface represents a proposal.
If a proposal contains extra information (see
DETAILS
), it will be
displayed in a supplemental details window, which appears when
the “Details” button is clicked.
Each View
object is associated with a Completion
instance. This instance can be obtained with
get_completion
. The View
class contains also the
show_completion
signal.
A same CompletionProvider
object can be used for several
GtkSourceCompletion
’s.
Methods
- class Completion
- add_provider(provider: CompletionProvider) None
Adds a
CompletionProvider
to the list of providers to be queried for completion results.- Parameters:
provider – a
CompletionProvider
- fuzzy_highlight(haystack: str, casefold_query: str) AttrList | None
This will add
<b>
tags around matched characters inhaystack
based oncasefold_query
.- Parameters:
haystack – the string to be highlighted
casefold_query – the typed-text used to highlight
haystack
- fuzzy_match(haystack: str | None, casefold_needle: str) tuple[bool, int]
This helper function can do a fuzzy match for you giving a haystack and casefolded needle.
Casefold your needle using
utf8_casefold
before running the query.Score will be set with the score of the match upon success. Otherwise, it will be set to zero.
- Parameters:
haystack – the string to be searched.
casefold_needle – A
utf8_casefold()
version of the needle.
- get_view() View
Gets the
View
that owns theCompletion
.
- hide() None
Emits the “hide” signal.
When the “hide” signal is emitted, the completion window will be dismissed.
- remove_provider(provider: CompletionProvider) None
Removes a
CompletionProvider
previously added withadd_provider
.- Parameters:
provider – a
CompletionProvider
Properties
- class Completion
- props.buffer: TextView
The
TextBuffer
for theCompletion
:view. This is a convenience property for providers.
- props.remember_info_visibility: bool
Determines whether the visibility of the info window should be saved when the completion is hidden, and restored when the completion is shown again.
- props.select_on_show: bool
Determines whether the first proposal should be selected when the completion is first shown.
- props.show_icons: bool
The “show-icons” property denotes if icons should be displayed within the list of completions presented to the user.
- props.view: View
The “view” property is the
TextView
for which thisCompletion
is providing completion features.
Signals
- class Completion.signals
-
- provider_added(provider: CompletionProvider) None
The “provided-added” signal is emitted when a new provider is added to the completion.
- Parameters:
provider – a
CompletionProvider
- provider_removed(provider: CompletionProvider) None
The “provided-removed” signal is emitted when a provider has been removed from the completion.
- Parameters:
provider – a
CompletionProvider