未验证 提交 19010373 编写于 作者: I Ivan Basov 提交者: GitHub

Editor completion: move references to EditorOperations from the new completion (#33774)

上级 c43de649
......@@ -15,7 +15,6 @@
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Roslyn.Utilities;
using AsyncCompletionData = Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion.Data;
using RoslynCompletionItem = Microsoft.CodeAnalysis.Completion.CompletionItem;
......@@ -29,7 +28,6 @@ internal sealed class CommitManager : ForegroundThreadAffinitizedObject, IAsyncC
new AsyncCompletionData.CommitResult(isHandled: false, AsyncCompletionData.CommitBehavior.None);
private readonly RecentItemsManager _recentItemsManager;
private readonly IEditorOperationsFactoryService _editorOperationsFactoryService;
private readonly ITextView _textView;
public IEnumerable<char> PotentialCommitCharacters
......@@ -48,10 +46,9 @@ public IEnumerable<char> PotentialCommitCharacters
}
}
internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager, IThreadingContext threadingContext, IEditorOperationsFactoryService editorOperationsFactoryService) : base(threadingContext)
internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager, IThreadingContext threadingContext) : base(threadingContext)
{
_recentItemsManager = recentItemsManager;
_editorOperationsFactoryService = editorOperationsFactoryService;
_textView = textView;
}
......@@ -182,8 +179,6 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
var triggerSnapshotSpan = new SnapshotSpan(triggerSnapshot, textChange.Span.ToSpan());
var mappedSpan = triggerSnapshotSpan.TranslateTo(subjectBuffer.CurrentSnapshot, SpanTrackingMode.EdgeInclusive);
var adjustedNewText = AdjustForVirtualSpace(textChange, view, _editorOperationsFactoryService);
using (var edit = subjectBuffer.CreateEdit(EditOptions.DefaultMinimalChange, reiteratedVersionNumber: null, editTag: null))
{
edit.Replace(mappedSpan.Span, change.TextChange.NewText);
......@@ -211,7 +206,7 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
var caretPositionInBuffer = view.GetCaretPoint(subjectBuffer);
if (caretPositionInBuffer.HasValue && mappedSpan.IntersectsWith(caretPositionInBuffer.Value))
{
view.TryMoveCaretToAndEnsureVisible(new SnapshotPoint(subjectBuffer.CurrentSnapshot, mappedSpan.Start.Position + adjustedNewText.Length));
view.TryMoveCaretToAndEnsureVisible(new SnapshotPoint(subjectBuffer.CurrentSnapshot, mappedSpan.Start.Position + textChange.NewText.Length));
}
else
{
......@@ -318,27 +313,5 @@ internal static bool SendEnterThroughToEditor(CompletionRules rules, RoslynCompl
return item.GetEntireDisplayText() == textTypedSoFar;
}
}
internal static string AdjustForVirtualSpace(TextChange textChange, ITextView textView, IEditorOperationsFactoryService editorOperationsFactoryService)
{
var newText = textChange.NewText;
var caretPoint = textView.Caret.Position.BufferPosition;
var virtualCaretPoint = textView.Caret.Position.VirtualBufferPosition;
if (textChange.Span.IsEmpty &&
textChange.Span.Start == caretPoint &&
virtualCaretPoint.IsInVirtualSpace)
{
// They're in virtual space and the text change is specified against the cursor
// position that isn't in virtual space. In this case, add the virtual spaces to the
// thing we're adding.
var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
var whitespace = editorOperations.GetWhitespaceForVirtualSpace(virtualCaretPoint);
return whitespace + newText;
}
return newText;
}
}
}
......@@ -6,7 +6,6 @@
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion
......@@ -18,18 +17,16 @@ internal class CommitManagerProvider : IAsyncCompletionCommitManagerProvider
{
private readonly IThreadingContext _threadingContext;
private readonly RecentItemsManager _recentItemsManager;
private readonly IEditorOperationsFactoryService _editorOperationsFactoryService;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CommitManagerProvider(IThreadingContext threadingContext, RecentItemsManager recentItemsManager, IEditorOperationsFactoryService editorOperationsFactoryService)
public CommitManagerProvider(IThreadingContext threadingContext, RecentItemsManager recentItemsManager)
{
_threadingContext = threadingContext;
_recentItemsManager = recentItemsManager;
_editorOperationsFactoryService = editorOperationsFactoryService;
}
IAsyncCompletionCommitManager IAsyncCompletionCommitManagerProvider.GetOrCreate(ITextView textView)
=> new CommitManager(textView, _recentItemsManager, _threadingContext, _editorOperationsFactoryService);
=> new CommitManager(textView, _recentItemsManager, _threadingContext);
}
}
......@@ -5,7 +5,6 @@
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncCompletion;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Internal.Log;
......@@ -13,6 +12,8 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Operations;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion
......@@ -113,7 +114,7 @@ private CompletionProvider GetCompletionProvider(CompletionItem item)
var mappedSpan = triggerSnapshotSpan.TranslateTo(
this.SubjectBuffer.CurrentSnapshot, SpanTrackingMode.EdgeInclusive);
var adjustedNewText = CommitManager.AdjustForVirtualSpace(textChange, this.TextView, _editorOperationsFactoryService);
var adjustedNewText = AdjustForVirtualSpace(textChange, this.TextView, _editorOperationsFactoryService);
var editOptions = GetEditOptions(mappedSpan, adjustedNewText);
// The immediate window is always marked read-only and the language service is
......@@ -195,6 +196,28 @@ private CompletionProvider GetCompletionProvider(CompletionItem item)
this.MakeMostRecentItem(item.DisplayText);
}
private static string AdjustForVirtualSpace(TextChange textChange, ITextView textView, IEditorOperationsFactoryService editorOperationsFactoryService)
{
var newText = textChange.NewText;
var caretPoint = textView.Caret.Position.BufferPosition;
var virtualCaretPoint = textView.Caret.Position.VirtualBufferPosition;
if (textChange.Span.IsEmpty &&
textChange.Span.Start == caretPoint &&
virtualCaretPoint.IsInVirtualSpace)
{
// They're in virtual space and the text change is specified against the cursor
// position that isn't in virtual space. In this case, add the virtual spaces to the
// thing we're adding.
var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
var whitespace = editorOperations.GetWhitespaceForVirtualSpace(virtualCaretPoint);
return whitespace + newText;
}
return newText;
}
private void SetCaretPosition(int desiredCaretPosition)
{
// Now, move the caret to the right location.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册