Question

When registering a custom language service extension, Visual Studio creates a new options entry for the language within the Text Editor node (in the Visual Studio options dialog). Beneath that node two default nodes are created named General and Tabs, whereby the General tab contains statement completion and display settings...

In the Dispay group there are three options; one of them is the Navigation Bar checkbox (which shows/hides the editor´s navigation bar). For my custom language service, this option is disabled. Of course, it´s not implemented yet.

enter image description here

I would like to know, what I have to do, to provide a navigation bar for my custom editor... I guess that there is a certain interface I have to implement in the editor´s factory, or the language service package must export a certain MEF component, or, or, ...

Était-ce utile?

La solution

Jon Senchyna´s answer guided me into the right direction. The OnSynchronizeDropdowns method gets never called (the SDK documentation is just wrong in that case). What did the final trick was to override at least GetComboAttributes, GetEntryAttributes and GetEntryText to get text-only items for both combo boxes...

[ComVisible(true)]
public sealed class CustomTypeAndMemberDropdownBars : TypeAndMemberDropdownBars
{
    private readonly IList<string> declarations;

    private readonly IList<string> members;

    public CustomTypeAndMemberDropdownBars(
        LanguageService languageService, 
        IVsTextView view)
        : base(languageService)
    {
        // TODO: initialize declarations and members from the given text view...
        this.declarations = ...
        this.members = ...
    }

    private enum ComboIndex
    {
        Types = 0, 

        Members = 1
    }

    public override int GetComboAttributes(
        int combo, 
        out uint entries, 
        out uint entryType, 
        out IntPtr imageList)
    {
        entries = 0;
        imageList = IntPtr.Zero;

        entryType = (uint)DROPDOWNENTRYTYPE.ENTRY_TEXT;

        var comboType = (ComboIndex)combo;
        switch (comboType)
        {
            case ComboIndex.Types:
                entries = (uint)this.declarations.Count();
                break;

            case ComboIndex.Members:
                entries = (uint)this.members.Count();
                break;
        }

        return VSConstants.S_OK;
    }

    public override int GetEntryAttributes(
        int combo, 
        int entry, 
        out uint fontAttrs)
    {
        fontAttrs = (uint)DROPDOWNFONTATTR.FONTATTR_PLAIN;

        return VSConstants.S_OK;
    }

    public override int GetEntryText(
        int combo, 
        int entry, 
        out string text)
    {
        text = null;
        var comboType = (ComboIndex)combo;
        switch (comboType)
        {
            case ComboIndex.Types:
                text = this.declarations[entry];
                break;

            case ComboIndex.Members:
                text = this.members[entry];
                break;
        }

        return VSConstants.S_OK;
    }

    public override bool OnSynchronizeDropdowns(
        LanguageService languageService, 
        IVsTextView textView, 
        int line, 
        int col, 
        ArrayList dropDownTypes, 
        ArrayList dropDownMembers, 
        ref int selectedType, 
        ref int selectedMember)
    {
        return false;
    }
}

Autres conseils

I believe the following steps should be what you need:

  1. In your Package class, set the ShowDropDownOptions property to true in the ProvideLanguageService attribute
  2. Create a class that implements TypeAndMemberDropdownBars
  3. In your LanguageService class, implement the CreateDropDownHelper function and have it return an instance of your TypeAndMemberDropdownBars
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top