提交 deee948a 编写于 作者: R Ravi Chande

Merge pull request #4978 from rchande/diffwindow

After calling nextHandler(), backspace completion should verify that …
......@@ -151,6 +151,14 @@ private bool StartNewModelComputation(ICompletionService completionService, Comp
return false;
}
// The caret may no longer be mappable into our subject buffer.
var caret = TextView.GetCaretPoint(SubjectBuffer);
if (!caret.HasValue)
{
return false;
}
if (this.TextView.Caret.Position.VirtualBufferPosition.IsInVirtualSpace)
{
// Convert any virtual whitespace to real whitespace by doing an empty edit at the caret position.
......
......@@ -3,10 +3,17 @@
Imports System.Threading
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis.Completion
Imports Microsoft.CodeAnalysis.Editor.Commands
Imports Microsoft.CodeAnalysis.Editor.CSharp.Formatting
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Extensions
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.VisualStudio.Text
Imports Microsoft.VisualStudio.Text.Differencing
Imports Microsoft.VisualStudio.Text.Editor
Imports Microsoft.VisualStudio.Text.Operations
Imports Microsoft.VisualStudio.Text.Projection
Imports Microsoft.VisualStudio.Utilities
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
Public Class CSharpCompletionCommandHandlerTests
......@@ -1507,5 +1514,56 @@ $$]]></Document>, extraExportedTypes:={GetType(CSharpEditorFormattingService)}.T
state.AssertMatchesTextStartingAtLine(6, "doo;")
End Using
End Sub
<WorkItem(4978, "https://github.com/dotnet/roslyn/issues/4978")>
<Fact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Sub SessionNotStartedWhenCaretNotMappableIntoSubjectBuffer()
' In inline diff view, typing delete next to a "deletion",
' can cause our CommandChain to be called with a subjectbuffer
' and TextView such that the textView's caret can't be mapped
' into our subject buffer.
'
' To test this, we create a projection buffer with 2 source
' spans: one of "text" content type and one based on a C#
' buffer. We create a TextView with that projection as
' its buffer, setting the caret such that it maps only
' into the "text" buffer. We then call the completion
' command handlers with commandargs based on that TextView
' but with the C# buffer as the SubjectBuffer.
Using state = TestState.CreateCSharpTestState(
<Document><![CDATA[
class C
{
void foo(int x)
{$$
/********/
int doodle;
}
}]]></Document>, extraExportedTypes:={GetType(CSharpEditorFormattingService)}.ToList())
Dim textBufferFactoryService = state.GetExportedValue(Of ITextBufferFactoryService)()
Dim contentTypeService = state.GetExportedValue(Of IContentTypeRegistryService)()
Dim contentType = contentTypeService.GetContentType(ContentTypeNames.CSharpContentType)
Dim textViewFactory = state.GetExportedValue(Of ITextEditorFactoryService)()
Dim editorOperationsFactory = state.GetExportedValue(Of IEditorOperationsFactoryService)()
Dim otherBuffer = textBufferFactoryService.CreateTextBuffer("text", contentType)
Dim otherExposedSpan = otherBuffer.CurrentSnapshot.CreateTrackingSpan(0, 4, SpanTrackingMode.EdgeExclusive, TrackingFidelityMode.Forward)
Dim subjectBufferExposedSpan = state.SubjectBuffer.CurrentSnapshot.CreateTrackingSpan(0, state.SubjectBuffer.CurrentSnapshot.Length, SpanTrackingMode.EdgeExclusive, TrackingFidelityMode.Forward)
Dim projectionBufferFactory = state.GetExportedValue(Of IProjectionBufferFactoryService)()
Dim projection = projectionBufferFactory.CreateProjectionBuffer(Nothing, New Object() {otherExposedSpan, subjectBufferExposedSpan}.ToList(), ProjectionBufferOptions.None)
Dim view = textViewFactory.CreateTextView(projection)
view.Caret.MoveTo(New SnapshotPoint(view.TextBuffer.CurrentSnapshot, 0))
Dim editorOperations = editorOperationsFactory.GetEditorOperations(view)
state.CompletionCommandHandler.ExecuteCommand(New DeleteKeyCommandArgs(view, state.SubjectBuffer), Sub() editorOperations.Delete())
state.AssertNoCompletionSession()
End Using
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册