Add a --no-plugins option to prevent analyzer plugins from running

Fixes https://github.com/dart-lang/sdk/issues/62353

Change-Id: I902badd0a7a072b98691d88ad7b382828227b1fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471660
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins
2026-01-12 11:28:17 -08:00
committed by Commit Queue
parent ec2b9b8699
commit 683ef059f5
10 changed files with 54 additions and 7 deletions
@@ -310,6 +310,7 @@ abstract class AnalysisServer {
PluginManager? pluginManager,
MessageSchedulerListener? messageSchedulerListener,
this.performanceLogger,
required bool usePlugins,
}) : resourceProvider = OverlayResourceProvider(baseResourceProvider),
pubApi = PubApi(
instrumentationService,
@@ -359,7 +360,11 @@ abstract class AnalysisServer {
instrumentationService,
sessionLogger,
);
var pluginWatcher = PluginWatcher(resourceProvider, pluginManager);
var pluginWatcher = PluginWatcher(
resourceProvider,
pluginManager,
pluginsAreEnabled: usePlugins,
);
var logName = options.newAnalysisDriverLog;
if (logName != null) {
@@ -180,6 +180,8 @@ class AnalysisServerOptions {
/// Whether to enable fine-grained dependencies.
bool withFineDependencies = false;
bool usePlugins = true;
}
/// Instances of the class [LegacyAnalysisServer] implement a server that
@@ -416,6 +418,7 @@ class LegacyAnalysisServer extends AnalysisServer {
httpClient,
processRunner,
NotificationManager(channel, baseResourceProvider.pathContext),
usePlugins: options.usePlugins,
) {
var contextManagerCallbacks = ServerContextManagerCallbacks(
this,
@@ -164,6 +164,7 @@ class LspAnalysisServer extends AnalysisServer {
httpClient,
processRunner,
LspNotificationManager(baseResourceProvider.pathContext),
usePlugins: options.usePlugins,
) {
notificationManager.server = this;
messageHandler = UninitializedStateMessageHandler(this);
@@ -264,8 +265,8 @@ class LspAnalysisServer extends AnalysisServer {
}
@override
@visibleForTesting
set pluginManager(PluginManager value) {
// we exchange the plugin manager in tests
super.pluginManager = value;
_pluginChangeSubscription?.cancel();
@@ -31,12 +31,25 @@ class PluginWatcher implements DriverWatcher {
final Map<AnalysisDriver, _DriverInfo> _driverInfo =
<AnalysisDriver, _DriverInfo>{};
final bool _pluginsAreEnabled;
/// Initialize a newly created plugin watcher.
PluginWatcher(this.resourceProvider, this.manager)
: _locator = PluginLocator(resourceProvider);
PluginWatcher(
this.resourceProvider,
this.manager, {
required bool pluginsAreEnabled,
}) : _locator = PluginLocator(resourceProvider),
_pluginsAreEnabled = pluginsAreEnabled;
@override
void addedDriver(AnalysisDriver driver) {
if (!_pluginsAreEnabled) {
// Call the plugin manager "initialized."
if (!manager.initializedCompleter.isCompleted) {
manager.initializedCompleter.complete();
}
return;
}
var contextRoot = driver.analysisContext!.contextRoot;
_driverInfo[driver] = _DriverInfo(contextRoot, <String>[
contextRoot.root.path,
@@ -66,9 +79,11 @@ class PluginWatcher implements DriverWatcher {
_addPlugins(driver);
}
/// The context manager has just removed the given analysis [driver].
@override
void removedDriver(AnalysisDriver driver) {
if (!_pluginsAreEnabled) {
return;
}
var info = _driverInfo[driver];
if (info == null) {
throw StateError('Cannot remove a driver that was not added');
@@ -155,6 +155,8 @@ class Driver implements ServerStarter {
/// The name of the flag to enable fine-grained dependencies.
static const String withFineDependenciesOption = 'with-fine-dependencies';
static const String pluginsFlag = 'plugins';
/// The builder for attachments that should be included into crash reports.
CrashReportingAttachmentsBuilder crashReportingAttachmentsBuilder =
CrashReportingAttachmentsBuilder.empty;
@@ -221,6 +223,8 @@ class Driver implements ServerStarter {
var sdkConfig = SdkConfiguration.readFromSdk();
analysisServerOptions.configurationOverrides = sdkConfig;
analysisServerOptions.usePlugins = results.flag(pluginsFlag);
// Analytics (legacy, and unified)
var disableAnalyticsForSession = results.flag(suppressAnalyticsFlag);
@@ -948,6 +952,12 @@ class Driver implements ServerStarter {
help: 'disable all search features',
hide: true,
);
parser.addFlag(
pluginsFlag,
help: 'Use analyzer plugins',
defaultsTo: true,
hide: true,
);
parser.addFlag(
disableSilentAnalysisExceptionsOption,
negatable: false,
@@ -28,7 +28,7 @@ class PluginWatcherTest extends AbstractContextTest {
void setUp() {
super.setUp();
manager = TestPluginManager();
watcher = PluginWatcher(resourceProvider, manager);
watcher = PluginWatcher(resourceProvider, manager, pluginsAreEnabled: true);
}
Future<void> test_addedDriver() async {
+5 -1
View File
@@ -34,11 +34,13 @@ class AnalysisServer {
this.cacheDirectoryPath,
required this.commandName,
required this.argResults,
required bool usePlugins,
this.enabledExperiments = const [],
this.disableStatusNotificationDebouncing = false,
this.suppressAnalytics = false,
bool useAotSnapshot = false,
}) : _useAotSnapshot = useAotSnapshot;
}) : _useAotSnapshot = useAotSnapshot,
_usePlugins = usePlugins;
final String? cacheDirectoryPath;
final File? packagesFile;
@@ -50,6 +52,7 @@ class AnalysisServer {
final bool disableStatusNotificationDebouncing;
final bool suppressAnalytics;
final bool _useAotSnapshot;
final bool _usePlugins;
Process? _process;
@@ -212,6 +215,7 @@ class AnalysisServer {
if (packagesFile != null) '--packages=${packagesFile!.path}',
if (enabledExperiments.isNotEmpty)
'--$experimentFlagName=${enabledExperiments.join(',')}',
if (!_usePlugins) '--no-plugins'
];
log.trace('$executable ${arguments.join(' ')}');
@@ -96,6 +96,8 @@ class AnalyzeCommand extends DartdevCommand {
defaultsTo: true,
hide: true,
)
..addFlag('plugins',
help: 'Use analyzer plugins', defaultsTo: true, hide: true)
..addExperimentalFlags();
}
@@ -136,6 +138,7 @@ class AnalyzeCommand extends DartdevCommand {
final machineFormat = args.option('format') == 'machine';
final jsonFormat = args.option('format') == 'json';
final printMemory = args.flag('memory') && jsonFormat;
final usePlugins = args.flag('plugins');
io.Directory sdkPath;
final useAotSnapshot = args.flag(useAotSnapshotFlag);
@@ -189,6 +192,7 @@ class AnalyzeCommand extends DartdevCommand {
cacheDirectoryPath: args.option('cache'),
commandName: 'analyze',
argResults: args,
usePlugins: usePlugins,
disableStatusNotificationDebouncing: true,
enabledExperiments: args.enabledExperiments,
suppressAnalytics: suppressAnalytics,
+3
View File
@@ -128,6 +128,9 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed
[target],
commandName: 'fix',
argResults: argResults,
// TODO(srawlins): Flip to `true` (or flag value) when plugins can bulk
// fix.
usePlugins: false,
suppressAnalytics: suppressAnalytics,
enabledExperiments: args.enabledExperiments,
useAotSnapshot: args.flag(useAotSnapshotFlag),
@@ -28,6 +28,7 @@ void main() {
[p.dir],
commandName: 'testing',
argResults: null,
usePlugins: false,
suppressAnalytics: true,
);
await server.start();
@@ -41,6 +42,7 @@ void main() {
[p.dir],
commandName: 'testing',
argResults: null,
usePlugins: false,
suppressAnalytics: true,
);
await server.start();