Search for usage in LXR

KTextEditor::CodeCompletionInterface Class Referenceabstract

#include <KTextEditor/CodeCompletionInterface>

Inheritance diagram for KTextEditor::CodeCompletionInterface:

Public Member Functions

virtual void abortCompletion ()=0
virtual void forceCompletion ()=0
virtual bool isAutomaticInvocationEnabled () const =0
virtual bool isCompletionActive () const =0
virtual void registerCompletionModel (CodeCompletionModel *model)=0
virtual void setAutomaticInvocationEnabled (bool enabled=true)=0
virtual void startCompletion (const Range &word, CodeCompletionModel *model)=0
virtual void unregisterCompletionModel (CodeCompletionModel *model)=0

Detailed Description

Code completion extension interface for the View.


The CodeCompletionInterface is designed to provide code completion functionality for a KTextEditor::View. This interface provides the basic mechanisms to display a list of completions, update this list according to user input, and allow the user to select a completion.

Essentially, this provides an item view for the available completions. In order to use this interface, you will need to implement a CodeCompletionModel that generates the relevant completions given the current input.

Accessing the CodeCompletionInterface

The CodeCompletionInterface is an extension interface for a View, i.e. the View inherits the interface provided that the used KTextEditor library implements the interface. Use qobject_cast to access the interface:

// view is of type KTextEditor::View*
auto iface = qobject_cast<KTextEditor::CodeCompletionInterface*>(view);
if (iface) {
// the implementation supports the interface
// do stuff
} else {
// the implementation does not support the interface

Using the CodeCompletionInterface

The CodeCompletionInterface can be used in different ways, which we will call "automatic", and "manual".


In automatic mode, the CodeCompletionInterface will take care of starting and aborting the generation of code completions as appropriate, when the users inserts or changes text.

To use the interface in this way, first register a CodeCompletionModel using registerCompletionModel(). Now call setAutomaticCompletionEnabled() to enabled automatic completions.


If you need more control over when code completions get shown or not, or which fragment of the text should be considered as the basis for generated completions, proceed as follows:

Call setAutomaticCompletionEnabled(false) to disable automatic completions. To start the generation of code completions for the current word, call startCompletion(), with the appropriate parameters. To hide the generated completions, use abortCompletion().

See also
KTextEditor::View, KTextEditor::CodeCompletionModel

Definition at line 84 of file codecompletioninterface.h.

Member Function Documentation

◆ abortCompletion()

virtual void KTextEditor::CodeCompletionInterface::abortCompletion ( )
pure virtual

Abort the currently displayed code completion without executing any currently selected completion.

This is safe, even when the completion box is not currently active.

See also

◆ forceCompletion()

virtual void KTextEditor::CodeCompletionInterface::forceCompletion ( )
pure virtual

Force execution of the currently selected completion, and hide the code completion box.

◆ isAutomaticInvocationEnabled()

virtual bool KTextEditor::CodeCompletionInterface::isAutomaticInvocationEnabled ( ) const
pure virtual

Determine the status of automatic code completion invocation.

◆ isCompletionActive()

virtual bool KTextEditor::CodeCompletionInterface::isCompletionActive ( ) const
pure virtual

Query whether the code completion box is currently displayed.

◆ registerCompletionModel()

virtual void KTextEditor::CodeCompletionInterface::registerCompletionModel ( CodeCompletionModel model)
pure virtual

Register a new code completion model.

modelnew completion model
See also

◆ setAutomaticInvocationEnabled()

virtual void KTextEditor::CodeCompletionInterface::setAutomaticInvocationEnabled ( bool  enabled = true)
pure virtual

Enable or disable automatic code completion invocation.

◆ startCompletion()

virtual void KTextEditor::CodeCompletionInterface::startCompletion ( const Range word,
CodeCompletionModel model 
pure virtual

Invoke code completion over a given range, with a specific model.

◆ unregisterCompletionModel()

virtual void KTextEditor::CodeCompletionInterface::unregisterCompletionModel ( CodeCompletionModel model)
pure virtual

Unregister a code completion model.

modelthe model that should be unregistered
See also

The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Mar 27 2023 04:03:56 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.