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

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

Issue 300553014: Implementation for 'analysis.updateContent' API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 analysis.server; 5 library analysis.server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_logger.dart'; 9 import 'package:analysis_server/src/analysis_logger.dart';
10 import 'package:analysis_server/src/channel.dart'; 10 import 'package:analysis_server/src/channel.dart';
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // TODO(danrubel): replace contextId with real analysisTarget 267 // TODO(danrubel): replace contextId with real analysisTarget
268 analysis['analysisTarget'] = contextId; 268 analysis['analysisTarget'] = contextId;
269 } else { 269 } else {
270 analysis['analyzing'] = false; 270 analysis['analyzing'] = false;
271 } 271 }
272 notification.params['analysis'] = analysis; 272 notification.params['analysis'] = analysis;
273 channel.sendNotification(notification); 273 channel.sendNotification(notification);
274 } 274 }
275 275
276 /** 276 /**
277 * Implementation for `server.setAnalysisRoots`. 277 * Implementation for `analysis.setAnalysisRoots`.
278 * 278 *
279 * TODO(scheglov) implement complete projects/contexts semantics. 279 * TODO(scheglov) implement complete projects/contexts semantics.
280 * 280 *
281 * The current implementation is intentionally simplified and expected 281 * The current implementation is intentionally simplified and expected
282 * that only folders are given each given folder corresponds to the exactly 282 * that only folders are given each given folder corresponds to the exactly
283 * one context. 283 * one context.
284 * 284 *
285 * So, we can start working in parallel on adding services and improving 285 * So, we can start working in parallel on adding services and improving
286 * projects/contexts support. 286 * projects/contexts support.
287 */ 287 */
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 323 }
324 // add new contexts 324 // add new contexts
325 for (Folder folder in newFolders) { 325 for (Folder folder in newFolders) {
326 PubFolder pubFolder = new PubFolder(defaultSdk, folder); 326 PubFolder pubFolder = new PubFolder(defaultSdk, folder);
327 folderMap[folder] = pubFolder; 327 folderMap[folder] = pubFolder;
328 addContextToWorkQueue(pubFolder.context); 328 addContextToWorkQueue(pubFolder.context);
329 } 329 }
330 } 330 }
331 331
332 /** 332 /**
333 * Implementation for `analysis.updateContent`.
334 */
335 void updateContent(Map<String, ContentChange> changes) {
336 changes.forEach((file, change) {
337 AnalysisContext analysisContext = _getAnalysisContext(file);
338 if (analysisContext != null) {
339 Source source = _getSource(file);
340 if (change.offset == null) {
341 print('setContents: $file');
Brian Wilkerson 2014/05/28 20:38:15 Remove debugging output?
scheglov 2014/05/28 20:44:05 Done.
342 analysisContext.setContents(source, change.content);
343 } else {
344 print('setChangedContents: $file');
345 analysisContext.setChangedContents(source, change.content,
346 change.offset, change.oldLength, change.newLength);
347 }
348 addContextToWorkQueue(analysisContext);
349 }
350 });
351 }
352
353 /**
333 * Return the [AnalysisContext] that is used to analyze the given [path]. 354 * Return the [AnalysisContext] that is used to analyze the given [path].
334 * Return `null` if there is no such context. 355 * Return `null` if there is no such context.
335 */ 356 */
336 AnalysisContext test_getAnalysisContext(String path) { 357 AnalysisContext _getAnalysisContext(String path) {
337 for (Folder folder in folderMap.keys) { 358 for (Folder folder in folderMap.keys) {
338 if (path.startsWith(folder.fullName)) { 359 if (path.startsWith(folder.fullName)) {
339 return folderMap[folder].context; 360 return folderMap[folder].context;
340 } 361 }
341 } 362 }
342 return null; 363 return null;
343 } 364 }
344 365
345 /** 366 /**
367 * Return the [Source] of the Dart file with the given [path].
368 */
369 Source _getSource(String path) {
370 File file = resourceProvider.getResource(path);
371 return file.createSource(UriKind.FILE_URI);
372 }
373
374 /**
346 * Return the [CompilationUnit] of the Dart file with the given [path]. 375 * Return the [CompilationUnit] of the Dart file with the given [path].
347 * Return `null` if the file is not a part of any context. 376 * Return `null` if the file is not a part of any context.
348 */ 377 */
349 CompilationUnit test_getResolvedCompilationUnit(String path) { 378 CompilationUnit test_getResolvedCompilationUnit(String path) {
350 // prepare AnalysisContext 379 // prepare AnalysisContext
351 AnalysisContext context = test_getAnalysisContext(path); 380 AnalysisContext context = _getAnalysisContext(path);
352 if (context == null) { 381 if (context == null) {
353 return null; 382 return null;
354 } 383 }
355 // prepare sources 384 // prepare sources
356 File file = resourceProvider.getResource(path); 385 Source unitSource = _getSource(path);
357 Source unitSource = file.createSource(UriKind.FILE_URI);
358 List<Source> librarySources = context.getLibrariesContaining(unitSource); 386 List<Source> librarySources = context.getLibrariesContaining(unitSource);
359 if (librarySources.isEmpty) { 387 if (librarySources.isEmpty) {
360 return null; 388 return null;
361 } 389 }
362 // get a resolved unit 390 // get a resolved unit
363 return context.getResolvedCompilationUnit2(unitSource, librarySources[0]); 391 return context.getResolvedCompilationUnit2(unitSource, librarySources[0]);
364 } 392 }
365 393
366 /** 394 /**
367 * Return `true` if all tasks are finished in this [AnalysisServer]. 395 * Return `true` if all tasks are finished in this [AnalysisServer].
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 /** 522 /**
495 * An enumeration of the services provided by the server domain. 523 * An enumeration of the services provided by the server domain.
496 */ 524 */
497 class ServerService extends Enum2<ServerService> { 525 class ServerService extends Enum2<ServerService> {
498 static const ServerService STATUS = const ServerService('STATUS', 0); 526 static const ServerService STATUS = const ServerService('STATUS', 0);
499 527
500 static const List<ServerService> VALUES = const [STATUS]; 528 static const List<ServerService> VALUES = const [STATUS];
501 529
502 const ServerService(String name, int ordinal) : super(name, ordinal); 530 const ServerService(String name, int ordinal) : super(name, ordinal);
503 } 531 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/domain_analysis.dart » ('j') | pkg/analysis_server/test/domain_analysis_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698