Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable add usings on paste by default #61299

Merged
merged 2 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CommandState GetCommandState(PasteCommandArgs args, Func<CommandState> 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;
Expand Down
12 changes: 9 additions & 3 deletions src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ public FeatureOnOffOptions()
FeatureName, "NavigateAsynchronously", defaultValue: true,
storageLocation: new RoamingProfileStorageLocation("TextEditor.NavigateAsynchronously"));

public static readonly PerLanguageOption2<bool?> AddImportsOnPaste = new(
FeatureName, "AddImportsOnPaste", defaultValue: null,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste"));
/// <summary>
/// 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).
/// </summary>
public static readonly PerLanguageOption2<bool> AddImportsOnPaste = new(
FeatureName, "AddImportsOnPaste", defaultValue: true,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.AddImportsOnPaste2"));
ryzngard marked this conversation as resolved.
Show resolved Hide resolved

public static readonly Option2<bool?> OfferRemoveUnusedReferences = new(
FeatureName, "OfferRemoveUnusedReferences", defaultValue: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IGlobalOptionService>(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down