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

Merge dev16.0.x to master #30744

Merged
merged 4 commits into from
Oct 26, 2018
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
4 changes: 4 additions & 0 deletions build/Targets/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Progression.Common"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Progression.Interfaces"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.RemoteControl"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.15.0"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Design"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Framework"/>
Expand All @@ -325,6 +326,7 @@
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.15.0.DesignTime"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.15.7.DesignTime"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Telemetry"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Text.Data"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Text.Logic"/>
Expand All @@ -334,6 +336,8 @@
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.TextManager.Interop.12.0"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.TextManager.Interop.12.1.DesignTime"/>
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Utilities"/>
<PrivateVisualStudioPackage Include="Microsoft.VSSDK.BuildTools"/>
<PrivateVisualStudioPackage Include="Newtonsoft.Json"/>
<PrivateVisualStudioPackage Include="NuGet.VisualStudio"/>
<PrivateVisualStudioPackage Include="StreamJsonRpc"/>
<PrivateVisualStudioPackage Include="VSLangProj"/>
Expand Down
17 changes: 0 additions & 17 deletions build/Targets/RepoToolset/Version.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,4 @@
<AssemblyVersion Condition="'$(AssemblyVersion)' == ''">42.42.42.42</AssemblyVersion>
</PropertyGroup>
</Target>

<!--
Append short commit SHA to PackageVersion.
-->
<Target Name="GetPackageVersion"
BeforeTargets="GenerateNuSpec"
DependsOnTargets="InitializeSourceControlInformation"
Condition="'$(DotNetFinalVersionKind)' != 'release'">
<PropertyGroup>
<_ShortSha>$(SourceRevisionId)</_ShortSha>
<_ShortSha Condition="$(SourceRevisionId.Length) &gt; 7">$(SourceRevisionId.Substring(0, 8))</_ShortSha>

<PackageVersion Condition="'$(SemanticVersioningV1)' != 'true'">$(Version)+$(_ShortSha)</PackageVersion>
<PackageVersion Condition="'$(SemanticVersioningV1)' == 'true'">$(Version)-$(_ShortSha)</PackageVersion>
</PropertyGroup>
</Target>

</Project>
2 changes: 1 addition & 1 deletion build/Targets/RepoToolset/Workarounds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
-->
<Target Name="InitializeStandardNuspecProperties"
BeforeTargets="GenerateNuspec"
DependsOnTargets="GetPackageVersion;_InitializeNuspecRepositoryInformationPropertiesWorkaround"
DependsOnTargets="_InitializeNuspecRepositoryInformationPropertiesWorkaround"
Condition="'$(NuspecFile)' != '' and '$(NuspecProperties)' == ''">

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,83 +1,20 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
using Roslyn.Utilities;
using VSCommanding = Microsoft.VisualStudio.Commanding;

namespace Microsoft.CodeAnalysis.Editor.Implementation.Formatting
{
internal partial class FormatCommandHandler : ForegroundThreadAffinitizedObject
internal partial class FormatCommandHandler
{
private const string s_experimentName = "CleanupOn";

public VSCommanding.CommandState GetCommandState(FormatDocumentCommandArgs args)
{
return GetCommandState(args.SubjectBuffer);
}

private void ShowGoldBarForCodeCleanupConfiguration(Document document, bool performAdditionalCodeCleanupDuringFormatting)
{
AssertIsForeground();
Logger.Log(FunctionId.CodeCleanupInfobar_BarDisplayed, KeyValueLogMessage.NoProperty);

var workspace = document.Project.Solution.Workspace;

// if info bar was shown already in same VS session, no need to show it again
if (workspace.Options.GetOption(CodeCleanupOptions.CodeCleanupInfoBarShown, document.Project.Language))
{
return;
}

// set as infobar shown so that we never show it again in same VS session. we might show it again
// in other VS sessions if it is not explicitly configured yet
workspace.Options = workspace.Options.WithChangedOption(
CodeCleanupOptions.CodeCleanupInfoBarShown, document.Project.Language, value: true);

var optionPageService = document.GetLanguageService<IOptionPageService>();
var infoBarService = document.Project.Solution.Workspace.Services.GetRequiredService<IInfoBarService>();

// wording for the Code Cleanup infobar will be different depending on if the feature is enabled
var infoBarMessage = performAdditionalCodeCleanupDuringFormatting
? EditorFeaturesResources.Format_document_performed_additional_cleanup
: EditorFeaturesResources.Code_cleanup_is_not_configured;

var configButtonText = performAdditionalCodeCleanupDuringFormatting
? EditorFeaturesResources.Change_configuration
: EditorFeaturesResources.Configure_it_now;

infoBarService.ShowInfoBarInGlobalView(
infoBarMessage,
new InfoBarUI(configButtonText,
kind: InfoBarUI.UIKind.Button,
() =>
{
Logger.Log(FunctionId.CodeCleanupInfobar_ConfigureNow, KeyValueLogMessage.NoProperty);
optionPageService.ShowFormattingOptionPage();
}),
new InfoBarUI(EditorFeaturesResources.Do_not_show_this_message_again,
kind: InfoBarUI.UIKind.Button,
() =>
{
Logger.Log(FunctionId.CodeCleanupInfobar_NeverShowCodeCleanupInfoBarAgain, KeyValueLogMessage.NoProperty);
workspace.Options = workspace.Options.WithChangedOption(
CodeCleanupOptions.NeverShowCodeCleanupInfoBarAgain, document.Project.Language, value: true);
}));
}

public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionContext context)
{
if (!CanExecuteCommand(args.SubjectBuffer))
Expand All @@ -91,109 +28,18 @@ public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionConte
return false;
}

context.OperationContext.TakeOwnership();

_waitIndicator.Wait(
EditorFeaturesResources.Formatting_document,
EditorFeaturesResources.Formatting_document,
allowCancel: true,
showProgress: true,
c =>
{
var docOptions = document.GetOptionsAsync(c.CancellationToken).WaitAndGetResult(c.CancellationToken);
using (Logger.LogBlock(FunctionId.FormatDocument, CodeCleanupLogMessage.Create(docOptions), c.CancellationToken))
using (var transaction = new CaretPreservingEditTransaction(
EditorFeaturesResources.Formatting, args.TextView, _undoHistoryRegistry, _editorOperationsFactoryService))
{
var codeCleanupService = document.GetLanguageService<ICodeCleanupService>();
if (codeCleanupService == null)
{
Format(args.TextView, document, selectionOpt: null, c.CancellationToken);
}
else
{
CodeCleanupOrFormat(args, document, codeCleanupService, c.ProgressTracker, c.CancellationToken);
}

transaction.Complete();
}
});

return true;
}

