提交 566b572a 编写于 作者: S Sam Harwell

Avoid constructing BlockCommentEditingCommandHandler outside the MEF catalog

上级 3ed3e4dd
......@@ -6,13 +6,13 @@
using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
......@@ -37,7 +37,7 @@ internal sealed class BlockCommentEditingCommandHandler : ICommandHandler<Return
private readonly IEditorOperationsFactoryService _editorOperationsFactoryService;
[ImportingConstructor]
[SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public BlockCommentEditingCommandHandler(
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService)
......
......@@ -4,9 +4,9 @@
using System;
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
......@@ -21,7 +21,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.BlockCommentEditing
internal sealed class CloseBlockCommentCommandHandler : ICommandHandler<TypeCharCommandArgs>
{
[ImportingConstructor]
[SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification = "Used in test code: https://github.com/dotnet/roslyn/issues/42814")]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CloseBlockCommentCommandHandler()
{
}
......
......@@ -10,7 +10,6 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
using Microsoft.VisualStudio.Text.Operations;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -726,7 +725,7 @@ protected override TestWorkspace CreateTestWorkspace(string initialMarkup)
protected override (ReturnKeyCommandArgs, string insertionText) CreateCommandArgs(ITextView textView, ITextBuffer textBuffer)
=> (new ReturnKeyCommandArgs(textView, textBuffer), "\r\n");
internal override ICommandHandler<ReturnKeyCommandArgs> CreateCommandHandler(ITextUndoHistoryRegistry undoHistoryRegistry, IEditorOperationsFactoryService editorOperationsFactoryService)
=> new BlockCommentEditingCommandHandler(undoHistoryRegistry, editorOperationsFactoryService);
internal override ICommandHandler<ReturnKeyCommandArgs> GetCommandHandler(TestWorkspace workspace)
=> Assert.IsType<BlockCommentEditingCommandHandler>(workspace.GetService<ICommandHandler>(ContentTypeNames.CSharpContentType, nameof(BlockCommentEditingCommandHandler)));
}
}
......@@ -11,7 +11,6 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
using Microsoft.VisualStudio.Text.Operations;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -369,7 +368,7 @@ protected override TestWorkspace CreateTestWorkspace(string initialMarkup)
protected override (TypeCharCommandArgs, string insertionText) CreateCommandArgs(ITextView textView, ITextBuffer textBuffer)
=> (new TypeCharCommandArgs(textView, textBuffer, '/'), "/");
internal override ICommandHandler<TypeCharCommandArgs> CreateCommandHandler(ITextUndoHistoryRegistry undoHistoryRegistry, IEditorOperationsFactoryService editorOperationsFactoryService)
=> new CloseBlockCommentCommandHandler();
internal override ICommandHandler<TypeCharCommandArgs> GetCommandHandler(TestWorkspace workspace)
=> Assert.IsType<CloseBlockCommentCommandHandler>(workspace.GetService<ICommandHandler>(ContentTypeNames.CSharpContentType, nameof(CloseBlockCommentCommandHandler)));
}
}
......@@ -10,7 +10,6 @@
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -19,9 +18,7 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests
[UseExportProvider]
public abstract class AbstractTypingCommandHandlerTest<TCommandArgs> where TCommandArgs : CommandArgs
{
internal abstract ICommandHandler<TCommandArgs> CreateCommandHandler(
ITextUndoHistoryRegistry undoHistoryRegistry,
IEditorOperationsFactoryService editorOperationsFactoryService);
internal abstract ICommandHandler<TCommandArgs> GetCommandHandler(TestWorkspace workspace);
protected abstract TestWorkspace CreateTestWorkspace(string initialMarkup);
......@@ -37,7 +34,7 @@ protected void Verify(string initialMarkup, string expectedMarkup, Action<TestWo
var view = testDocument.GetTextView();
view.Caret.MoveTo(new SnapshotPoint(view.TextSnapshot, testDocument.CursorPosition.Value));
var commandHandler = CreateCommandHandler(workspace.GetService<ITextUndoHistoryRegistry>(), workspace.GetService<IEditorOperationsFactoryService>());
var commandHandler = GetCommandHandler(workspace);
var (args, insertionText) = CreateCommandArgs(view, view.TextBuffer);
var nextHandler = CreateInsertTextHandler(view, insertionText);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册