OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analysis_server.src.services.completion.completion_dart; | 5 library analysis_server.src.services.completion.completion_dart; |
6 | 6 |
7 import 'package:analysis_server/src/provisional/completion/completion_core.dart' ; | 7 import 'dart:async'; |
8 | |
9 import 'package:analysis_server/src/provisional/completion/completion_core.dart' | |
10 show CompletionRequest; | |
8 import 'package:analysis_server/src/provisional/completion/completion_dart.dart' ; | 11 import 'package:analysis_server/src/provisional/completion/completion_dart.dart' ; |
9 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; | 12 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.dart'; |
10 import 'package:analysis_server/src/services/completion/completion_core.dart'; | 13 import 'package:analysis_server/src/services/completion/completion_core.dart'; |
14 import 'package:analyzer/file_system/file_system.dart'; | |
15 import 'package:analyzer/src/context/context.dart' | |
16 show AnalysisFutureHelper, AnalysisContextImpl; | |
11 import 'package:analyzer/src/generated/ast.dart'; | 17 import 'package:analyzer/src/generated/ast.dart'; |
18 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; | |
19 import 'package:analyzer/src/generated/source.dart'; | |
20 import 'package:analyzer/src/task/dart.dart'; | |
21 import 'package:analyzer/task/dart.dart'; | |
12 | 22 |
13 /** | 23 /** |
14 * The information about a requested list of completions within a Dart file. | 24 * The information about a requested list of completions within a Dart file. |
15 */ | 25 */ |
16 class DartCompletionRequestImpl extends CompletionRequestImpl | 26 class DartCompletionRequestImpl extends CompletionRequestImpl |
17 implements DartCompletionRequest { | 27 implements DartCompletionRequest { |
18 /** | 28 /** |
19 * The compilation unit in which the completion was requested. | 29 * The cached completion target or `null` if not computed yet. |
20 */ | 30 */ |
21 final CompilationUnit unit; | 31 CompletionTarget _target; |
22 | 32 |
23 /** | 33 /** |
24 * A flag indicating whether the compilation [unit] is resolved. | 34 * `true` if [resolveDeclarationsInScope] has partially resolved the unit |
35 * referenced by [target], else `false`. | |
25 */ | 36 */ |
26 final bool isResolved; | 37 bool _haveResolveDeclarationsInScope = false; |
27 | 38 |
28 /** | 39 /** |
29 * The completion target. This determines what part of the parse tree | 40 * Initialize a newly created completion request based on the given request. |
30 * will receive the newly inserted text. | |
31 */ | 41 */ |
32 final CompletionTarget target; | 42 factory DartCompletionRequestImpl.forRequest(CompletionRequest request) { |
43 return new DartCompletionRequestImpl(request.context, | |
44 request.resourceProvider, request.source, request.offset); | |
45 } | |
33 | 46 |
34 /** | 47 /** |
35 * Initialize a newly created completion request based on the given arguments. | 48 * Initialize a newly created completion request based on the given arguments. |
36 */ | 49 */ |
37 DartCompletionRequestImpl( | 50 DartCompletionRequestImpl(AnalysisContext context, |
38 CompletionRequest request, this.unit, this.isResolved, this.target) | 51 ResourceProvider resourceProvider, Source source, int offset) |
39 : super(request.context, request.resourceProvider, request.source, | 52 : super(context, resourceProvider, source, offset); |
scheglov
2015/11/22 05:19:02
It may be worth to drop this constructor.
It dupli
danrubel
2015/11/23 17:47:32
Its easier for the tests to use this constructor,
| |
40 request.offset); | 53 |
54 @override | |
55 Future<CompilationUnit> resolveDeclarationsInScope() async { | |
56 CompilationUnit unit = target.unit; | |
57 if (_haveResolveDeclarationsInScope) { | |
58 return unit; | |
59 } | |
60 | |
61 // Determine the library source | |
62 Source librarySource; | |
63 if (unit.directives.any((d) => d is PartOfDirective)) { | |
64 List<Source> libraries = context.getLibrariesContaining(source); | |
65 if (libraries.isEmpty) { | |
66 return null; | |
67 } | |
68 librarySource = libraries[0]; | |
69 } else { | |
70 librarySource = source; | |
71 } | |
72 | |
73 // Resolve declarations in the target unit | |
74 var resolvedUnit = await new AnalysisFutureHelper<CompilationUnit>( | |
scheglov
2015/11/22 05:19:02
Please add the type.
danrubel
2015/11/23 17:47:32
Done.
| |
75 (context as AnalysisContextImpl), | |
scheglov
2015/11/22 05:19:02
Drop parenthesis.
Actually I think we don't need e
danrubel
2015/11/23 17:47:32
Done.
| |
76 new LibrarySpecificUnit(librarySource, source), | |
77 RESOLVED_UNIT3).computeAsync(); | |
scheglov
2015/11/22 05:19:02
Now, when we have a single implementation of Analy
Brian Wilkerson
2015/11/22 18:02:46
We effectively only have one implementation now, a
danrubel
2015/11/23 17:47:32
Its not clear to me if I need to change anything h
| |
78 | |
79 // TODO(danrubel) determine if the underlying source has been modified | |
80 // in a way that invalidates the completion request | |
81 // and return null | |
82 | |
83 // Gracefully degrade if unit cannot be resolved | |
84 if (resolvedUnit == null) { | |
85 return null; | |
86 } | |
87 | |
88 // Recompute the target for the newly resolved unit | |
89 _target = new CompletionTarget.forOffset(resolvedUnit, offset); | |
90 _haveResolveDeclarationsInScope = true; | |
91 return resolvedUnit; | |
92 } | |
93 | |
94 @override | |
95 CompletionTarget get target { | |
96 if (_target == null) { | |
97 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); | |
98 _target = new CompletionTarget.forOffset(unit, offset); | |
99 } | |
100 return _target; | |
101 } | |
41 } | 102 } |
OLD | NEW |