private void CodeCleanupOrFormat(
FormatDocumentCommandArgs args, Document document, ICodeCleanupService codeCleanupService,
IProgressTracker progressTracker, CancellationToken cancellationToken)
{
var workspace = document.Project.Solution.Workspace;
var isFeatureTurnedOnThroughABTest = TurnOnCodeCleanupForGroupBIfInABTest(document, workspace);
var performAdditionalCodeCleanupDuringFormatting = workspace.Options.GetOption(CodeCleanupOptions.PerformAdditionalCodeCleanupDuringFormatting, document.Project.Language);

// if feature is turned on through AB test, we need to show the Gold bar even if they set NeverShowCodeCleanupInfoBarAgain == true before
if (isFeatureTurnedOnThroughABTest ||
!workspace.Options.GetOption(CodeCleanupOptions.NeverShowCodeCleanupInfoBarAgain, document.Project.Language))
{
// Show different gold bar text depends on PerformAdditionalCodeCleanupDuringFormatting value
ShowGoldBarForCodeCleanupConfiguration(document, performAdditionalCodeCleanupDuringFormatting);
}

if (performAdditionalCodeCleanupDuringFormatting)
{
// Start with a single progress item, which is the one to actually apply
// the changes.
progressTracker.AddItems(1);

// Code cleanup
var oldDoc = document;

var codeCleanupChanges = GetCodeCleanupAndFormatChangesAsync(
document, codeCleanupService, progressTracker, cancellationToken).WaitAndGetResult(cancellationToken);

if (codeCleanupChanges != null && codeCleanupChanges.Length > 0)
{
progressTracker.Description = EditorFeaturesResources.Applying_changes;
ApplyChanges(oldDoc, codeCleanupChanges.ToList(), selectionOpt: null, cancellationToken);
}

progressTracker.ItemCompleted();
}
else
var formattingService = document.GetLanguageService<IEditorFormattingService>();
if (formattingService == null || !formattingService.SupportsFormatDocument)
{
Format(args.TextView, document, selectionOpt: null, cancellationToken);
return false;
}
}

private static bool TurnOnCodeCleanupForGroupBIfInABTest(Document document, Workspace workspace)
{
// If the feature is OFF and the feature options have not yet been Enabled to their assigned flight, do so now
// Do not reset the options if we already set it for them once, so options won't get reset if user manually disabled it already after it is enabled by the flight
if (!workspace.Options.GetOption(CodeCleanupOptions.PerformAdditionalCodeCleanupDuringFormatting, document.Project.Language)
&& !workspace.Options.GetOption(CodeCleanupABTestOptions.SettingIsAlreadyUpdatedByExperiment))
using (context.OperationContext.AddScope(allowCancellation: true, EditorFeaturesResources.Formatting_document))
{
var experimentationService = document.Project.Solution.Workspace.Services.GetService<IExperimentationService>();

if (experimentationService != null
&& experimentationService.IsExperimentEnabled(s_experimentName))
{
workspace.Options = workspace.Options.WithChangedOption(CodeCleanupABTestOptions.SettingIsAlreadyUpdatedByExperiment, true)
.WithChangedOption(CodeCleanupOptions.PerformAdditionalCodeCleanupDuringFormatting, document.Project.Language, true);
return true;
}
Format(args.TextView, document, null, context.OperationContext.UserCancellationToken);
}

return false;
}

