Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/completion_dart.dart

Issue 1471173003: hook new DartCompletionContributor API into existing framework (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analysis_server.src.services.completion.completion_dart;
6
7 import 'dart:async';
8
9 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
10 show CompletionRequest;
11 import 'package:analysis_server/src/provisional/completion/completion_dart.dart' ;
12 import 'package:analysis_server/src/provisional/completion/dart/completion_targe t.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;
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';
22
23 /**
24 * The information about a requested list of completions within a Dart file.
25 */
26 class DartCompletionRequestImpl extends CompletionRequestImpl
27 implements DartCompletionRequest {
28 /**
29 * The cached completion target or `null` if not computed yet.
30 */
31 CompletionTarget _target;
32
33 /**
34 * `true` if [resolveDeclarationsInScope] has partially resolved the unit
35 * referenced by [target], else `false`.
36 */
37 bool _haveResolveDeclarationsInScope = false;
38
39 /**
40 * Initialize a newly created completion request based on the given request.
41 */
42 factory DartCompletionRequestImpl.forRequest(CompletionRequest request) {
43 return new DartCompletionRequestImpl._(request.context,
44 request.resourceProvider, request.source, request.offset);
45 }
46
47 DartCompletionRequestImpl._(AnalysisContext context,
48 ResourceProvider resourceProvider, Source source, int offset)
49 : super(context, resourceProvider, source, offset);
50
51 @override
52 Future<CompilationUnit> resolveDeclarationsInScope() async {
53 CompilationUnit unit = target.unit;
54 if (_haveResolveDeclarationsInScope) {
55 return unit;
56 }
57
58 // Determine the library source
59 Source librarySource;
60 if (unit.directives.any((d) => d is PartOfDirective)) {
61 List<Source> libraries = context.getLibrariesContaining(source);
62 if (libraries.isEmpty) {
63 return null;
64 }
65 librarySource = libraries[0];
66 } else {
67 librarySource = source;
68 }
69
70 // Resolve declarations in the target unit
71 CompilationUnit resolvedUnit =
72 await new AnalysisFutureHelper<CompilationUnit>(
73 context,
74 new LibrarySpecificUnit(librarySource, source),
75 RESOLVED_UNIT3).computeAsync();
76
77 // TODO(danrubel) determine if the underlying source has been modified
78 // in a way that invalidates the completion request
79 // and return null
80
81 // Gracefully degrade if unit cannot be resolved
82 if (resolvedUnit == null) {
83 return null;
84 }
85
86 // Recompute the target for the newly resolved unit
87 _target = new CompletionTarget.forOffset(resolvedUnit, offset);
88 _haveResolveDeclarationsInScope = true;
89 return resolvedUnit;
90 }
91
92 @override
93 CompletionTarget get target {
94 if (_target == null) {
95 CompilationUnit unit = context.computeResult(source, PARSED_UNIT);
96 _target = new CompletionTarget.forOffset(unit, offset);
97 }
98 return _target;
99 }
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698