44
55import  'dart:typed_data' ;
66
7+ import  'package:_fe_analyzer_shared/src/base/analyzer_public_api.dart' ;
78import  'package:analyzer/dart/analysis/analysis_options.dart' ;
89import  'package:analyzer/dart/analysis/code_style_options.dart' ;
910import  'package:analyzer/dart/analysis/features.dart' ;
@@ -599,6 +600,20 @@ class AnalysisOptionsImpl implements AnalysisOptions {
599600      )) {
600601        buffer.addString (pluginConfiguration.name);
601602        buffer.addBool (pluginConfiguration.isEnabled);
603+         switch  (pluginConfiguration.source) {
604+           case  GitPluginSource  source: 
605+             buffer.addString (source._url);
606+             if  (source._path case  var  path? ) {
607+               buffer.addString (path);
608+             }
609+             if  (source._ref case  var  ref? ) {
610+               buffer.addString (ref);
611+             }
612+           case  PathPluginSource  source: 
613+             buffer.addString (source._path);
614+           case  VersionedPluginSource  source: 
615+             buffer.addString (source._constraint);
616+         }
602617        buffer.addInt (pluginConfiguration.diagnosticConfigs.length);
603618        for  (var  diagnosticConfig
604619            in  pluginConfiguration.diagnosticConfigs.values) {
@@ -660,6 +675,83 @@ class AnalysisOptionsImpl implements AnalysisOptions {
660675  }
661676}
662677
678+ @AnalyzerPublicApi (
679+   message:  'exported by lib/dart/analysis/analysis_options.dart' ,
680+ )
681+ final  class  GitPluginSource  implements  PluginSource  {
682+   final  String  _url;
683+ 
684+   final  String ?  _path;
685+ 
686+   final  String ?  _ref;
687+ 
688+   GitPluginSource ({required  String  url, String ?  path, String ?  ref})
689+     :  _url =  url,
690+       _path =  path,
691+       _ref =  ref;
692+ 
693+   @override 
694+   String  toYaml ({required  String  name}) {
695+     var  buffer =  StringBuffer ()
696+       ..writeln ('  $name :' )
697+       ..writeln ('    git:' )
698+       ..writeln ('      url: $_url ' );
699+     if  (_ref !=  null ) {
700+       buffer.writeln ('      ref: $_ref ' );
701+     }
702+     if  (_path !=  null ) {
703+       buffer.writeln ('      path: $_path ' );
704+     }
705+     return  buffer.toString ();
706+   }
707+ }
708+ 
709+ @AnalyzerPublicApi (
710+   message:  'exported by lib/dart/analysis/analysis_options.dart' ,
711+ )
712+ final  class  PathPluginSource  implements  PluginSource  {
713+   final  String  _path;
714+ 
715+   PathPluginSource ({required  String  path}) :  _path =  path;
716+ 
717+   @override 
718+   String  toYaml ({required  String  name}) => 
719+       ''' 
720+   $name : 
721+     path: $_path  
722+ ''' ;
723+ }
724+ 
725+ /// The configuration of a Dart Analysis Server plugin, as specified by 
726+ /// analysis options. 
727+ @AnalyzerPublicApi (
728+   message:  'exported by lib/dart/analysis/analysis_options.dart' ,
729+ )
730+ final  class  PluginConfiguration  {
731+   /// The name of the plugin being configured. 
732+    final  String  name;
733+ 
734+   /// The source of the plugin being configured. 
735+    final  PluginSource  source;
736+ 
737+   /// The list of specified [DiagnosticConfig] s. 
738+    // ignore: analyzer_public_api_bad_type 
739+   final  Map <String , DiagnosticConfig > diagnosticConfigs;
740+ 
741+   /// Whether the plugin is enabled. 
742+    final  bool  isEnabled;
743+ 
744+   // ignore: analyzer_public_api_bad_type 
745+   PluginConfiguration ({
746+     required  this .name,
747+     required  this .source,
748+     this .diagnosticConfigs =  const  {},
749+     this .isEnabled =  true ,
750+   });
751+ 
752+   String  sourceYaml () =>  source.toYaml (name:  name);
753+ }
754+ 
663755/// The analysis options for plugins, as specified in the top-level `plugins`  
664756/// section. 
665757final  class  PluginsOptions  {
@@ -675,6 +767,36 @@ final class PluginsOptions {
675767  });
676768}
677769
770+ /// A description of the source of a plugin. 
771+ /// 
772+ /// We support all of the source formats documented at 
773+ /// https://dart.dev/tools/pub/dependencies. 
774+ @AnalyzerPublicApi (
775+   message:  'exported by lib/dart/analysis/analysis_options.dart' ,
776+ )
777+ sealed  class  PluginSource  {
778+   /// Returns the YAML-formatted source, using [name]  as a key, for writing into 
779+   /// a pubspec 'dependencies' section. 
780+    String  toYaml ({required  String  name});
781+ }
782+ 
783+ /// A plugin source using a version constraint, hosted either at pub.dev or 
784+ /// another host. 
785+ // TODO(srawlins): Support a different 'hosted' URL. 
786+ @AnalyzerPublicApi (
787+   message:  'exported by lib/dart/analysis/analysis_options.dart' ,
788+ )
789+ final  class  VersionedPluginSource  implements  PluginSource  {
790+   /// The specified version constraint. 
791+    final  String  _constraint;
792+ 
793+   VersionedPluginSource ({required  String  constraint})
794+     :  _constraint =  constraint;
795+ 
796+   @override 
797+   String  toYaml ({required  String  name}) =>  '  $name : $_constraint \n ' ;
798+ }
799+ 
678800extension  on  YamlNode ?  {
679801  bool ?  get  boolValue {
680802    var  self =  this ;
0 commit comments