private async Task<ImmutableArray<TextChange>> GetCodeCleanupAndFormatChangesAsync(
Document document, ICodeCleanupService codeCleanupService,
IProgressTracker progressTracker, CancellationToken cancellationToken)
{
var newDoc = await codeCleanupService.CleanupAsync(
document, progressTracker, cancellationToken).ConfigureAwait(false);

var changes = await newDoc.GetTextChangesAsync(document, cancellationToken).ConfigureAwait(false);
return changes.ToImmutableArrayOrEmpty();
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,17 @@ internal partial class FormatCommandHandler :
{
private readonly ITextUndoHistoryRegistry _undoHistoryRegistry;
private readonly IEditorOperationsFactoryService _editorOperationsFactoryService;
private readonly IWaitIndicator _waitIndicator;

public string DisplayName => EditorFeaturesResources.Automatic_Formatting;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public FormatCommandHandler(
IThreadingContext threadingContext,
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService,
IWaitIndicator waitIndicator)
: base(threadingContext)
IEditorOperationsFactoryService editorOperationsFactoryService)
{
_undoHistoryRegistry = undoHistoryRegistry;
_editorOperationsFactoryService = editorOperationsFactoryService;
_waitIndicator = waitIndicator;
}

private void Format(ITextView textView, Document document, TextSpan? selectionOpt, CancellationToken cancellationToken)
Expand All @@ -78,8 +73,6 @@ private void Format(ITextView textView, Document document, TextSpan? selectionOp

private void ApplyChanges(Document document, IList<TextChange> changes, TextSpan? selectionOpt, CancellationToken cancellationToken)
{
AssertIsForeground();

if (selectionOpt.HasValue)
{
var ruleFactory = document.Project.Solution.Workspace.Services.GetService<IHostDependentFormattingRuleFactoryService>();
Expand Down
12 changes: 0 additions & 12 deletions src/Features/Core/Portable/CodeCleanup/CodeCleanupABTestOptions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,6 @@
<CheckBox x:Name="FormatOnPasteCheckBox" x:Uid="FormatOnPasteCheckBox" />
</StackPanel>
</GroupBox>
<GroupBox x:Name="FormatDocumentSettingsGroupBox" x:Uid="FormatDocumentSettingsGroupBox" >
<StackPanel>
<CheckBox x:Name="AllCSharpFormattingRulesCheckBox" x:Uid="AllCSharpFormattingRulesCheckBox" IsEnabled="False" IsChecked="True"/>
<CheckBox x:Name="PerformAdditionalCodeCleanupDuringFormattingCheckBox" x:Uid="PerformAdditionalCodeCleanupDuringFormattingCheckBox" />
<StackPanel Margin="15, 0, 0, 0" IsEnabled="{Binding ElementName=PerformAdditionalCodeCleanupDuringFormattingCheckBox, Path=IsChecked}">
<CheckBox x:Name="RemoveUnusedUsingsCheckBox" x:Uid="RemoveUnusedUsingsCheckBox" />
<CheckBox x:Name="SortUsingsCheckBox" x:Uid="SortUsingsCheckBox" />
<CheckBox x:Name="AddRemoveBracesForSingleLineControlStatementsCheckBox" x:Uid="AddRemoveBracesForSingleLineControlStatementsCheckBox" />
<CheckBox x:Name="AddAccessibilityModifiersCheckBox" x:Uid="AddAccessibilityModifiersCheckBox" />
<CheckBox x:Name="SortAccessibilityModifiersCheckBox" x:Uid="SortAccessibilityModifiersCheckBox" />
<CheckBox x:Name="ApplyExpressionBlockBodyPreferencesCheckBox" x:Uid="ApplyExpressionBlockBodyPreferencesCheckBox" />
<CheckBox x:Name="ApplyImplicitExplicitTypePreferencesCheckBox" x:Uid="ApplyImplicitExplicitTypePreferencesCheckBox" />
<CheckBox x:Name="ApplyInlineOutVariablePreferencesCheckBox" x:Uid="ApplyInlineOutVariablePreferencesCheckBox" />
<CheckBox x:Name="ApplyLanguageFrameworkTypePreferencesCheckBox" x:Uid="ApplyLanguageFrameworkTypePreferencesCheckBox" />
<CheckBox x:Name="ApplyObjectCollectionInitializationPreferencesCheckBox" x:Uid="ApplyObjectCollectionInitializationPreferencesCheckBox" />
<CheckBox x:Name="ApplyThisQualificationPreferencesCheckBox" x:Uid="ApplyThisQualificationPreferencesCheckBox" />
<CheckBox x:Name="MakePrivateFieldReadonlyWhenPossibleCheckBox" x:Uid="MakePrivateFieldReadonlyWhenPossibleCheckBox" />
<CheckBox x:Name="RemoveUnnecessaryCastsCheckBox" x:Uid="RemoveUnnecessaryCastsCheckBox" />
<CheckBox x:Name="RemoveUnusedVariablesCheckBox" x:Uid="RemoveUnusedVariablesCheckBox" />
</StackPanel>
</StackPanel>
</GroupBox>
</StackPanel>
</ScrollViewer>
</options:AbstractOptionPageControl>
Loading