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

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

Issue 617153004: narrow imported element suggestions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix failing test Created 6 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 services.completion.computer.dart.toplevel; 5 library services.completion.computer.dart.toplevel;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart' as protocol show Element, Ele mentKind; 9 import 'package:analysis_server/src/protocol.dart' as protocol show Element,
10 ElementKind;
10 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind; 11 import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind;
11 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 12 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
12 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' ; 13 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' ;
13 import 'package:analysis_server/src/services/search/search_engine.dart'; 14 import 'package:analysis_server/src/services/search/search_engine.dart';
14 import 'package:analyzer/src/generated/ast.dart'; 15 import 'package:analyzer/src/generated/ast.dart';
15 import 'package:analyzer/src/generated/element.dart'; 16 import 'package:analyzer/src/generated/element.dart';
16 17
17 /** 18 /**
18 * A computer for calculating imported class and top level variable 19 * A computer for calculating imported class and top level variable
19 * `completion.getSuggestions` request results. 20 * `completion.getSuggestions` request results.
(...skipping 18 matching lines...) Expand all
38 /** 39 /**
39 * A visitor for determining which imported class and top level variable 40 * A visitor for determining which imported class and top level variable
40 * should be suggested and building those suggestions. 41 * should be suggested and building those suggestions.
41 */ 42 */
42 class _ImportedVisitor extends GeneralizingAstVisitor<Future<bool>> { 43 class _ImportedVisitor extends GeneralizingAstVisitor<Future<bool>> {
43 final DartCompletionRequest request; 44 final DartCompletionRequest request;
44 45
45 _ImportedVisitor(this.request); 46 _ImportedVisitor(this.request);
46 47
47 @override 48 @override
48 Future<bool> visitCombinator(Combinator node) { 49 Future<bool> visitBlock(Block node) {
49 NamespaceDirective directive = 50 return _addImportedElementSuggestions();
50 node.getAncestor((parent) => parent is NamespaceDirective); 51 }
51 if (directive != null) { 52
53 @override
54 Future<bool> visitNode(AstNode node) {
55 return new Future.value(false);
56 }
57
58 @override
59 Future<bool> visitSimpleIdentifier(SimpleIdentifier node) {
60 AstNode parent = node.parent;
61 if (parent is Combinator) {
62 return _addCombinatorSuggestions(parent);
63 }
64 if (parent is ExpressionStatement) {
65 return _addImportedElementSuggestions();
66 }
67 return new Future.value(false);
68 }
69
70 Future _addCombinatorSuggestions(Combinator node) {
71 var directive = node.getAncestor((parent) => parent is NamespaceDirective);
72 if (directive is NamespaceDirective) {
52 LibraryElement library = directive.uriElement; 73 LibraryElement library = directive.uriElement;
53 LibraryElementSuggestionBuilder.suggestionsFor(request, library); 74 LibraryElementSuggestionBuilder.suggestionsFor(request, library);
54 return new Future.value(true); 75 return new Future.value(true);
55 } 76 }
56 return new Future.value(false); 77 return new Future.value(false);
57 } 78 }
58 79
59 @override 80 Future<bool> _addImportedElementSuggestions() {
60 Future<bool> visitExpressionStatement(ExpressionStatement node) {
61 Expression expression = node.expression;
62 if (expression is SimpleIdentifier) {
63 if (expression.end < request.offset) {
64 // Don't suggest imported elements for local var name
65 return new Future.value(false);
66 }
67 }
68 return visitNode(node);
69 }
70
71 @override
72 Future<bool> visitNode(AstNode node) {
73 return _addImportedElements();
74 }
75
76 @override
77 Future<bool> visitSimpleIdentifier(SimpleIdentifier node) {
78 return node.parent.accept(this);
79 }
80
81 @override
82 Future<bool> visitVariableDeclaration(VariableDeclaration node) {
83 // Do not add suggestions if editing the name in a var declaration
84 SimpleIdentifier name = node.name;
85 if (name == null ||
86 name.offset < request.offset ||
87 request.offset > name.end) {
88 return visitNode(node);
89 }
90 return new Future.value(false);
91 }
92
93 Future<bool> _addImportedElements() {
94 var future = request.searchEngine.searchTopLevelDeclarations(''); 81 var future = request.searchEngine.searchTopLevelDeclarations('');
95 return future.then((List<SearchMatch> matches) { 82 return future.then((List<SearchMatch> matches) {
96 83
97 Set<LibraryElement> visibleLibs = new Set<LibraryElement>(); 84 Set<LibraryElement> visibleLibs = new Set<LibraryElement>();
98 Set<LibraryElement> excludedLibs = new Set<LibraryElement>(); 85 Set<LibraryElement> excludedLibs = new Set<LibraryElement>();
99 86
100 Map<LibraryElement, Set<String>> showNames = 87 Map<LibraryElement, Set<String>> showNames =
101 new Map<LibraryElement, Set<String>>(); 88 new Map<LibraryElement, Set<String>>();
102 Map<LibraryElement, Set<String>> hideNames = 89 Map<LibraryElement, Set<String>> hideNames =
103 new Map<LibraryElement, Set<String>>(); 90 new Map<LibraryElement, Set<String>>();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 166
180 request.suggestions.add(suggestion); 167 request.suggestions.add(suggestion);
181 } 168 }
182 } 169 }
183 } 170 }
184 }); 171 });
185 return true; 172 return true;
186 }); 173 });
187 } 174 }
188 } 175 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698