OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 import 'dart:async'; | |
6 | |
7 import 'package:analyzer/dart/ast/ast.dart'; | |
8 import 'package:analyzer/error/error.dart'; | |
9 import 'package:analyzer/file_system/file_system.dart'; | |
10 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | |
11 import 'package:analyzer/src/generated/source.dart'; | |
12 | |
13 /** | |
14 * This class computes [AnalysisResult]s for Dart files. | |
15 */ | |
16 class AnalysisDriver { | |
Brian Wilkerson
2016/10/25 17:24:12
It looks like AnalysisDriver is the replacement fo
scheglov
2016/10/25 18:38:45
It seems so - it produces analysis results, client
| |
17 /** | |
18 * The byte storage to get and put serialized data. | |
19 * | |
20 * It can be shared between other [AnalysisDriver]s. | |
Paul Berry
2016/10/23 10:39:19
s/between/with/.
Also, yay! I like how you've de
scheglov
2016/10/23 20:54:34
Done.
| |
21 */ | |
22 final ByteStore _byteStore; | |
23 | |
24 /** | |
25 * The [SourceFactory] is used to resolve URIs to paths and restore URIs | |
26 * from file paths. | |
27 */ | |
28 final SourceFactory _sourceFactory; | |
29 | |
30 /** | |
31 * This [ContentCache] is consulted for a file content before reading | |
32 * the content from the file. | |
33 */ | |
34 final ContentCache _contentCache; | |
35 | |
36 AnalysisDriver(this._byteStore, this._sourceFactory, this._contentCache); | |
37 | |
38 /** | |
39 * Set the list of files that the driver should try to analyze sooner. | |
40 * | |
41 * Every path in the list must be absolute and normalized. | |
42 * | |
43 * The driver will produce the results through the [results] stream. The | |
44 * exact order in which results are produced is not defined, neither | |
45 * between priority files, not between them and not priority files. | |
Paul Berry
2016/10/23 10:39:19
s/not priority/non-priority/
scheglov
2016/10/23 20:54:34
Done.
| |
46 */ | |
47 void set priorityFiles(List<String> priorityPaths) { | |
48 // TODO(scheglov) implement | |
49 } | |
50 | |
51 /** | |
52 * Return the [Stream] that produces [AnalysisResult]s for added files. | |
53 * | |
54 * Analysis starts when the client starts listening to the stream, and stops | |
55 * when the client cancels the subscription. | |
56 * | |
57 * Analysis is eventual, the driver will try to produce results that are at | |
58 * some point more consistent with the state of the files, but does not | |
59 * guarantee that this will ever happen. | |
Paul Berry
2016/10/23 10:39:19
I think we should make a stronger guarantee than t
scheglov
2016/10/23 20:54:34
Thank you, Paul.
I added this comment to the class
| |
60 * | |
61 * More than one result might be produced for the same file, even if the | |
62 * client does not change the state of the files. | |
63 * | |
64 * Results might be produced even for files that have never been added | |
65 * using [addFile], for example when [getResult] was called for a file. | |
66 */ | |
67 Stream<AnalysisResult> get results async* { | |
68 // TODO(scheglov) implement | |
69 } | |
70 | |
71 /** | |
72 * Add the file with the given [path] to the set of files to analyze. | |
73 * | |
74 * The [path] must be absolute and normalized. | |
75 * | |
76 * The results of analysis are eventually produced by the [results] stream. | |
77 */ | |
78 void addFile(String path) { | |
Brian Wilkerson
2016/10/25 17:24:12
I think we'll want addFiles (plural) for performan
scheglov
2016/10/25 18:38:45
I don't know yet if we need addFiles().
Maybe as a
Brian Wilkerson
2016/10/26 06:54:47
// foo/lib/a.dart
import 'file:///c.dart'
// foo/
scheglov
2016/10/26 16:45:39
OK, I see.
Let's discuss this when we're all in th
| |
79 // TODO(scheglov) implement | |
80 } | |
81 | |
82 /** | |
83 * The file with the given [path] might have changed - updated, added or | |
84 * removed. Or not, we don't know. Or it might have, but then changed back. | |
85 * | |
86 * The [path] must be absolute and normalized. | |
87 * | |
88 * The driver might use this information to decide that new analysis results | |
89 * should be produced, but does not guarantee this, nor for the given file, | |
90 * nor for any other file. | |
Paul Berry
2016/10/23 10:39:19
If you take my suggestion above, you could replace
scheglov
2016/10/23 20:54:34
Done.
| |
91 * | |
92 * Invocation of this method will not prevent a [Future] returned from | |
93 * [getResult] from completing with a result, and does not guarantee that the | |
94 * result will reflect the state of the file at the moment before, at or | |
95 * after the invocation of [changeFile]. | |
96 */ | |
Paul Berry
2016/10/23 10:39:19
Is it ok to pass a path to [changeFile] that is no
scheglov
2016/10/23 20:54:34
Yes, it is OK to notify about implicitly analyzed
| |
97 void changeFile(String path) { | |
98 // TODO(scheglov) implement | |
99 } | |
100 | |
101 /** | |
102 * Return the [Future] that completes with a [AnalysisResult] for the file | |
103 * with the given [path]. | |
104 * | |
105 * The [path] must be absolute and normalized. | |
Paul Berry
2016/10/23 10:39:19
Is it required that the path is in the set of expl
scheglov
2016/10/23 20:54:34
No, it isn't.
The path can be any file - explicitl
| |
106 * | |
107 * The result is not guaranteed to be produced for the state of the file | |
108 * which is closest to the moment of the invocation. But if the client | |
109 * continues invoking this method, eventually one of the invocations will | |
110 * return a [Future] that completes with the result that is closer to the | |
111 * state of the files. | |
Paul Berry
2016/10/23 10:39:19
Can we make a stronger guarantee when the analysis
scheglov
2016/10/23 20:54:34
Done.
| |
112 */ | |
113 Future<AnalysisResult> getResult(String path) { | |
114 // TODO(scheglov) implement | |
115 throw new UnimplementedError(); | |
116 } | |
117 | |
118 /** | |
119 * Remove the file with the given [path] from the list of files to analyze. | |
120 * | |
121 * The [path] must be absolute and normalized. | |
122 * | |
123 * The results of analysis of the file might still be produced by the | |
124 * [results] stream. The driver will try to stop producing these results, | |
125 * but does not guarantee this. | |
126 */ | |
127 void removeFile(String path) { | |
128 // TODO(scheglov) implement | |
129 } | |
130 } | |
Paul Berry
2016/10/23 10:39:19
Additional API that we may need to add in the futu
scheglov
2016/10/23 20:54:34
Thanks, I will add this to the list.
Paul Berry
2016/10/23 21:07:19
Oops, sorry. No difference. I'm not sure what I
| |
131 | |
132 /** | |
133 * The result of analyzing of a single file. | |
134 * | |
135 * These results are self-consistent, i.e. [content], [contentHash], the | |
136 * resolved [unit] correspond to each other. All referenced elements, even | |
137 * external ones, are also self-consistent. But none of the results is | |
138 * guaranteed to be consistent with the state of the files. | |
139 * | |
140 * Every result is independent, and is not guaranteed to be consistent with | |
141 * any previously returned result, even inside of the same library. | |
142 */ | |
143 class AnalysisResult { | |
144 /** | |
145 * The path of the analysed file, absolute and normalized. | |
146 */ | |
147 final String path; | |
148 | |
149 /** | |
150 * The URI of the file that corresponded to the [path] in the used | |
151 * [SourceFactory] at some point. Is it not guaranteed to be still consistent | |
152 * to the [path], and provided as FYI. | |
153 */ | |
154 final Uri uri; | |
155 | |
156 /** | |
157 * The content of the file that was scanned, parsed and resolved. | |
158 */ | |
159 final String content; | |
160 | |
161 /** | |
162 * The MD5 hash of the [content]. | |
163 */ | |
164 final String contentHash; | |
165 | |
166 /** | |
167 * The fully resolved compilation unit for the [content]. | |
168 */ | |
169 final CompilationUnit unit; | |
170 | |
171 /** | |
172 * The full list of computed analysis errors, both syntactic and semantic. | |
173 */ | |
174 final List<AnalysisError> errors; | |
175 | |
176 AnalysisResult(this.path, this.uri, this.content, this.contentHash, this.unit, | |
177 this.errors); | |
178 } | |
OLD | NEW |