Sam's Blog

26 Oct

The many properties of ProvideLanguageServiceAttribute

The ProvideLanguageServiceAttribute class has been with us for many years now. At least since it shipped as source code in the Visual Studio 2005 SDK. With more than two dozen properties, it’s easy to get lost trying to figure out which ones are meaningful and/or useful, and which ones are safe to ignore.

Like the other registration attributes, for Visual Studio 2010+ extension developers this class aids in the creation of a .pkgdef file for a VSPackage extension. Each property is associated with one or more entries in the file, and eventually corresponds to registry keys which can be queried by either Visual Studio itself or an extension. In the case of ProvideLanguageServiceAttribute, the supported entries fall into the following categories.

  1. Some properties instruct Visual Studio to either enable or disable one or more standard options in the Tools → Options… → Text Editor → {language name} pages for the language being registered (aka the language options pages).
  2. Some properties set the default values for one or more standard options in the language options pages.
  3. Some properties control other special behavior of the Visual Studio editor.
  4. Some properties do not have any impact on Visual Studio itself, but do create registry entries that can be queried by an extension (more on these later).
  5. Some properties I am still unclear on, either because I have never used them or because they appear to have changed behavior or become obsolete for Visual Studio 2010+ extensions. (Hopefully I can eventually move items from this category to other categories.)

Enabling/disabling standard options

The following properties determine whether certain standard UI elements in the language options pages are visible and/or enabled.

  • EnableAdvancedMembersOption. When set to false, the Hide advanced members check box on the General language options page is disabled. The default value is false. This option is closely related to both the ShowCompletion and HideAdvancedMembersByDefault options described below.
  • EnableLineNumbers. When set to false, the Line numbers check box on the General language options page is disabled. The default value is true.
  • ShowCompletion. When set to false, all of the check boxes under Statement completion on the General language options page are disabled. The default value is false.
  • ShowDropDownOptions. When set to false, the Navigation bar check box on the General language options page is disabled. The default value is false. Note: This behavior was observed in Visual Studio 2013, and differs substantially from the behavior described on MSDN. Users implementing this feature should set the property to true, and other users should leave the property unset for consistent behavior that matches MSDN.
  • ShowSmartIndent. When set to false, the Smart radio box on the Tabs language options page is disabled. The default value is false.

Specifying default options

The following properties determine the default values of language options.

  • DefaultToInsertSpaces. When set to true, the Insert spaces option on the Tabs language options page is selected by default. When set to false, the Keep tabs option is selected by default. The default value is false.
  • DefaultToNonHotURLs.
  • HideAdvancedMembersByDefault. When set to true, the Hide advanced members box is checked by default on the General language options page. The default value is false.

Controlling special behavior

The following properties control standard editor behavior which is not exposed through the standard language options pages.

  • RequestStockColors. For MPF language services targeting versions of Visual Studio prior to 2010, this was a very important property for users implementing custom syntax highlighting items. When set to false, Visual Studio will try to cast your implementation of IVsLanguageInfo to an instance of IVsProvideColorableItems to get information about the additional syntax highlighting colors. For Visual Studio 2010+ extensions, a much cleaner API is available by simply setting the property to true and exporting instances of ClassificationTypeDefinition and EditorFormatDefinition to support additional syntax highlighting colors. The default value is false.
  • SingleCodeWindowOnly. When set to true, the Window → New Window command is disabled for editor windows created for this language. Note that this does not affect the behavior of the Window → Split command. The default value is false (and should not be changed unless absolutely necessary).

Properties that do not impact Visual Studio

Many of the available properties set registry keys that do not directly impact Visual Studio at all. For users basing their language service implementations on the managed package framework (MPF), these properties control behavior provided by that framework. Since I no longer use this framework for language service implementations, I’ll omit the detailed descriptions of these properties.

Properties I’m currently unsure of

Leave a Reply

© 2024 Sam's Blog | Entries (RSS) and Comments (RSS)

Your Index Web Directorywordpress logo