@@ -113,5 +113,82 @@ static void Method2 (int a)
113113 Assert . That ( items , Contains . Item ( "Method2" ) ) ;
114114 Assert . AreEqual ( 1 , completionResult . ExpressionLength ) ;
115115 }
116+
117+ [ Test ]
118+ public async Task HandlesWhenTextBufferChangesAndContainsLessLines ( )
119+ {
120+ var contentType = MimeTypeCatalog . Instance . GetContentTypeForMimeType ( "text/x-csharp" ) ;
121+
122+ var text = @"
123+ namespace console61
124+ {
125+ class MainClass
126+ {
127+ static void MethodA (int a)
128+ {
129+ }
130+
131+ static void MethodB (int a)
132+ {
133+ }
134+
135+ static void MethodC (int a)
136+ {
137+ }
138+
139+ public static void Main (string [] args)
140+ {
141+ $Console.WriteLine(2);$
142+ }
143+
144+ static void Method2 (int a)
145+ {
146+ }
147+ }
148+ }
149+ " ;
150+
151+ var textAfter = @"
152+ namespace console61
153+ {
154+ class MainClass
155+ {
156+ }
157+
158+ static void MethodZ (int a)
159+ {
160+ }
161+ }
162+ " ;
163+
164+ int startOfStatement = text . IndexOf ( '$' ) ;
165+ if ( startOfStatement >= 0 )
166+ text = text . Substring ( 0 , startOfStatement ) + text . Substring ( startOfStatement + 1 ) ;
167+ int endOfStatement = text . IndexOf ( '$' ) ;
168+ if ( endOfStatement >= 0 )
169+ text = text . Substring ( 0 , endOfStatement ) + text . Substring ( endOfStatement + 1 ) ;
170+
171+ var buffer = PlatformCatalog . Instance . TextBufferFactoryService . CreateTextBuffer ( text , contentType ) ;
172+ var doc = GetAnalysisDocument ( text ) ;
173+
174+ var snapshot = buffer . CurrentSnapshot ;
175+ var startLine = snapshot . GetLineFromPosition ( startOfStatement ) ;
176+ var startColumn = startOfStatement - startLine . Start . Position ;
177+ var endLine = snapshot . GetLineFromPosition ( endOfStatement ) ;
178+ var endColumn = endOfStatement - endLine . Start . Position ;
179+
180+ // get the stack frame
181+ var stackFrame = new StackFrame ( 0 , new SourceLocation ( "" , "" , startLine . LineNumber , startColumn , endLine . LineNumber , endColumn ) , "C#" ) ;
182+
183+ // now, alter the source so that the stack frame's location appear after the last line in the buffer
184+ var bufferAfter = PlatformCatalog . Instance . TextBufferFactoryService . CreateTextBuffer ( textAfter , contentType ) ;
185+ var docAfter = GetAnalysisDocument ( textAfter ) ;
186+ var controller = new DebuggerCompletionProvider ( docAfter , bufferAfter ) ;
187+
188+ var completionResult =
189+ await controller . GetExpressionCompletionDataAsync ( "a" , stackFrame , default ) ;
190+
191+ Assert . IsNull ( completionResult ) ;
192+ }
116193 }
117194}
0 commit comments