Skip to content

Commit 74ef6d1

Browse files
srawlinsCommit Queue
authored andcommitted
DAS plugins: Do not run lint rules or warnings unnecessarily
Work towards #61490 When a plugin re-resolves a library [1] via `AnalysisSessionImpl.getResolvedLibrary`, which calls `AnalysisDriver.getResolvedLibrary`, eventually we get down to `LibraryAnalyzer.analyze`. This method contains the singular piece of code that checks `AnalysisOptions.lint` and `AnalysisOptions.warning` [2]. A plugin re-resolves a library in order to parse the code, and ultimately resolve the library into a LibraryElement. It does _not_ use any lint computed by `LibraryAnalyzer.analyze()`, nor any warnings, nor even any compile-time errors. So we should do our best to do the minimal amount of work that still gets us our LibraryElement. Setting `AnalysisOptions.lint` and `AnalysisOptions.warning` reduces the amount of work that `LibraryAnalyzer.analyze()` does. [1]: https://github.com/dart-lang/sdk/blob/c11f9118692461f61570e1ee07b6f5fc43288bb0/pkg/analysis_server_plugin/lib/src/plugin_server.dart#L351 [2]: https://github.com/dart-lang/sdk/blob/c11f9118692461f61570e1ee07b6f5fc43288bb0/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart#L342-L359 Change-Id: I73413a6646b14ff3a01246470b00e0a3676c4b3a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450365 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 8875f1a commit 74ef6d1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pkg/analysis_server_plugin/lib/src/plugin_server.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,30 @@ class PluginServer {
323323
}
324324

325325
/// Analyzes the libraries at the given [paths].
326+
// TODO(srawlins): Refactor how libraries are analyzed using AnalysisDriver,
327+
// to be similar to what analysis server does:
328+
//
329+
// 1. When the analysis roots change it creates the AnalysisContextCollection
330+
// and listens to the drivers' streams of results.
331+
// 2. When a file changes, it lets the driver know about it.
332+
// 3. As the driver analyzes the potentially impacted files it
333+
// a. runs the lints that have been enabled and
334+
// b. puts the result on the stream.
335+
// 4. When a result is on the stream the server grabs the results and sends
336+
// the diagnostics to the client.
337+
//
338+
// It doesn't ever explicitly ask the driver which files were impacted and it
339+
// doesn't explicitly run the lints directly because the driver will do that
340+
// implicitly. There would be benefits to plugins working the same way:
341+
//
342+
// * The driver can do a more efficient job of scheduling analysis than the
343+
// server can (because of having a more complete picture).
344+
// * It means there's only one way that we're trying to use the analyzer so it
345+
// will be easier to make changes to the analyzer when we need to (smaller
346+
// API exposure).
347+
// * The logic for doing analysis is in one place so it's easier to reason
348+
// about.
349+
// * We don't need to be familiar with two different architectures.
326350
Future<void> _analyzeLibraries({
327351
required AnalysisContext analysisContext,
328352
required Set<String> paths,
@@ -668,6 +692,13 @@ class PluginServer {
668692
byteStore: _byteStore,
669693
sdkPath: _sdkPath,
670694
fileContentCache: FileContentCache(_resourceProvider),
695+
updateAnalysisOptions4:
696+
// Disable extra warning computation and lint computation, because
697+
// these are reported in the main analysis server isolate, not in the
698+
// plugins isolate.
699+
({required AnalysisOptionsImpl analysisOptions}) => analysisOptions
700+
..warning = false
701+
..lint = false,
671702
);
672703
_contextCollection = contextCollection;
673704
await _analyzeAllFilesInContextCollection(

0 commit comments

Comments
 (0)