OLD | NEW |
1 # Providing Code Completions | 1 # Providing Code Completions |
2 | 2 |
3 A code completion is used by clients to provide a set of possible completions to | 3 A code completion is used by clients to provide a set of possible completions to |
4 partially entered code. Completions are intended to address two use cases: to | 4 partially entered code. Completions are intended to address two use cases: to |
5 help users enter code with less effort and to help users discover the behavior | 5 help users enter code with less effort and to help users discover the behavior |
6 of an object. | 6 of an object. |
7 | 7 |
8 For example, if the user has typed `o.toSt` and then requested completions, one | 8 For example, if the user has typed `o.toSt` and then requested completions, one |
9 suggestion might be `toString`. | 9 suggestion might be `toString`. |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 responsible for returning a list of `CompletionContributor`s. It is the | 38 responsible for returning a list of `CompletionContributor`s. It is the |
39 completion contributors that produce the actual completion suggestions. (Most | 39 completion contributors that produce the actual completion suggestions. (Most |
40 plugins will only need a single completion contributor.) | 40 plugins will only need a single completion contributor.) |
41 | 41 |
42 To write a completion contributor, create a class that implements | 42 To write a completion contributor, create a class that implements |
43 `CompletionContributor`. The interface defines a single method named | 43 `CompletionContributor`. The interface defines a single method named |
44 `computeSuggestions`. The method has two arguments: a `CompletionRequest` that | 44 `computeSuggestions`. The method has two arguments: a `CompletionRequest` that |
45 describes the where completions are being requested and a `CompletionCollector` | 45 describes the where completions are being requested and a `CompletionCollector` |
46 through which suggestions are to be added. | 46 through which suggestions are to be added. |
47 | 47 |
| 48 If you mix in the class `DartCompletionMixin`, then the request will be an |
| 49 instance of `DartCompletionRequest`, which also has analysis results. |
| 50 |
48 ## Example | 51 ## Example |
49 | 52 |
50 Start by creating a class that implements `CompletionContributor`, then | 53 Start by creating a class that implements `CompletionContributor`, then |
51 implement the method `computeSuggestions`. Your contributor should invoke the | 54 implement the method `computeSuggestions`. Your contributor should invoke the |
52 method `checkAborted`, defined on the `CompletionRequest` object, before | 55 method `checkAborted`, defined on the `CompletionRequest` object, before |
53 starting any slow work. This allows the computation of completion suggestions | 56 starting any slow work. This allows the computation of completion suggestions |
54 to be preempted if the client no longer needs the results. | 57 to be preempted if the client no longer needs the results. |
55 | 58 |
56 For example, your contributor might look something like the following: | 59 For example, your contributor might look something like the following: |
57 | 60 |
(...skipping 14 matching lines...) Expand all Loading... |
72 class MyPlugin extends ServerPlugin with CompletionMixin, DartCompletionMixin { | 75 class MyPlugin extends ServerPlugin with CompletionMixin, DartCompletionMixin { |
73 // ... | 76 // ... |
74 | 77 |
75 @override | 78 @override |
76 List<CompletionContributor> getCompletionContributors( | 79 List<CompletionContributor> getCompletionContributors( |
77 AnalysisDriverGeneric driver) { | 80 AnalysisDriverGeneric driver) { |
78 return <CompletionContributor>[new MyCompletionContributor()]; | 81 return <CompletionContributor>[new MyCompletionContributor()]; |
79 } | 82 } |
80 } | 83 } |
81 ``` | 84 ``` |
OLD | NEW |