diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller.cs index 14f73c14e5d64469a61e24c0ae117c22cccb3c56..e3fa1eed7c3859efde4ac5fe70e3590697eecbbc 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller.cs @@ -113,6 +113,12 @@ private SnapshotPoint GetCaretPointInViewBuffer() return this.TextView.Caret.Position.BufferPosition; } + private SnapshotPoint GetCaretPointInSubjectBuffer() + { + AssertIsForeground(); + return this.TextView.BufferGraph.MapUpOrDownToBuffer(this.TextView.Caret.Position.BufferPosition, this.SubjectBuffer).GetValueOrDefault(); + } + internal override void OnModelUpdated(Model modelOpt) { AssertIsForeground(); diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_Backspace.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_Backspace.cs index f11c4f887f46155c939c07d2b81f9e739df64793..d5c347fe5ce1c56f23d1fd1fecd511a9aa7d7990 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_Backspace.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_Backspace.cs @@ -5,6 +5,7 @@ using System.Threading; using Microsoft.CodeAnalysis.Completion; using Microsoft.CodeAnalysis.Editor.Commands; +using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; @@ -30,18 +31,19 @@ private void ExecuteBackspaceOrDelete(ITextView textView, Action nextHandler, bo AssertIsForeground(); char? deletedChar; - var caretPoint = GetCaretPointInViewBuffer().Position; + var subjectBufferCaretPoint = GetCaretPointInSubjectBuffer(); + var viewBufferCaretPoint = GetCaretPointInViewBuffer(); if (isDelete) { - deletedChar = GetCaretPointInViewBuffer().Position >= 0 && GetCaretPointInViewBuffer().Position < textView.TextBuffer.CurrentSnapshot.Length - ? textView.TextBuffer.CurrentSnapshot[GetCaretPointInViewBuffer().Position] + deletedChar = viewBufferCaretPoint.Position >= 0 && viewBufferCaretPoint.Position < textView.TextBuffer.CurrentSnapshot.Length + ? textView.TextBuffer.CurrentSnapshot[viewBufferCaretPoint.Position] : default(char?); } else { // backspace - deletedChar = caretPoint > 0 - ? textView.TextBuffer.CurrentSnapshot[caretPoint - 1] + deletedChar = viewBufferCaretPoint > 0 + ? textView.TextBuffer.CurrentSnapshot[viewBufferCaretPoint - 1] : default(char?); } @@ -88,7 +90,7 @@ private void ExecuteBackspaceOrDelete(ITextView textView, Action nextHandler, bo var model = sessionOpt.Computation.InitialUnfilteredModel; - if ((model == null && CaretHasLeftDefaultTrackingSpan(caretPoint, documentBeforeDeletion)) || + if ((model == null && CaretHasLeftDefaultTrackingSpan(subjectBufferCaretPoint, documentBeforeDeletion)) || (model != null && this.IsCaretOutsideAllItemBounds(model, this.GetCaretPointInViewBuffer())) || (model != null && CreateCompletionService().DismissIfLastFilterCharacterDeleted && AllFilterTextsEmpty(model, GetCaretPointInViewBuffer()))) { diff --git a/src/VisualStudio/Core/Test/DebuggerIntelliSense/CSharpDebuggerIntellisenseTests.vb b/src/VisualStudio/Core/Test/DebuggerIntelliSense/CSharpDebuggerIntellisenseTests.vb index 2b7d5797d72a7222ada7ea75c0a16f77180b7bd0..bdad34a4bbef7f225a65df03a5d003b771b1cf09 100644 --- a/src/VisualStudio/Core/Test/DebuggerIntelliSense/CSharpDebuggerIntellisenseTests.vb +++ b/src/VisualStudio/Core/Test/DebuggerIntelliSense/CSharpDebuggerIntellisenseTests.vb @@ -459,6 +459,162 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.DebuggerIntelliSense End Using End Sub + + + Public Sub CompletionUsesContextBufferPositions() + Dim text = + + + e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e. +(1,3): error CS1001: Identifier expected +e. +(1,3): error CS1001: Identifier expected +e. +(1,3): error CS1001: Identifier expected +e. +(1,3): error CS1001: Identifier expected +e. +(1,3): error CS1001: Identifier expected +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +e.InnerException +{"Exception of type 'System.Exception' was thrown."} + Data: {System.Collections.ListDictionaryInternal} + HResult: -2146233088 + HelpLink: null + InnerException: null + Message: "Exception of type 'System.Exception' was thrown." + Source: null + StackTrace: null + TargetSite: null +$$ + class Program +{ + static void Main(string[] args) + [|{|] + + } +} + + + + Using state = TestState.CreateCSharpTestState(text, True) + state.SendTypeChars("arg") + Assert.Equal("arg", state.GetCurrentViewLineText()) + state.AssertCompletionSession() + state.SendTab() + Assert.Equal("args", state.GetCurrentViewLineText()) + End Using + End Sub + Private Sub VerifyCompletionAndDotAfter(item As String, state As TestState) state.SendTypeChars(item) state.AssertSelectedCompletionItem(item)