diff --git a/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.IVsImmediateStatementCompletion2.cs b/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.IVsImmediateStatementCompletion2.cs index 94d2be28514de9b84b27c078dc6be68800d1ceb4..ccb62048bf8eeb4929438c0246836e00e8417fbd 100644 --- a/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.IVsImmediateStatementCompletion2.cs +++ b/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.IVsImmediateStatementCompletion2.cs @@ -1,15 +1,18 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using Microsoft.CodeAnalysis.Editor; +using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.VisualStudio.Editor; using Microsoft.VisualStudio.LanguageServices.Implementation.DebuggerIntelliSense; using Microsoft.VisualStudio.OLE.Interop; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.TextManager.Interop; +using Roslyn.Utilities; namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService { @@ -81,6 +84,16 @@ int IVsImmediateStatementCompletion2.InstallStatementCompletion(int install, IVs if (buffer != null) { var contextBuffer = EditorAdaptersFactoryService.GetDataBuffer(buffer); + + if (!contextBuffer.ContentType.IsOfType(this.ContentTypeName)) + { + FatalError.ReportWithoutCrash( + new ArgumentException($"Expected content type {this.ContentTypeName} " + + $"but got buffer of content type {contextBuffer.ContentType}")); + + return VSConstants.E_FAIL; + } + var context = CreateContext(view, textView, debuggerBuffer, contextBuffer, currentStatementSpan); if (context.TryInitialize()) {