未验证 提交 5011213d 编写于 作者: D David Poeschl 提交者: GitHub

Merge pull request #28537 from dotnet/merges/dev15.8.x-to-dev15.9.x

Merge dev15.8.x to dev15.9.x
......@@ -8,6 +8,8 @@
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
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;
......@@ -29,6 +31,7 @@ public VSCommanding.CommandState GetCommandState(FormatDocumentCommandArgs args)
private void ShowGoldBarForCodeCleanupConfigurationIfNeeded(Document document)
{
AssertIsForeground();
Logger.Log(FunctionId.CodeCleanupInfobar_BarDisplayed, KeyValueLogMessage.NoProperty);
var workspace = document.Project.Solution.Workspace;
......@@ -53,12 +56,14 @@ private void ShowGoldBarForCodeCleanupConfigurationIfNeeded(Document document)
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);
}));
......@@ -78,6 +83,7 @@ public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionConte
}
context.OperationContext.TakeOwnership();
_waitIndicator.Wait(
EditorFeaturesResources.Formatting_document,
EditorFeaturesResources.Formatting_document,
......@@ -85,19 +91,20 @@ public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionConte
showProgress: true,
c =>
{
var cancellationToken = context.OperationContext.UserCancellationToken;
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, cancellationToken);
Format(args.TextView, document, selectionOpt: null, c.CancellationToken);
}
else
{
CodeCleanupOrFormat(args, document, c.ProgressTracker, cancellationToken);
CodeCleanupOrFormat(args, document, c.ProgressTracker, c.CancellationToken);
}
transaction.Complete();
......@@ -141,7 +148,7 @@ public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionConte
}
private async Task<ImmutableArray<TextChange>> GetCodeCleanupAndFormatChangesAsync(
Document document, ICodeCleanupService codeCleanupService,
Document document, ICodeCleanupService codeCleanupService,
IProgressTracker progressTracker, CancellationToken cancellationToken)
{
var newDoc = await codeCleanupService.CleanupAsync(
......
......@@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.OrganizeImports;
using Microsoft.CodeAnalysis.PooledObjects;
......@@ -133,10 +134,12 @@ internal class CSharpCodeCleanupService : ICodeCleanupService
}
progressTracker.Description = FeaturesResources.Formatting_document;
var result = await Formatter.FormatAsync(document).ConfigureAwait(false);
progressTracker.ItemCompleted();
return result;
using (Logger.LogBlock(FunctionId.CodeCleanup_Format, cancellationToken))
{
var result = await Formatter.FormatAsync(document).ConfigureAwait(false);
progressTracker.ItemCompleted();
return result;
}
}
private async Task<Document> RemoveSortUsingsAsync(
......@@ -147,13 +150,19 @@ internal class CSharpCodeCleanupService : ICodeCleanupService
var removeUsingsService = document.GetLanguageService<IRemoveUnnecessaryImportsService>();
if (removeUsingsService != null)
{
document = await removeUsingsService.RemoveUnnecessaryImportsAsync(document, cancellationToken).ConfigureAwait(false);
using (Logger.LogBlock(FunctionId.CodeCleanup_RemoveUnusedImports, cancellationToken))
{
document = await removeUsingsService.RemoveUnnecessaryImportsAsync(document, cancellationToken).ConfigureAwait(false);
}
}
}
if (docOptions.GetOption(CodeCleanupOptions.SortImports))
{
document = await OrganizeImportsService.OrganizeImportsAsync(document, cancellationToken).ConfigureAwait(false);
using (Logger.LogBlock(FunctionId.CodeCleanup_SortImports, cancellationToken))
{
document = await OrganizeImportsService.OrganizeImportsAsync(document, cancellationToken).ConfigureAwait(false);
}
}
return document;
......@@ -188,8 +197,11 @@ internal class CSharpCodeCleanupService : ICodeCleanupService
{
foreach (var diagnosticId in diagnosticIds)
{
document = await ApplyCodeFixesForSpecificDiagnosticId(
document, diagnosticId, cancellationToken).ConfigureAwait(false);
using (Logger.LogBlock(FunctionId.CodeCleanup_ApplyCodeFixesAsync, diagnosticId, cancellationToken))
{
document = await ApplyCodeFixesForSpecificDiagnosticId(
document, diagnosticId, cancellationToken).ConfigureAwait(false);
}
}
return document;
......
// 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 Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.CodeCleanup
{
internal static class CodeCleanupLogMessage
{
public static KeyValueLogMessage Create(DocumentOptionSet docOptions)
{
return KeyValueLogMessage.Create(LogType.UserAction, m =>
{
foreach (var option in CodeCleanupOptionsProvider.SingletonOptions)
{
m[option.Name] = docOptions.GetOption((PerLanguageOption<bool>)option, LanguageNames.CSharp);
}
});
}
}
}
......@@ -81,7 +81,7 @@ internal static class CodeCleanupOptions
[ExportOptionProvider, Shared]
internal class CodeCleanupOptionsProvider : IOptionProvider
{
public ImmutableArray<IOption> Options { get; } = ImmutableArray.Create<IOption>(
public static ImmutableArray<IOption> SingletonOptions { get; } = ImmutableArray.Create<IOption>(
CodeCleanupOptions.CodeCleanupInfoBarShown,
CodeCleanupOptions.AddAccessibilityModifiers,
CodeCleanupOptions.AddRemoveBracesForSingleLineControlStatements,
......@@ -92,11 +92,15 @@ internal class CodeCleanupOptionsProvider : IOptionProvider
CodeCleanupOptions.ApplyObjectCollectionInitializationPreferences,
CodeCleanupOptions.ApplyThisQualificationPreferences,
CodeCleanupOptions.MakePrivateFieldReadonlyWhenPossible,
CodeCleanupOptions.NeverShowCodeCleanupInfoBarAgain,
CodeCleanupOptions.PerformAdditionalCodeCleanupDuringFormatting,
CodeCleanupOptions.RemoveUnnecessaryCasts,
CodeCleanupOptions.RemoveUnusedImports,
CodeCleanupOptions.RemoveUnusedVariables,
CodeCleanupOptions.SortAccessibilityModifiers,
CodeCleanupOptions.SortImports
);
public ImmutableArray<IOption> Options { get; } = SingletonOptions;
}
}
......@@ -34,16 +34,20 @@ internal sealed class Snapshot : PortableExecutableReference, ISupportTemporaryS
private readonly VisualStudioMetadataReferenceManager _provider;
private readonly Lazy<DateTime> _timestamp;
private Exception _error;
private FileChangeTracker _fileChangeTrackerOpt;
internal Snapshot(VisualStudioMetadataReferenceManager provider, MetadataReferenceProperties properties, string fullPath)
internal Snapshot(VisualStudioMetadataReferenceManager provider, MetadataReferenceProperties properties, string fullPath, FileChangeTracker fileChangeTrackerOpt)
: base(properties, fullPath)
{
Contract.Requires(Properties.Kind == MetadataImageKind.Assembly);
_provider = provider;
_fileChangeTrackerOpt = fileChangeTrackerOpt;
_timestamp = new Lazy<DateTime>(() => {
try
{
_fileChangeTrackerOpt?.EnsureSubscription();
return FileUtilities.GetFileTimeStamp(this.FilePath);
}
catch (IOException e)
......@@ -98,7 +102,7 @@ protected override DocumentationProvider CreateDocumentationProvider()
protected override PortableExecutableReference WithPropertiesImpl(MetadataReferenceProperties properties)
{
return new Snapshot(_provider, properties, this.FilePath);
return new Snapshot(_provider, properties, this.FilePath, _fileChangeTrackerOpt);
}
private string GetDebuggerDisplay()
......
......@@ -55,8 +55,6 @@ public PortableExecutableReference CurrentSnapshot
UpdateSnapshot();
}
// make sure we have file notification subscribed
_fileChangeTracker.EnsureSubscription();
return _currentSnapshot;
}
}
......@@ -74,7 +72,7 @@ public void Dispose()
public void UpdateSnapshot()
{
_currentSnapshot = new Snapshot(_provider, Properties, this.FilePath);
_currentSnapshot = new Snapshot(_provider, Properties, this.FilePath, _fileChangeTracker);
}
private string GetDebuggerDisplay()
......
......@@ -83,7 +83,7 @@ internal IEnumerable<ITemporaryStreamStorage> GetStorages(string fullPath, DateT
public PortableExecutableReference CreateMetadataReferenceSnapshot(string filePath, MetadataReferenceProperties properties)
{
return new VisualStudioMetadataReference.Snapshot(this, properties, filePath);
return new VisualStudioMetadataReference.Snapshot(this, properties, filePath, fileChangeTrackerOpt: null);
}
public VisualStudioMetadataReference CreateMetadataReference(string filePath, MetadataReferenceProperties properties)
......
......@@ -418,5 +418,15 @@ internal enum FunctionId
SymbolFinder_Solution_Pattern_FindSourceDeclarationsAsync,
SymbolFinder_Project_Pattern_FindSourceDeclarationsAsync,
Intellisense_Completion_Commit,
CodeCleanupInfobar_BarDisplayed,
CodeCleanupInfobar_ConfigureNow,
CodeCleanupInfobar_NeverShowCodeCleanupInfoBarAgain,
FormatDocument,
CodeCleanup_ApplyCodeFixesAsync,
CodeCleanup_RemoveUnusedImports,
CodeCleanup_SortImports,
CodeCleanup_Format
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册