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

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

Issue 362893004: Implementation for 'analysis.getHover'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments Created 6 years, 5 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/lib/src/computer/computer_hover.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 analysis.server; 5 library analysis.server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/analysis_logger.dart'; 10 import 'package:analysis_server/src/analysis_logger.dart';
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 219 }
220 220
221 /** 221 /**
222 * Set the priority files to the given [files]. 222 * Set the priority files to the given [files].
223 */ 223 */
224 void setPriorityFiles(Request request, List<String> files) { 224 void setPriorityFiles(Request request, List<String> files) {
225 Map<AnalysisContext, List<Source>> sourceMap = 225 Map<AnalysisContext, List<Source>> sourceMap =
226 new HashMap<AnalysisContext, List<Source>>(); 226 new HashMap<AnalysisContext, List<Source>>();
227 List<String> unanalyzed = new List<String>(); 227 List<String> unanalyzed = new List<String>();
228 files.forEach((file) { 228 files.forEach((file) {
229 AnalysisContext analysisContext = _getAnalysisContext(file); 229 AnalysisContext analysisContext = getAnalysisContext(file);
230 if (analysisContext == null) { 230 if (analysisContext == null) {
231 unanalyzed.add(file); 231 unanalyzed.add(file);
232 } else { 232 } else {
233 List<Source> sourceList = sourceMap[analysisContext]; 233 List<Source> sourceList = sourceMap[analysisContext];
234 if (sourceList == null) { 234 if (sourceList == null) {
235 sourceList = <Source>[]; 235 sourceList = <Source>[];
236 sourceMap[analysisContext] = sourceList; 236 sourceMap[analysisContext] = sourceList;
237 } 237 }
238 sourceList.add(_getSource(file)); 238 sourceList.add(getSource(file));
239 } 239 }
240 }); 240 });
241 if (unanalyzed.isNotEmpty) { 241 if (unanalyzed.isNotEmpty) {
242 StringBuffer buffer = new StringBuffer(); 242 StringBuffer buffer = new StringBuffer();
243 buffer.writeAll(unanalyzed, ', '); 243 buffer.writeAll(unanalyzed, ', ');
244 throw new RequestFailure(new Response.unanalyzedPriorityFiles(request, 244 throw new RequestFailure(new Response.unanalyzedPriorityFiles(request,
245 buffer.toString())); 245 buffer.toString()));
246 } 246 }
247 folderMap.forEach((Folder folder, AnalysisContext context) { 247 folderMap.forEach((Folder folder, AnalysisContext context) {
248 List<Source> sourceList = sourceMap[context]; 248 List<Source> sourceList = sourceMap[context];
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 new Response.unsupportedFeature( 427 new Response.unsupportedFeature(
428 requestId, e.message)); 428 requestId, e.message));
429 } 429 }
430 } 430 }
431 431
432 /** 432 /**
433 * Implementation for `analysis.updateContent`. 433 * Implementation for `analysis.updateContent`.
434 */ 434 */
435 void updateContent(Map<String, ContentChange> changes) { 435 void updateContent(Map<String, ContentChange> changes) {
436 changes.forEach((file, change) { 436 changes.forEach((file, change) {
437 AnalysisContext analysisContext = _getAnalysisContext(file); 437 AnalysisContext analysisContext = getAnalysisContext(file);
438 // TODO(paulberry): handle the case where a file is referred to by more 438 // TODO(paulberry): handle the case where a file is referred to by more
439 // than one context (e.g package A depends on package B using a local 439 // than one context (e.g package A depends on package B using a local
440 // path, user has both packages open for editing in separate contexts, 440 // path, user has both packages open for editing in separate contexts,
441 // and user modifies a file in package B). 441 // and user modifies a file in package B).
442 if (analysisContext != null) { 442 if (analysisContext != null) {
443 Source source = _getSource(file); 443 Source source = getSource(file);
444 if (change.offset == null) { 444 if (change.offset == null) {
445 analysisContext.setContents(source, change.content); 445 analysisContext.setContents(source, change.content);
446 } else { 446 } else {
447 analysisContext.setChangedContents(source, change.content, 447 analysisContext.setChangedContents(source, change.content,
448 change.offset, change.oldLength, change.newLength); 448 change.offset, change.oldLength, change.newLength);
449 } 449 }
450 schedulePerformAnalysisOperation(analysisContext); 450 schedulePerformAnalysisOperation(analysisContext);
451 } 451 }
452 }); 452 });
453 } 453 }
454 454
455 /** 455 /**
456 * Implementation for `analysis.setSubscriptions`. 456 * Implementation for `analysis.setSubscriptions`.
457 */ 457 */
458 void setAnalysisSubscriptions(Map<AnalysisService, Set<String>> subscriptions) { 458 void setAnalysisSubscriptions(Map<AnalysisService, Set<String>> subscriptions) {
459 // send notifications for already analyzed sources 459 // send notifications for already analyzed sources
460 subscriptions.forEach((service, Set<String> newFiles) { 460 subscriptions.forEach((service, Set<String> newFiles) {
461 Set<String> oldFiles = analysisServices[service]; 461 Set<String> oldFiles = analysisServices[service];
462 Set<String> todoFiles = oldFiles != null ? newFiles.difference(oldFiles) : newFiles; 462 Set<String> todoFiles = oldFiles != null ? newFiles.difference(oldFiles) : newFiles;
463 for (String file in todoFiles) { 463 for (String file in todoFiles) {
464 Source source = _getSource(file); 464 Source source = getSource(file);
465 AnalysisContext context = _getAnalysisContext(file); 465 AnalysisContext context = getAnalysisContext(file);
466 // errors 466 // errors
467 if (service == AnalysisService.ERRORS) { 467 if (service == AnalysisService.ERRORS) {
468 LineInfo lineInfo = context.getLineInfo(source); 468 LineInfo lineInfo = context.getLineInfo(source);
469 List<AnalysisError> errors = context.getErrors(source).errors; 469 List<AnalysisError> errors = context.getErrors(source).errors;
470 sendAnalysisNotificationErrors(this, file, lineInfo, errors); 470 sendAnalysisNotificationErrors(this, file, lineInfo, errors);
471 } 471 }
472 // Dart unit notifications. 472 // Dart unit notifications.
473 if (AnalysisEngine.isDartFileName(file)) { 473 if (AnalysisEngine.isDartFileName(file)) {
474 CompilationUnit dartUnit = getResolvedCompilationUnitToResendNotificat ion(file); 474 CompilationUnit dartUnit = getResolvedCompilationUnitToResendNotificat ion(file);
475 if (dartUnit != null) { 475 if (dartUnit != null) {
(...skipping 14 matching lines...) Expand all
490 } 490 }
491 }); 491 });
492 // remember new subscriptions 492 // remember new subscriptions
493 this.analysisServices = subscriptions; 493 this.analysisServices = subscriptions;
494 } 494 }
495 495
496 /** 496 /**
497 * Return the [AnalysisContext] that is used to analyze the given [path]. 497 * Return the [AnalysisContext] that is used to analyze the given [path].
498 * Return `null` if there is no such context. 498 * Return `null` if there is no such context.
499 */ 499 */
500 AnalysisContext _getAnalysisContext(String path) { 500 AnalysisContext getAnalysisContext(String path) {
501 for (Folder folder in folderMap.keys) { 501 for (Folder folder in folderMap.keys) {
502 if (path.startsWith(folder.path)) { 502 if (path.startsWith(folder.path)) {
503 return folderMap[folder]; 503 return folderMap[folder];
504 } 504 }
505 } 505 }
506 return null; 506 return null;
507 } 507 }
508 508
509 /** 509 /**
510 * Return the [Source] of the Dart file with the given [path]. 510 * Return the [Source] of the Dart file with the given [path].
511 */ 511 */
512 Source _getSource(String path) { 512 Source getSource(String path) {
513 File file = contextDirectoryManager.resourceProvider.getResource(path); 513 File file = contextDirectoryManager.resourceProvider.getResource(path);
514 return file.createSource(UriKind.FILE_URI); 514 return file.createSource(UriKind.FILE_URI);
515 } 515 }
516 516
517 /** 517 /**
518 * Returns the [CompilationUnit] of the Dart file with the given [path] that 518 * Returns the [CompilationUnit] of the Dart file with the given [path] that
519 * should be used to resend notifications for already resolved unit. 519 * should be used to resend notifications for already resolved unit.
520 * Returns `null` if the file is not a part of any context, library has not 520 * Returns `null` if the file is not a part of any context, library has not
521 * been yet resolved, or any problem happened. 521 * been yet resolved, or any problem happened.
522 */ 522 */
523 CompilationUnit getResolvedCompilationUnitToResendNotification(String path) { 523 CompilationUnit getResolvedCompilationUnitToResendNotification(String path) {
524 // prepare AnalysisContext 524 // prepare AnalysisContext
525 AnalysisContext context = _getAnalysisContext(path); 525 AnalysisContext context = getAnalysisContext(path);
526 if (context == null) { 526 if (context == null) {
527 return null; 527 return null;
528 } 528 }
529 // prepare sources 529 // prepare sources
530 Source unitSource = _getSource(path); 530 Source unitSource = getSource(path);
531 List<Source> librarySources = context.getLibrariesContaining(unitSource); 531 List<Source> librarySources = context.getLibrariesContaining(unitSource);
532 if (librarySources.isEmpty) { 532 if (librarySources.isEmpty) {
533 return null; 533 return null;
534 } 534 }
535 // if library has not been resolved yet, the unit will be resolved later 535 // if library has not been resolved yet, the unit will be resolved later
536 Source librarySource = librarySources[0]; 536 Source librarySource = librarySources[0];
537 if (context.getLibraryElement(librarySource) == null) { 537 if (context.getLibraryElement(librarySource) == null) {
538 return null; 538 return null;
539 } 539 }
540 // if library has been already resolved, resolve unit 540 // if library has been already resolved, resolve unit
541 return context.resolveCompilationUnit2(unitSource, librarySource); 541 return context.resolveCompilationUnit2(unitSource, librarySource);
542 } 542 }
543 543
544 /** 544 /**
545 * Return the [CompilationUnit] of the Dart file with the given [path]. 545 * Return the [CompilationUnit] of the Dart file with the given [path].
546 * Return `null` if the file is not a part of any context. 546 * Return `null` if the file is not a part of any context.
547 */ 547 */
548 CompilationUnit test_getResolvedCompilationUnit(String path) { 548 CompilationUnit test_getResolvedCompilationUnit(String path) {
549 // prepare AnalysisContext 549 // prepare AnalysisContext
550 AnalysisContext context = _getAnalysisContext(path); 550 AnalysisContext context = getAnalysisContext(path);
551 if (context == null) { 551 if (context == null) {
552 return null; 552 return null;
553 } 553 }
554 // prepare sources 554 // prepare sources
555 Source unitSource = _getSource(path); 555 Source unitSource = getSource(path);
556 List<Source> librarySources = context.getLibrariesContaining(unitSource); 556 List<Source> librarySources = context.getLibrariesContaining(unitSource);
557 if (librarySources.isEmpty) { 557 if (librarySources.isEmpty) {
558 return null; 558 return null;
559 } 559 }
560 // get a resolved unit 560 // get a resolved unit
561 return context.getResolvedCompilationUnit2(unitSource, librarySources[0]); 561 return context.getResolvedCompilationUnit2(unitSource, librarySources[0]);
562 } 562 }
563 563
564 /** 564 /**
565 * Return `true` if all operations have been performed in this [AnalysisServer ]. 565 * Return `true` if all operations have been performed in this [AnalysisServer ].
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 /** 598 /**
599 * An enumeration of the services provided by the server domain. 599 * An enumeration of the services provided by the server domain.
600 */ 600 */
601 class ServerService extends Enum2<ServerService> { 601 class ServerService extends Enum2<ServerService> {
602 static const ServerService STATUS = const ServerService('STATUS', 0); 602 static const ServerService STATUS = const ServerService('STATUS', 0);
603 603
604 static const List<ServerService> VALUES = const [STATUS]; 604 static const List<ServerService> VALUES = const [STATUS];
605 605
606 const ServerService(String name, int ordinal) : super(name, ordinal); 606 const ServerService(String name, int ordinal) : super(name, ordinal);
607 } 607 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/computer/computer_hover.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698