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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/driver.dart

Issue 2656233004: Use AnalysisDriver.getErrors() to get cached errors for already analyzed files. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/driver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/dart/analysis/driver.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 203944d3dfb316293a6d36d0e063abb0cbde939a..34dee148973a167079ac578ab93bd78383fe3c77 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -487,6 +487,36 @@ class AnalysisDriver {
}
/**
+ * Return a [Future] that completes with the [ErrorsResult] for the Dart
+ * file with the given [path]. If the file is not a Dart file or cannot
+ * be analyzed, the [Future] completes with `null`.
+ *
+ * The [path] must be absolute and normalized.
+ *
+ * This method does not use analysis priorities, and must not be used in
+ * interactive analysis, such as Analysis Server or its plugins.
+ */
+ Future<ErrorsResult> getErrors(String path) async {
+ // Ask the analysis result without unit, so return cached errors.
+ // If no cached analysis result, it will be computed.
+ AnalysisResult analysisResult = _computeAnalysisResult(path);
+
+ // If not computed yet, because a part file without a known library,
+ // we have to compute the full analysis result, with the unit.
+ analysisResult ??= await getResult(path);
+ if (analysisResult == null) {
+ return null;
+ }
+
+ return new ErrorsResult(
+ path,
+ analysisResult.uri,
+ analysisResult.contentHash,
+ analysisResult.lineInfo,
+ analysisResult.errors);
+ }
+
+ /**
* Return a [Future] that completes with the list of added files that
* reference the given external [name].
*/
@@ -1390,6 +1420,43 @@ class AnalysisResult {
}
/**
+ * The errors in a single file.
+ *
+ * These results are self-consistent, i.e. [content], [contentHash], [errors]
+ * correspond to each other. But none of the results is guaranteed to be
+ * consistent with the state of the files.
+ */
+class ErrorsResult {
+ /**
+ * The path of the parsed file, absolute and normalized.
+ */
+ final String path;
+
+ /**
+ * The URI of the file that corresponded to the [path].
+ */
+ final Uri uri;
+
+ /**
+ * The MD5 hash of the [content].
+ */
+ final String contentHash;
+
+ /**
+ * Information about lines in the [content].
+ */
+ final LineInfo lineInfo;
+
+ /**
+ * The full list of computed analysis errors, both syntactic and semantic.
+ */
+ final List<AnalysisError> errors;
+
+ ErrorsResult(
+ this.path, this.uri, this.contentHash, this.lineInfo, this.errors);
+}
+
+/**
* Exception that happened during analysis.
*/
class ExceptionResult {
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/driver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698