The Code Completion module is located under
/cvs/editor/completion directory. It provides the
with a simple API for showing and hiding of the completion
and with SPI defining the completion providers that is located
and the implementation located in
CompositeCompletionItem interface was added to allow for
completion items containing possible sub-items.
void CompletionResultSet.setHasAdditionalItemsText(String text) was added
to allow for customization of the text displayed in a completion popup whenever
a CompletionProvider indicates that additional items could be added to the result set.
void CompletionResultSet.setHasAdditionalItems(boolean value) was added
to indicate that some items could exist that will likely need a long time to be computed
and added to the result set. It is preferred to add them on the special 'all' code
completion invocation only.
void CompletionResultSet.setWaitText(String waitText) was added
to allow customization of the text in the label displayed
if the completion query results are not computed in certain timeout.
CharSequence CompletionItem.getInsertPrefix() was added.
CompletionTask.refresh(CompletionResultSet resultSet) now allows
void AsyncCompletionQuery.preQueryUpdate(JTextComponent component)
was added to reflect that in AsyncCompletionTask.
The API is small and it only allows to explicitly show or hide the completion window.
It's being used by code templates that need to explicitly show the code completion window when tabbing to a particular parameter.
There may be certain actions that want to ensure that the code completion is hidden at the time when they are invoked. For example the actions pasting the content of the completion item into the document.
Completion infrastructure needs to obtain the results that are then displayed
in the completion window.
There are three types of displayed results related to the current caret offset:
For the purpose of obtaining these completion results
There may be an arbitrary number of independent completion providers for a single completion popup window.
The completion providers are registered through the xml layer into Editors/<mime-type>/CompletionProviders. Once the document with the particular mime-type gets loaded the corresponding completion providers will get instantiated and used.
The code completion's infrastructure invokes the requests for the completion results in the AWT thread.
Therefore all the methods of the completion providers are invoked in AWT thread but they may reschedule their processing into other threads.
The completion provider creates a task that computes the resulting
data that will then be displayed by the code completion infrastructure.
The task creation and computation are called synchronously from the AWT event dispatch thread.
However there can be potentially long-running tasks (e.g. working with MDR) that are not desirable to be run in AWT thread.
Therefore the completion infrastructure provides a listener to which the completion task notifies the results.
The support class AsyncCompletionTask allows to post the task computation into
The completion task computes a collection of completion items
which are then collected by the completion infrastructure and displayed.
Displaying. Each completion item must be able to display itself in a
Sorting. The completion items may come from different completion providers and they must be sorted before displaying. The sort order should not only be alphabetical but it should also allow a prioritization of the items according to their importance in the given context.
Actions. The interaction of the user with the completion item is done by interacting with item's input map and action map.
Documentation. The item may want to display additional detailed information in a documentation popup window.
Read more about the implementation in the answers to architecture questions.