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

Side by Side Diff: pkg/analysis_server/lib/src/domain_completion.dart

Issue 422423003: incremental step moving completion into services and adding tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/completion_test.dart » ('j') | 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 domain.completion; 5 library domain.completion;
6 6
7 import 'dart:async';
8
9 import 'package:analysis_server/src/analysis_server.dart'; 7 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/constants.dart'; 8 import 'package:analysis_server/src/constants.dart';
11 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_services/completion/completion_suggestion.dart'; 10 import 'package:analysis_services/completion/completion_suggestion.dart';
11 import 'package:analysis_services/completion/top_level_computer.dart';
13 import 'package:analysis_services/constants.dart'; 12 import 'package:analysis_services/constants.dart';
14 import 'package:analysis_services/search/search_engine.dart'; 13 import 'package:analysis_services/search/search_engine.dart';
15 import 'package:analyzer/src/generated/element.dart';
16 14
17 /** 15 /**
18 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] 16 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler]
19 * that handles requests in the search domain. 17 * that handles requests in the search domain.
20 */ 18 */
21 class CompletionDomainHandler implements RequestHandler { 19 class CompletionDomainHandler implements RequestHandler {
22 /** 20 /**
23 * The analysis server that is using this handler to process requests. 21 * The analysis server that is using this handler to process requests.
24 */ 22 */
25 final AnalysisServer server; 23 final AnalysisServer server;
(...skipping 25 matching lines...) Expand all
51 } 49 }
52 return null; 50 return null;
53 } 51 }
54 52
55 Response getSuggestions(Request request) { 53 Response getSuggestions(Request request) {
56 // extract param 54 // extract param
57 String file = request.getRequiredParameter(FILE).asString(); 55 String file = request.getRequiredParameter(FILE).asString();
58 int offset = request.getRequiredParameter(OFFSET).asInt(); 56 int offset = request.getRequiredParameter(OFFSET).asInt();
59 // schedule completion analysis 57 // schedule completion analysis
60 String completionId = (_nextCompletionId++).toString(); 58 String completionId = (_nextCompletionId++).toString();
61 var computer = new TopLevelSuggestionsComputer(server.searchEngine); 59 var computer = new TopLevelComputer(server.searchEngine);
62 var future = computer.compute(); 60 var future = computer.compute();
63 future.then((List<CompletionSuggestion> results) { 61 future.then((List<CompletionSuggestion> results) {
64 _sendCompletionNotification(completionId, true, results); 62 _sendCompletionNotification(completionId, true, results);
65 }); 63 });
66 // respond 64 // respond
67 return new Response(request.id)..setResult(ID, completionId); 65 return new Response(request.id)..setResult(ID, completionId);
68 } 66 }
69 67
70 void _sendCompletionNotification(String completionId, bool isLast, 68 void _sendCompletionNotification(String completionId, bool isLast,
71 Iterable<CompletionSuggestion> results) { 69 Iterable<CompletionSuggestion> results) {
72 Notification notification = new Notification(COMPLETION_RESULTS); 70 Notification notification = new Notification(COMPLETION_RESULTS);
73 notification.setParameter(ID, completionId); 71 notification.setParameter(ID, completionId);
74 notification.setParameter(LAST, isLast); 72 notification.setParameter(LAST, isLast);
75 notification.setParameter(RESULTS, results); 73 notification.setParameter(RESULTS, results);
76 server.sendNotification(notification); 74 server.sendNotification(notification);
77 } 75 }
78 } 76 }
79 77
80 /**
81 * A computer for `completion.getSuggestions` request results.
82 */
83 class TopLevelSuggestionsComputer {
84 final SearchEngine searchEngine;
85
86 TopLevelSuggestionsComputer(this.searchEngine);
87
88 /**
89 * Computes [CompletionSuggestion]s for the specified position in the source.
90 */
91 Future<List<CompletionSuggestion>> compute() {
92 var future = searchEngine.searchTopLevelDeclarations('');
93 return future.then((List<SearchMatch> matches) {
94 return matches.map((SearchMatch match) {
95 Element element = match.element;
96 String completion = element.displayName;
97 return new CompletionSuggestion(
98 CompletionSuggestionKind.fromElementKind(element.kind),
99 CompletionRelevance.DEFAULT,
100 completion,
101 completion.length,
102 0,
103 element.isDeprecated,
104 false // isPotential
105 );
106 }).toList();
107 });
108 }
109 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698