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

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

Issue 2681393004: Implement also 'execution.mapUri' for file to URI. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/integration/execution/map_uri_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.execution; 5 library domain.execution;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:core'; 9 import 'dart:core';
10 10
11 import 'package:analysis_server/plugin/protocol/protocol.dart'; 11 import 'package:analysis_server/plugin/protocol/protocol.dart';
12 import 'package:analysis_server/src/analysis_server.dart'; 12 import 'package:analysis_server/src/analysis_server.dart';
13 import 'package:analysis_server/src/constants.dart'; 13 import 'package:analysis_server/src/constants.dart';
14 import 'package:analyzer/file_system/file_system.dart'; 14 import 'package:analyzer/file_system/file_system.dart';
15 import 'package:analyzer/src/dart/analysis/driver.dart';
15 import 'package:analyzer/src/generated/engine.dart'; 16 import 'package:analyzer/src/generated/engine.dart';
16 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
17 18
18 /** 19 /**
19 * Instances of the class [ExecutionDomainHandler] implement a [RequestHandler] 20 * Instances of the class [ExecutionDomainHandler] implement a [RequestHandler]
20 * that handles requests in the `execution` domain. 21 * that handles requests in the `execution` domain.
21 */ 22 */
22 class ExecutionDomainHandler implements RequestHandler { 23 class ExecutionDomainHandler implements RequestHandler {
23 /** 24 /**
24 * The analysis server that is using this handler to process requests. 25 * The analysis server that is using this handler to process requests.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ExecutionMapUriParams params = 93 ExecutionMapUriParams params =
93 new ExecutionMapUriParams.fromRequest(request); 94 new ExecutionMapUriParams.fromRequest(request);
94 String contextId = params.id; 95 String contextId = params.id;
95 String path = contextMap[contextId]; 96 String path = contextMap[contextId];
96 if (path == null) { 97 if (path == null) {
97 return new Response.invalidParameter(request, 'id', 98 return new Response.invalidParameter(request, 'id',
98 'There is no execution context with an id of $contextId'); 99 'There is no execution context with an id of $contextId');
99 } 100 }
100 101
101 SourceFactory sourceFactory; 102 SourceFactory sourceFactory;
103 AnalysisDriver driver;
102 if (server.options.enableNewAnalysisDriver) { 104 if (server.options.enableNewAnalysisDriver) {
103 var driver = server.getAnalysisDriver(path); 105 driver = server.getAnalysisDriver(path);
104 if (driver == null) { 106 if (driver == null) {
105 return new Response.invalidExecutionContext(request, contextId); 107 return new Response.invalidExecutionContext(request, contextId);
106 } 108 }
107 sourceFactory = driver.sourceFactory; 109 sourceFactory = driver.sourceFactory;
108 } else { 110 } else {
109 AnalysisContext context = server.getContainingContext(path); 111 AnalysisContext context = server.getContainingContext(path);
110 if (context == null) { 112 if (context == null) {
111 return new Response.invalidExecutionContext(request, contextId); 113 return new Response.invalidExecutionContext(request, contextId);
112 } 114 }
113 sourceFactory = context.sourceFactory; 115 sourceFactory = context.sourceFactory;
114 } 116 }
115 117
116 String file = params.file; 118 String file = params.file;
117 String uri = params.uri; 119 String uri = params.uri;
118 if (file != null) { 120 if (file != null) {
119 if (uri != null) { 121 if (uri != null) {
120 return new Response.invalidParameter(request, 'file', 122 return new Response.invalidParameter(request, 'file',
121 'Either file or uri must be provided, but not both'); 123 'Either file or uri must be provided, but not both');
122 } 124 }
123 Resource resource = server.resourceProvider.getResource(file); 125 Resource resource = server.resourceProvider.getResource(file);
124 if (!resource.exists) { 126 if (!resource.exists) {
125 return new Response.invalidParameter(request, 'file', 'Must exist'); 127 return new Response.invalidParameter(request, 'file', 'Must exist');
126 } else if (resource is! File) { 128 } else if (resource is! File) {
127 return new Response.invalidParameter( 129 return new Response.invalidParameter(
128 request, 'file', 'Must not refer to a directory'); 130 request, 'file', 'Must not refer to a directory');
129 } 131 }
130 ContextSourcePair contextSource = server.getContextSourcePair(file); 132
131 Source source = contextSource.source; 133 Source source;
134 if (server.options.enableNewAnalysisDriver) {
135 source = driver.fsState.getFileForPath(file).source;
136 } else {
137 ContextSourcePair contextSource = server.getContextSourcePair(file);
138 source = contextSource.source;
139 }
132 if (source.uriKind != UriKind.FILE_URI) { 140 if (source.uriKind != UriKind.FILE_URI) {
133 uri = source.uri.toString(); 141 uri = source.uri.toString();
134 } else { 142 } else {
135 uri = sourceFactory.restoreUri(source).toString(); 143 uri = sourceFactory.restoreUri(source).toString();
136 } 144 }
137 return new ExecutionMapUriResult(uri: uri).toResponse(request.id); 145 return new ExecutionMapUriResult(uri: uri).toResponse(request.id);
138 } else if (uri != null) { 146 } else if (uri != null) {
139 Source source = sourceFactory.forUri(uri); 147 Source source = sourceFactory.forUri(uri);
140 if (source == null) { 148 if (source == null) {
141 return new Response.invalidParameter(request, 'uri', 'Invalid URI'); 149 return new Response.invalidParameter(request, 'uri', 'Invalid URI');
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if (_isInAnalysisRoot(filePath)) { 255 if (_isInAnalysisRoot(filePath)) {
248 server.sendNotification( 256 server.sendNotification(
249 new ExecutionLaunchDataParams(filePath, kind: kind).toNotification()); 257 new ExecutionLaunchDataParams(filePath, kind: kind).toNotification());
250 } 258 }
251 } 259 }
252 260
253 static List<String> _getFullNames(List<Source> sources) { 261 static List<String> _getFullNames(List<Source> sources) {
254 return sources.map((Source source) => source.fullName).toList(); 262 return sources.map((Source source) => source.fullName).toList();
255 } 263 }
256 } 264 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/integration/execution/map_uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698