From 993027c3ac233627ba91c49ebc3e8202436ed7f4 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 12 May 2022 20:14:24 -0700 Subject: [PATCH 1/2] Enable add usings on paste by default --- .../AbstractAddImportsPasteCommandHandler.cs | 2 +- .../Shared/Options/FeatureOnOffOptions.cs | 6 +-- .../Options/AdvancedOptionPageControl.xaml.cs | 8 +--- .../CSharp/CSharpAddMissingUsingsOnPaste.cs | 39 ------------------- .../Options/AdvancedOptionPageControl.xaml.vb | 8 +--- .../AutomationObject.OnOff.vb | 4 +- 6 files changed, 8 insertions(+), 59 deletions(-) diff --git a/src/EditorFeatures/Core/AddImports/AbstractAddImportsPasteCommandHandler.cs b/src/EditorFeatures/Core/AddImports/AbstractAddImportsPasteCommandHandler.cs index 06c9643439d34..fd215741024cf 100644 --- a/src/EditorFeatures/Core/AddImports/AbstractAddImportsPasteCommandHandler.cs +++ b/src/EditorFeatures/Core/AddImports/AbstractAddImportsPasteCommandHandler.cs @@ -57,7 +57,7 @@ public CommandState GetCommandState(PasteCommandArgs args, Func ne public void ExecuteCommand(PasteCommandArgs args, Action nextCommandHandler, CommandExecutionContext executionContext) { // If the feature is not explicitly enabled we can exit early - if (_globalOptions.GetOption(FeatureOnOffOptions.AddImportsOnPaste, args.SubjectBuffer.GetLanguageName()) != true) + if (!_globalOptions.GetOption(FeatureOnOffOptions.AddImportsOnPaste, args.SubjectBuffer.GetLanguageName())) { nextCommandHandler(); return; diff --git a/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs b/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs index f54e8a00d40ab..6a0abc2be8873 100644 --- a/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs +++ b/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs @@ -94,9 +94,9 @@ public FeatureOnOffOptions() FeatureName, "NavigateAsynchronously", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.NavigateAsynchronously")); - public static readonly PerLanguageOption2 AddImportsOnPaste = new( - FeatureName, "AddImportsOnPaste", defaultValue: null, - storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste")); + public static readonly PerLanguageOption2 AddImportsOnPaste = new( + FeatureName, "AddImportsOnPaste", defaultValue: true, + storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste2")); public static readonly Option2 OfferRemoveUnusedReferences = new( FeatureName, "OfferRemoveUnusedReferences", defaultValue: true, diff --git a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs index ee2694786184a..40e6c100acd26 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs @@ -75,13 +75,7 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(SeparateImportGroups, GenerationOptions.SeparateImportDirectiveGroups, LanguageNames.CSharp); BindToOption(SuggestForTypesInReferenceAssemblies, SymbolSearchOptionsStorage.SearchReferenceAssemblies, LanguageNames.CSharp); BindToOption(SuggestForTypesInNuGetPackages, SymbolSearchOptionsStorage.SearchNuGetPackages, LanguageNames.CSharp); - BindToOption(AddUsingsOnPaste, FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.CSharp, () => - { - // This option used to be backed by an experimentation flag but is no longer. - // Having the option still a bool? keeps us from running into storage related issues, - // but if the option was stored as null we want it to respect this default - return false; - }); + BindToOption(AddUsingsOnPaste, FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.CSharp); // Quick Actions BindToOption(ComputeQuickActionsAsynchronouslyExperimental, SuggestionsOptions.Asynchronous, () => diff --git a/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs index 2a2cbc5bad2a6..304eadde5e4d0 100644 --- a/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs @@ -57,45 +57,6 @@ static void Main(string[] args) AssertEx.EqualOrDiff(@" using System; -class Program -{ - static void Main(string[] args) - { - } - - Task DoThingAsync() => Task.CompletedTask; -}", await TestServices.Editor.GetTextAsync(HangMitigatingCancellationToken)); - } - - [IdeFact] - public async Task VerifyDisabledWithNull() - { - var project = ProjectName; - await TestServices.SolutionExplorer.AddFileAsync(project, "Example.cs", contents: @" -public class Example -{ -} -", cancellationToken: HangMitigatingCancellationToken); - await SetUpEditorAsync(@" -using System; - -class Program -{ - static void Main(string[] args) - { - } - - $$ -}", HangMitigatingCancellationToken); - - var globalOptions = await TestServices.Shell.GetComponentModelServiceAsync(HangMitigatingCancellationToken); - globalOptions.SetGlobalOption(new OptionKey(FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.CSharp), null); - - await PasteAsync(@"Task DoThingAsync() => Task.CompletedTask;", HangMitigatingCancellationToken); - - AssertEx.EqualOrDiff(@" -using System; - class Program { static void Main(string[] args) diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb index 386d61981a952..b9611c52bbf4e 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb @@ -67,13 +67,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options BindToOption(SeparateImportGroups, GenerationOptions.SeparateImportDirectiveGroups, LanguageNames.VisualBasic) BindToOption(SuggestForTypesInReferenceAssemblies, SymbolSearchOptionsStorage.SearchReferenceAssemblies, LanguageNames.VisualBasic) BindToOption(SuggestForTypesInNuGetPackages, SymbolSearchOptionsStorage.SearchNuGetPackages, LanguageNames.VisualBasic) - BindToOption(AddMissingImportsOnPaste, FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.VisualBasic, - Function() - ' This option used to be backed by an experimentation flag but Is no longer. - ' Having the option still a bool? keeps us from running into storage related issues, - ' but if the option was stored as null we want it to respect this default - Return False - End Function) + BindToOption(AddMissingImportsOnPaste, FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.VisualBasic) ' Quick Actions BindToOption(ComputeQuickActionsAsynchronouslyExperimental, SuggestionsOptions.Asynchronous, diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.OnOff.vb b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.OnOff.vb index 07ce66fec3b03..26bf099e64884 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.OnOff.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AutomationObject/AutomationObject.OnOff.vb @@ -125,11 +125,11 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options End Set End Property - Public Property AddImportsOnPaste As Integer + Public Property AddImportsOnPaste As Boolean Get Return GetBooleanOption(FeatureOnOffOptions.AddImportsOnPaste) End Get - Set(value As Integer) + Set(value As Boolean) SetBooleanOption(FeatureOnOffOptions.AddImportsOnPaste, value) End Set End Property From ce24998452b8dc3c7f6481eac4e7a26089fae9eb Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Thu, 12 May 2022 20:21:31 -0700 Subject: [PATCH 2/2] Add comment explaining change in storage location and suffix --- .../Core/Shared/Options/FeatureOnOffOptions.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs b/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs index 6a0abc2be8873..32d34894b342a 100644 --- a/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs +++ b/src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs @@ -94,6 +94,12 @@ public FeatureOnOffOptions() FeatureName, "NavigateAsynchronously", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.NavigateAsynchronously")); + /// + /// This option was previously "bool?" to accomodate different supported defaults + /// that were being provided via remote settings. The feature has stabalized and moved + /// to on by default, so the storage location was changed to + /// TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste2 (note the 2 suffix). + /// public static readonly PerLanguageOption2 AddImportsOnPaste = new( FeatureName, "AddImportsOnPaste", defaultValue: true, storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste2"));