code_completion.md: review

This commit is contained in:
Yann Cébron 2019-11-28 16:02:51 +01:00
parent e42819628f
commit 7f8332d6a7

View File

@ -16,7 +16,7 @@ This method needs to return an array of objects containing either strings,
[PsiElement](upsource:///platform/core-api/src/com/intellij/psi/PsiElement.java)
instances or instances of the
[LookupElement](upsource:///platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java)
class.
class (see [Lookup Items](#lookup-items) below).
If a
[PsiElement](upsource:///platform/core-api/src/com/intellij/psi/PsiElement.java)
instance is returned in the array, the completion list shows the icon for the element.
@ -32,30 +32,37 @@ which collects all declarations passed to its `processDeclarations()` method and
Implementing the
[CompletionContributor](upsource:///platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java)
interface gives you the greatest control over the operation of code completion for your language.
Note that the JavaDoc of that class contains a detailed FAQ for implementing code completion.
> **NOTE** Note that the JavaDoc of that class contains a detailed FAQ for implementing code completion.
The core scenario of using
[CompletionContributor](upsource:///platform/lang-api/src/com/intellij/codeInsight/completion/CompletionContributor.java)
consists of calling the `extend()` method and passing in the *pattern* specifying the context in which this completion variant is applicable, as well as a *completion provider* which generates the items to show in the completion list.
**Example**:
[CompletionContributor](https://github.com/JetBrains/intellij-plugins/blob/master/osmorc/src/org/osmorc/manifest/completion/OsgiManifestCompletionContributor.java)
for completing keywords in MANIFEST.MF files.
Keep in mind that the pattern is checked against the leaf PSI element. If you
want to match a composite element, use `withParent` or `withSuperParent`
methods.
**Examples**:
- [CompletionContributor](https://github.com/JetBrains/intellij-plugins/blob/master/osmorc/src/org/osmorc/manifest/completion/OsgiManifestCompletionContributor.java)
for completing keywords in MANIFEST.MF files.
- [Custom Language Support Tutorial: Completion Contributor](/tutorials/custom_language_support/completion_contributor.md)
#### Lookup Items
Items shown in the completion list are represented by instances of the
[LookupElement](upsource:///platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java)
interface.
These instances are normally created through the
[LookupElementBuilder](upsource:///platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementBuilder.java)
class.
For every lookup element, you can specify the following attributes:
* Text, tail text and type text. Tail text is shown next to the main item text, is not used for prefix matching, and can be used, for example, to show the parameter list of the method. Type text is shown right-aligned in the lookup list and can be used to show the return type or containing class of a method, for example.
* Text. Shown left-aligned.
* Tail text. Shown next to the main item text, is not used for prefix matching, and can be used, for example, to show the parameter list of the method.
* Type text. Shown right-aligned in the lookup list and can be used to show the return type or containing class of a method, for example.
* Icon
* Text attributes (bold, strikeout etc.)
* Text attributes. Bold, Strikeout, etc.
* Insert handler. The insert handler is a callback which is called when the item is selected, and can be used to perform additional modifications of the text (for example, to put in the parentheses for a method call)