diff --git a/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.VsCodeWindowManager.cs b/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.VsCodeWindowManager.cs index b0ddab92d1c97774e4621a427350ecc18875ca3e..c0e8cc63f6b819d3dfa6e0fc914770f4133ae869 100644 --- a/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.VsCodeWindowManager.cs +++ b/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractLanguageService`2.VsCodeWindowManager.cs @@ -3,9 +3,12 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; +using System.Linq; using Microsoft.CodeAnalysis.Editor; using Microsoft.CodeAnalysis.Editor.Options; using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Shared.Extensions; +using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.LanguageServices.Implementation.NavigationBar; using Microsoft.VisualStudio.TextManager.Interop; using Roslyn.Utilities; @@ -64,6 +67,19 @@ private void AddOrRemoveDropdown(bool enabled) return; } + if (ErrorHandler.Failed(_codeWindow.GetBuffer(out var buffer))) + { + return; + } + + // Temporary solution until the editor provides a proper way to resolve the correct navbar. + // Tracked in https://github.com/dotnet/roslyn/issues/40989 + var document = _languageService.EditorAdaptersFactoryService.GetDataBuffer(buffer).AsTextContainer().GetRelatedDocuments().FirstOrDefault(); + if (document.GetLanguageService() == null) + { + return; + } + if (enabled) { var existingDropdownBar = GetDropdownBar(dropdownManager);