Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Extensibility - Custom Language Text Editor Settings

I'm trying to develop a language service within Visual Studio, and so far I've been able to implement a basic Tagger for highlights and spans:

enter image description here

However, I wanted to take it a step further and add my own section under 'Text Editor' so that I can maintain Tab settings, and the like for the language (shown below): enter image description here

I'm finding it difficult to find resources for Visual Studio extensibility online, as there's a lot you can do but knowing where to start is often difficult. I'm also interested in custom project/item services, but have similar issues with finding a sample.

It's possible I'm close as it is (due to the custom taggers), I just don't know what to decorate the exported types with, or I've got a lot of underlying work to do. Direction appreciated.

like image 744
Allen Clark Copeland Jr Avatar asked Sep 29 '22 13:09

Allen Clark Copeland Jr


1 Answers

I found this blog post it has a lot of Visual Studio Extension project samples. Among them there is one project called Options Page – VS 2013 I think this is what you are looking for:

Option page

For your specific case you should tweak the following attributes in the class (taken from the example) OptionsPagePackage.cs. Specifically these attributes:

  • ProvideOptionPageAttribute
  • ProvideProfileAttribute

Have "category" as second passed parameter (which correspond to the main category in the Tools menu).

[ProvideOptionPageAttribute(typeof(OptionsPageGeneral),"Text Editor","General", 100, 101, true, new string[] { "Change sample general options (C#)" })] 
    [ProvideProfileAttribute(typeof(OptionsPageGeneral), "Text Editor", "General Options", 100, 101, true, DescriptionResourceID = 100)] 
    [ProvideOptionPageAttribute(typeof(OptionsPageCustom), "Text Editor", "Custom", 100, 102, true, new string[] { "Change sample custom options (C#)" })] 
    [InstalledProductRegistration("Text Editor", "My Options Page (C#) Sample", "1.0")] 
    [Guid(GuidStrings.GuidPackage)] 
    public class OptionsPagePackageCS : Package 
    { 
    .....
    }

The DescriptionResourceID (100,101,102 etc) are defined in the xml file VsPackage.resx and will be used by the vsix installer to insert the labels in the tools menu:

<data name="100" xml:space="preserve">
    <value>My Managed Options (C#)</value>
    <comment>Options category</comment>
  </data>
  <data name="101" xml:space="preserve">
    <value>My Options</value>
    <comment>General page</comment>
  </data>
  <data name="102" xml:space="preserve">
    <value>Custom</value>
    <comment>Custom page</comment>
  </data>

This is my attempt:

enter image description here

Just be cautious as using an existing Category will overwrite the existing one. As you can see in the picture there are no options for all the other languages.

EDIT:

As pointed out by Alexander to avoid overwriting the existing configuration (if one wants to add his category to an existing one in the Tools menu) backslash must be added to the category parameter in the attributes mentioned above. For Example:

[ProvideOptionPageAttribute(typeof(OptionsPageGeneral),"Text Editor","General", 100, 101, true, new string[] { "Change sample general options (C#)" })]

Becomes:

 [ProvideOptionPageAttribute(typeof(OptionsPageGeneral),"Text Editor\\MyOptionPage","General", 100, 101, true, new string[] { "Change sample general options (C#)" })]

In that case MyOptionPage will be a child of Text Editor and it won't overwrite the existing configuration.

hope it helps.

like image 190
codingadventures Avatar answered Oct 06 '22 20:10

codingadventures