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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 implement the method `computeSuggestions`. Your contributor should invoke the | 51 implement the method `computeSuggestions`. Your contributor should invoke the |
52 method `checkAborted`, defined on the `CompletionRequest` object, before | 52 method `checkAborted`, defined on the `CompletionRequest` object, before |
53 starting any slow work. This allows the computation of completion suggestions | 53 starting any slow work. This allows the computation of completion suggestions |
54 to be preempted if the client no longer needs the results. | 54 to be preempted if the client no longer needs the results. |
55 | 55 |
56 For example, your contributor might look something like the following: | 56 For example, your contributor might look something like the following: |
57 | 57 |
58 ```dart | 58 ```dart |
59 class MyCompletionContributor implements CompletionContributor { | 59 class MyCompletionContributor implements CompletionContributor { |
60 @override | 60 @override |
61 Future<Null> computeSuggestions(covariant DartCompletionRequest request, | 61 Future<Null> computeSuggestions(DartCompletionRequest request, |
62 CompletionCollector collector) async { | 62 CompletionCollector collector) async { |
63 // ... | 63 // ... |
64 } | 64 } |
65 } | 65 } |
66 ``` | 66 ``` |
67 | 67 |
68 Given a contributor like the one above, you can implement your plugin similar to | 68 Given a contributor like the one above, you can implement your plugin similar to |
69 the following: | 69 the following: |
70 | 70 |
71 ```dart | 71 ```dart |
72 class MyPlugin extends ServerPlugin with CompletionMixin, DartCompletionMixin { | 72 class MyPlugin extends ServerPlugin with CompletionMixin, DartCompletionMixin { |
73 // ... | 73 // ... |
74 | 74 |
75 @override | 75 @override |
76 List<CompletionContributor> getCompletionContributors( | 76 List<CompletionContributor> getCompletionContributors( |
77 covariant AnalysisDriverGeneric driver) { | 77 AnalysisDriverGeneric driver) { |
78 return <CompletionContributor>[new MyCompletionContributor()]; | 78 return <CompletionContributor>[new MyCompletionContributor()]; |
79 } | 79 } |
80 } | 80 } |
81 ``` | 81 ``` |
OLD | NEW |