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

Side by Side Diff: pkg/analysis_services/lib/src/completion/top_level_computer.dart

Issue 440343003: incremental improvement to top level code completion results (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rework top level code completion computer Created 6 years, 4 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
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.toplevel; 5 library services.completion.computer.toplevel;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_services/completion/completion_computer.dart'; 9 import 'package:analysis_services/completion/completion_computer.dart';
10 import 'package:analysis_services/completion/completion_suggestion.dart'; 10 import 'package:analysis_services/completion/completion_suggestion.dart';
11 import 'package:analysis_services/search/search_engine.dart'; 11 import 'package:analysis_services/search/search_engine.dart';
12 import 'package:analyzer/src/generated/ast.dart';
12 import 'package:analyzer/src/generated/element.dart'; 13 import 'package:analyzer/src/generated/element.dart';
13 14
14 /** 15 /**
15 * A computer for `completion.getSuggestions` request results. 16 * A computer for calculating class and top level variable
17 * `completion.getSuggestions` request results
16 */ 18 */
17 class TopLevelComputer extends CompletionComputer { 19 class TopLevelComputer extends CompletionComputer {
18 final SearchEngine searchEngine; 20 final SearchEngine searchEngine;
21 final CompilationUnit unit;
19 22
20 TopLevelComputer(this.searchEngine); 23 TopLevelComputer(this.searchEngine, this.unit);
21 24
22 /** 25 /**
23 * Computes [CompletionSuggestion]s for the specified position in the source. 26 * Computes [CompletionSuggestion]s for the specified position in the source.
24 */ 27 */
25 Future<List<CompletionSuggestion>> compute() { 28 Future<List<CompletionSuggestion>> compute() {
26 var future = searchEngine.searchTopLevelDeclarations(''); 29 var future = searchEngine.searchTopLevelDeclarations('');
27 return future.then((List<SearchMatch> matches) { 30 return future.then((List<SearchMatch> matches) {
28 return matches.map((SearchMatch match) { 31
29 Element element = match.element; 32 // Compute the set of visible libraries to determine relevance
30 String completion = element.displayName; 33 var visibleLibraries = new Set<LibraryElement>();
31 return new CompletionSuggestion( 34 visibleLibraries.add(unit.element.library);
32 CompletionSuggestionKind.fromElementKind(element.kind), 35 visibleLibraries.addAll(unit.element.library.importedLibraries);
Paul Berry 2014/08/06 18:50:41 Do we need to do extra work to filter out names be
danrubel 2014/08/06 19:44:38 Good point. https://codereview.chromium.org/445083
33 CompletionRelevance.DEFAULT, 36
34 completion, 37 // Compute the set of possible classes and top level variables
35 completion.length, 38 var suggestions = new List<CompletionSuggestion>();
36 0, 39 matches.forEach((SearchMatch match) {
37 element.isDeprecated, 40 if (match.kind == MatchKind.DECLARATION) {
38 false // isPotential 41 Element element = match.element;
39 ); 42 String completion = element.displayName;
40 }).toList(); 43 suggestions.add(
44 new CompletionSuggestion(
45 CompletionSuggestionKind.fromElementKind(element.kind),
46 visibleLibraries.contains(element.library) ?
47 CompletionRelevance.DEFAULT :
48 CompletionRelevance.LOW,
49 completion,
50 completion.length,
51 0,
52 element.isDeprecated,
53 false // isPotential
54 ));
55 }
56 });
57 return suggestions;
41 }); 58 });
42 } 59 }
60
43 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698