Completion

class Completion(**properties: Any)

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

block_interactive() None
fuzzy_highlight(haystack: str, casefold_query: str) AttrList | None

This will add <b> tags around matched characters in haystack based on casefold_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_buffer() Buffer

Gets the connected View’s Buffer

get_page_size() int
get_view() View

Gets the View that owns the Completion.

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 with add_provider.

Parameters:

provider – a CompletionProvider

set_page_size(page_size: int) None
Parameters:

page_size

show() None

Emits the “show” signal.

When the “show” signal is emitted, the completion window will be displayed if there are any results available.

unblock_interactive() None

Properties

class Completion
props.buffer: TextView

The TextBuffer for the Completion:view. This is a convenience property for providers.

props.page_size: int

The number of rows to display to the user before scrolling.

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 this Completion is providing completion features.

Signals

class Completion.signals
hide() None

The “hide” signal is emitted when the completion window should be hidden.

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

show() None

The “show” signal is emitted when the completion window should be shown.