public void VsTextViewCreated(IVsTextView textViewAdapter) { IWpfTextView textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter); IVsTextBuffer textBuffer = EditorAdaptersFactoryService.GetBufferAdapter(textView.TextBuffer); textView.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument document); textViewAdapter.GetBuffer(out var textlines); if (textlines != null) { XFile file = null; string fileName = FilePathUtilities.GetFilePath(textlines); textlines.GetLanguageServiceID(out var langId); // Note that this may get called after the classifier has been instantiated if (langId == GuidStrings.guidLanguageService) // is our language service active ? { // Get XFile and assign it to the TextBuffer if (!textView.TextBuffer.Properties.TryGetProperty(typeof(XFile), out file)) { file = XSolution.FindFile(fileName); if (file == null) { XSolution.OrphanedFilesProject.AddFile(fileName); file = XSolution.FindFile(fileName); } if (file != null) { textView.TextBuffer.Properties.AddProperty(typeof(XFile), file); } } if (file != null) { file.Interactive = true; textView.Properties.AddProperty(typeof(XFile), file); } var filter = new XSharpEditorCommandHandler(textView); IOleCommandTarget next; textViewAdapter.AddCommandFilter(filter, out next); filter.Next = next; } // For VS 2017 we look for Microsoft.VisualStudio.Editor.Implementation.VsCodeWindowAdapter // For VS 2019 we look for Microsoft.VisualStudio.TextManager.Interop.IVsCodeWindow // Both implement IVsDropdownbarManager IVsDropdownBarManager dropDownBarManager = null; if (dropDownBarKey != null && textView.Properties.ContainsProperty(dropDownBarKey)) { object window = textView.Properties.GetProperty(dropDownBarKey); dropDownBarManager = window as IVsDropdownBarManager; } if (dropDownBarManager == null) { // look at all the properties to find the one that implements IVsDropdownBarManager foreach (var property in textView.Properties.PropertyList) { if (property.Value is IVsDropdownBarManager manager) { dropDownBarKey = property.Key; // remember key for next iteration dropDownBarManager = manager; break; } } } // The same file may be open in multiple textViews // these will share the same dropdown if (_dropDowns.ContainsKey(fileName)) { dropdown = _dropDowns[fileName]; dropdown.addTextView(textView); } else if (dropDownBarManager != null) { dropdown = new XSharpDropDownClient(dropDownBarManager, file); dropDownBarManager.RemoveDropdownBar(); dropDownBarManager.AddDropdownBar(2, dropdown); _dropDowns.Add(fileName, dropdown); dropdown.addTextView(textView); } if (!_textViews.ContainsKey(fileName)) { _textViews.Add(fileName, new List <IWpfTextView>()); } _textViews[fileName].Add(textView); textView.Closed += TextView_Closed; } }