Skip to content

Commit

Permalink
analyzer: rename most API references to 'plugins' to 'legacy plugins'
Browse files Browse the repository at this point in the history
Change-Id: I56217045ff9d4da8a5a556cd709e0f63a507884f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384964
Commit-Queue: Samuel Rawlins <[email protected]>
Reviewed-by: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
srawlins authored and Commit Queue committed Sep 12, 2024
1 parent 3bf33d6 commit b141611
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 108 deletions.
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/src/plugin/plugin_watcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PluginWatcher implements DriverWatcher {
var contextRoot = driver.analysisContext!.contextRoot;
_driverInfo[driver] = _DriverInfo(
contextRoot, <String>[contextRoot.root.path, _getSdkPath(driver)]);
var enabledPlugins = driver.enabledPluginNames;
var enabledPlugins = driver.enabledLegacyPluginNames;
for (var hostPackageName in enabledPlugins) {
//
// Determine whether the package exists and defines a plugin.
Expand Down
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/src/status/diagnostics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ _CollectedOptionsData _collectOptionsData(AnalysisDriver driver) {
if (driver.analysisContext?.allAnalysisOptions case var allAnalysisOptions?) {
for (var analysisOptions in allAnalysisOptions) {
collectedData.lints.addAll(analysisOptions.lintRules.map((e) => e.name));
collectedData.plugins.addAll(analysisOptions.enabledPluginNames);
collectedData.plugins.addAll(analysisOptions.enabledLegacyPluginNames);
}
}
return collectedData;
Expand Down
8 changes: 5 additions & 3 deletions pkg/analysis_server/test/src/plugin/plugin_watcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class PluginWatcherTest extends AbstractContextTest {

var driver = driverFor(testFile);
// TODO(pq): stop modifying options objects (https://github.com/dart-lang/sdk/issues/54045)
driver.getAnalysisOptionsForFile(testFile).enabledPluginNames = ['foo'];
driver.getAnalysisOptionsForFile(testFile).enabledLegacyPluginNames = [
'foo',
];

expect(manager.addedContextRoots, isEmpty);
watcher.addedDriver(driver);
Expand All @@ -71,8 +73,8 @@ class PluginWatcherTest extends AbstractContextTest {
Future<void> test_addedDriver_missingPackage() async {
var driver = driverFor(testFile);
// TODO(pq): stop modifying options objects (https://github.com/dart-lang/sdk/issues/54045)
driver.getAnalysisOptionsForFile(testFile).enabledPluginNames = [
'noSuchPackage'
driver.getAnalysisOptionsForFile(testFile).enabledLegacyPluginNames = [
'noSuchPackage',
];

watcher.addedDriver(driver);
Expand Down
7 changes: 5 additions & 2 deletions pkg/analyzer/lib/dart/analysis/analysis_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ abstract class AnalysisOptions {
/// The set of features that are globally enabled for this context.
FeatureSet get contextFeatures;

/// Return a list of the names of the packages for which, if they define a
/// plugin, the plugin should be enabled.
/// A list of the names of the packages for which, if they define a
/// legacy plugin, the legacy plugin should be enabled.
List<String> get enabledLegacyPluginNames;

@Deprecated("Use 'enabledLegacyPluginNames' instead")
List<String> get enabledPluginNames;

/// Return a list of error processors that are to be used when reporting
Expand Down
52 changes: 26 additions & 26 deletions pkg/analyzer/lib/src/analysis_options/apply_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,6 @@ extension on AnalysisOptionsImpl {
}
}

void applyPlugins(YamlNode? plugins) {
var pluginName = plugins.stringValue;
if (pluginName != null) {
enabledPluginNames = [pluginName];
} else if (plugins is YamlList) {
for (var element in plugins.nodes) {
var pluginName = element.stringValue;
if (pluginName != null) {
// Only the first plugin is supported.
enabledPluginNames = [pluginName];
return;
}
}
} else if (plugins is YamlMap) {
for (var key in plugins.nodes.keys.cast<YamlNode?>()) {
var pluginName = key.stringValue;
if (pluginName != null) {
// Only the first plugin is supported.
enabledPluginNames = [pluginName];
return;
}
}
}
}

void applyUnignorables(YamlNode? cannotIgnore) {
if (cannotIgnore is! YamlList) {
return;
Expand Down Expand Up @@ -172,6 +147,31 @@ extension on AnalysisOptionsImpl {
}
return CodeStyleOptionsImpl(this, useFormatter: useFormatter);
}

void _applyLegacyPlugins(YamlNode? plugins) {
var pluginName = plugins.stringValue;
if (pluginName != null) {
enabledLegacyPluginNames = [pluginName];
} else if (plugins is YamlList) {
for (var element in plugins.nodes) {
var pluginName = element.stringValue;
if (pluginName != null) {
// Only the first legacy plugin is supported.
enabledLegacyPluginNames = [pluginName];
return;
}
}
} else if (plugins is YamlMap) {
for (var key in plugins.nodes.keys.cast<YamlNode?>()) {
var pluginName = key.stringValue;
if (pluginName != null) {
// Only the first legacy plugin is supported.
enabledLegacyPluginNames = [pluginName];
return;
}
}
}
}
}

extension AnalysisOptionsImplExtensions on AnalysisOptionsImpl {
Expand Down Expand Up @@ -219,7 +219,7 @@ extension AnalysisOptionsImplExtensions on AnalysisOptionsImpl {

// Process plugins.
var plugins = analyzer.valueAt(AnalyzerOptions.plugins);
applyPlugins(plugins);
_applyLegacyPlugins(plugins);
}

// Process the 'code-style' option.
Expand Down
40 changes: 19 additions & 21 deletions pkg/analyzer/lib/src/dart/analysis/context_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ class ContextLocatorImpl implements ContextLocator {
root.included.add(folder);
}

var rootEnabledPlugins =
_getEnabledPlugins(location.workspace, location.optionsFile);
var rootEnabledLegacyPlugins =
_getEnabledLegacyPlugins(location.workspace, location.optionsFile);

_createContextRootsIn(
roots,
{},
folder,
excludedFolders,
root,
rootEnabledPlugins,
rootEnabledLegacyPlugins,
root.excludedGlobs,
defaultOptionsFile,
defaultPackagesFile,
Expand Down Expand Up @@ -305,7 +305,7 @@ class ContextLocatorImpl implements ContextLocator {
Folder folder,
List<Folder> excludedFolders,
ContextRoot containingRoot,
Set<String> containingRootEnabledPlugins,
Set<String> containingRootEnabledLegacyPlugins,
List<LocatedGlob> excludedGlobs,
File? optionsFile,
File? packagesFile) {
Expand All @@ -324,17 +324,15 @@ class ContextLocatorImpl implements ContextLocator {
var buildGnFile = folder.getExistingFile(file_paths.buildGn);

var localEnabledPlugins =
_getEnabledPlugins(containingRoot.workspace, localOptionsFile);
// Plugins differ only if there is an analysis_options and it contains
// a different set of plugins from the containing context.
_getEnabledLegacyPlugins(containingRoot.workspace, localOptionsFile);
// Legacy plugins differ only if there is an analysis_options and it
// contains a different set of plugins from the containing context.
var pluginsDiffer = localOptionsFile != null &&
!const SetEquality<String>()
.equals(containingRootEnabledPlugins, localEnabledPlugins);
.equals(containingRootEnabledLegacyPlugins, localEnabledPlugins);

//
// Create a context root for the given [folder] if a packages or build file
// is locally specified, or the set of enabled plugins changed.
//
// is locally specified, or the set of enabled legacy plugins changed.
if (pluginsDiffer || localPackagesFile != null || buildGnFile != null) {
if (optionsFile != null) {
localOptionsFile = optionsFile;
Expand All @@ -355,7 +353,7 @@ class ContextLocatorImpl implements ContextLocator {
containingRoot.excluded.add(folder);
roots.add(root);
containingRoot = root;
containingRootEnabledPlugins = localEnabledPlugins;
containingRootEnabledLegacyPlugins = localEnabledPlugins;
excludedGlobs = _getExcludedGlobs(root.optionsFile, workspace);
root.excludedGlobs = excludedGlobs;
}
Expand All @@ -374,7 +372,7 @@ class ContextLocatorImpl implements ContextLocator {
folder,
excludedFolders,
containingRoot,
containingRootEnabledPlugins,
containingRootEnabledLegacyPlugins,
excludedGlobs,
optionsFile,
packagesFile,
Expand All @@ -393,7 +391,7 @@ class ContextLocatorImpl implements ContextLocator {
Folder folder,
List<Folder> excludedFolders,
ContextRoot containingRoot,
Set<String> containingRootEnabledPlugins,
Set<String> containingRootEnabledLegacyPlugins,
List<LocatedGlob> excludedGlobs,
File? optionsFile,
File? packagesFile) {
Expand Down Expand Up @@ -437,7 +435,7 @@ class ContextLocatorImpl implements ContextLocator {
child,
excludedFolders,
containingRoot,
containingRootEnabledPlugins,
containingRootEnabledLegacyPlugins,
excludedGlobs,
optionsFile,
packagesFile,
Expand Down Expand Up @@ -522,9 +520,9 @@ class ContextLocatorImpl implements ContextLocator {
return null;
}

/// Gets the set of enabled plugins for [optionsFile]m taking into account
/// any includes.
Set<String> _getEnabledPlugins(Workspace workspace, File? optionsFile) {
/// Gets the set of enabled legacy plugins for [optionsFile], taking into
/// account any includes.
Set<String> _getEnabledLegacyPlugins(Workspace workspace, File? optionsFile) {
if (optionsFile == null) {
return const {};
}
Expand All @@ -536,10 +534,10 @@ class ContextLocatorImpl implements ContextLocator {
var optionsYaml = provider.getOptionsFromFile(optionsFile);
options.applyOptions(optionsYaml);

return options.enabledPluginNames.toSet();
return options.enabledLegacyPluginNames.toSet();
} catch (_) {
// No plugins will be enabled if the file doesn't parse or cannot be read
// for any reason.
// No legacy plugins will be enabled if the file doesn't parse or cannot
// be read for any reason.
return {};
}
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,16 @@ class AnalysisDriver {
return libraryContext.elementFactory.analysisSession;
}

/// Return a set of the names of all the plugins enabled in analysis options
/// in this driver.
Set<String> get enabledPluginNames {
// We currently only support plugins enabled at the very root of a context
// (and we create contexts for any analysis options that changes plugins
// from its parent context).
/// The set of legacy plugin names enabled in analysis options in this driver.
Set<String> get enabledLegacyPluginNames {
// We currently only support legacy plugins enabled at the very root of a
// context (and we create contexts for any analysis options that changes
// plugins from its parent context).
var rootOptionsFile = analysisContext?.contextRoot.optionsFile;
return rootOptionsFile != null
? getAnalysisOptionsForFile(rootOptionsFile).enabledPluginNames.toSet()
? getAnalysisOptionsForFile(rootOptionsFile)
.enabledLegacyPluginNames
.toSet()
: const {};
}

Expand Down
16 changes: 10 additions & 6 deletions pkg/analyzer/lib/src/generated/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
FeatureSet nonPackageFeatureSet = ExperimentStatus();

@override
List<String> enabledPluginNames = const <String>[];
List<String> enabledLegacyPluginNames = const <String>[];

/// Return `true` if timing data should be gathered during execution.
bool enableTiming = false;
Expand Down Expand Up @@ -254,7 +254,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
AnalysisOptionsImpl.from(AnalysisOptions options) {
codeStyleOptions = options.codeStyleOptions;
contextFeatures = options.contextFeatures;
enabledPluginNames = options.enabledPluginNames;
enabledLegacyPluginNames = options.enabledLegacyPluginNames;
errorProcessors = options.errorProcessors;
excludePatterns = options.excludePatterns;
lint = options.lint;
Expand All @@ -279,6 +279,10 @@ class AnalysisOptionsImpl implements AnalysisOptions {
nonPackageFeatureSet = featureSet;
}

@override
@Deprecated("Use 'enabledLegacyPluginNames' instead")
List<String> get enabledPluginNames => enabledLegacyPluginNames;

@override
List<ErrorProcessor> get errorProcessors =>
_errorProcessors ??= const <ErrorProcessor>[];
Expand Down Expand Up @@ -353,10 +357,10 @@ class AnalysisOptionsImpl implements AnalysisOptions {
buffer.addString(lintRule.name);
}

// Append plugin names.
buffer.addInt(enabledPluginNames.length);
for (String enabledPluginName in enabledPluginNames) {
buffer.addString(enabledPluginName);
// Append legacy plugin names.
buffer.addInt(enabledLegacyPluginNames.length);
for (var enabledLegacyPluginName in enabledLegacyPluginNames) {
buffer.addString(enabledLegacyPluginName);
}

// Hash and convert to Uint32List.
Expand Down
Loading

0 comments on commit b141611

Please sign in to comment.