From af2fa54fae83c70b8c080068b57e587f5d5262ce Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Fri, 30 Jul 2021 15:42:46 -0700 Subject: [PATCH] Disable add usings on paste by default --- .../AbstractAddImportsPasteCommandHandler.cs | 15 +++------------ .../Options/AdvancedOptionPageControl.xaml.cs | 6 +++--- .../CSharp/CSharpAddMissingUsingsOnPaste.cs | 3 +-- .../Options/AdvancedOptionPageControl.xaml.vb | 6 +++--- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/EditorFeatures/Core/Implementation/AddImports/AbstractAddImportsPasteCommandHandler.cs b/src/EditorFeatures/Core/Implementation/AddImports/AbstractAddImportsPasteCommandHandler.cs index 8cef7069e3f07..7d6b67e4bb173 100644 --- a/src/EditorFeatures/Core/Implementation/AddImports/AbstractAddImportsPasteCommandHandler.cs +++ b/src/EditorFeatures/Core/Implementation/AddImports/AbstractAddImportsPasteCommandHandler.cs @@ -43,8 +43,8 @@ public void ExecuteCommand(PasteCommandArgs args, Action nextCommandHandler, Com // Check that the feature is enabled before doing any work var optionValue = args.SubjectBuffer.GetOptionalFeatureOnOffOption(FeatureOnOffOptions.AddImportsOnPaste); - // If the feature is explicitly disabled we can exit early - if (optionValue.HasValue && !optionValue.Value) + // If the feature is not explicitly enabled we can exit early + if (optionValue != true) { nextCommandHandler(); return; @@ -71,7 +71,7 @@ public void ExecuteCommand(PasteCommandArgs args, Action nextCommandHandler, Com try { - ExecuteCommandWorker(args, executionContext, optionValue, trackingSpan); + ExecuteCommandWorker(args, executionContext, trackingSpan); } catch (OperationCanceledException) { @@ -84,7 +84,6 @@ public void ExecuteCommand(PasteCommandArgs args, Action nextCommandHandler, Com private void ExecuteCommandWorker( PasteCommandArgs args, CommandExecutionContext executionContext, - bool? optionValue, ITrackingSpan trackingSpan) { if (!args.SubjectBuffer.CanApplyChangeDocumentToWorkspace()) @@ -114,14 +113,6 @@ private void ExecuteCommandWorker( return; } - // Enable by default unless the user has explicitly disabled in the settings - var disabled = optionValue.HasValue && !optionValue.Value; - - if (disabled) - { - return; - } - using var _ = executionContext.OperationContext.AddScope(allowCancellation: true, DialogText); var cancellationToken = executionContext.OperationContext.UserCancellationToken; diff --git a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs index 31d71b6eb1cc9..2466678c2557b 100644 --- a/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs +++ b/src/VisualStudio/CSharp/Impl/Options/AdvancedOptionPageControl.xaml.cs @@ -62,10 +62,10 @@ public AdvancedOptionPageControl(OptionStore optionStore, IComponentModel compon BindToOption(SuggestForTypesInNuGetPackages, SymbolSearchOptions.SuggestForTypesInNuGetPackages, LanguageNames.CSharp); BindToOption(AddUsingsOnPaste, FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.CSharp, () => { - // This option used to be backed by an experimentation flag but is now enabled by default. + // 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 be enabled by default - return true; + // but if the option was stored as null we want it to respect this default + return false; }); BindToOption(Split_string_literals_on_enter, SplitStringLiteralOptions.Enabled, LanguageNames.CSharp); diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs index 1e43702f1f496..c989728db5b4d 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs @@ -60,7 +60,7 @@ static void Main(string[] args) } [WpfFact, Trait(Traits.Feature, Traits.Features.AddMissingImports)] - public void VerifyEnabledWithNull() + public void VerifyDisabledWithNull() { var project = new Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils.Project(ProjectName); VisualStudio.SolutionExplorer.AddFile(project, "Example.cs", contents: @" @@ -85,7 +85,6 @@ static void Main(string[] args) VisualStudio.Editor.Verify.TextContains(@" using System; -using System.Threading.Tasks; class Program { diff --git a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb index 3b6514a1bd682..949c832f0a7b7 100644 --- a/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb +++ b/src/VisualStudio/VisualBasic/Impl/Options/AdvancedOptionPageControl.xaml.vb @@ -66,10 +66,10 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options BindToOption(SuggestForTypesInNuGetPackages, SymbolSearchOptions.SuggestForTypesInNuGetPackages, LanguageNames.VisualBasic) BindToOption(AddMissingImportsOnPaste, FeatureOnOffOptions.AddImportsOnPaste, LanguageNames.VisualBasic, Function() - ' This option used to be backed by an experimentation flag but Is now enabled by default. + ' 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 be enabled by default - Return True + ' but if the option was stored as null we want it to respect this default + Return False End Function) ' Highlighting