Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Feature Service API

Amadeusz Wieczorek edited this page May 11, 2018 · 8 revisions

Feature Service is an API that offers a standardized way to disable various Visual Studio features.

Possible uses are:

  • Inline rename to disable interactive popups
  • Multi caret to disable completion
  • R# to disable completion in C# documents

Previously, Visual Studio features were disabled through a combination of method calls that ultimately suppress the feature from being visible, but they cause side effects, a growing need to maintain these hacks on our side and various other developer frustrations.

The API is defined in Microsoft.VisualStudio.Utilities

  • FeatureDefinition is a MEF part that registers a feature, later accessed by string. Applicable metadata:
  • Required Name(string), used to disable the feature or check its status
  • Optional BaseDefinition(string), which means that feature is disabled if its base feature is disabled

We provide a few feature names in Microsoft.VisualStudio.Utilities.PredefinedEditorFeatureNames: Editor, Popup, InteractivePopup and Completion. This list will grow as we onboard more features.

  • IFeatureServiceFactory is a MEF part used to obtain instances of IFeatureService

  • GlobalFeatureService returns VS-wide IFeatureService

  • GetOrCreate(IPropertyOwner scope) returns IFeatureService applicable to given scope, for example ITextView

  • IFeatureService is used to disable\restore a feature and to check its availability

  • IsEnabled(string featureName) returns whether a feature or its base is disabled in this scope or parent scope.

[Export]
[Name(nameof(MyFeature))]   // required
[BaseDefinition(PredefinedEditorFeatureNames.Popup)]   // zero or more BaseDefinitions are allowed
public FeatureDefinition MyFeature;
[Import]
IFeatureServiceFactory FeatureServiceFactory;

IFeatureService globalService = FeatureServiceFactory.GlobalFeatureService;
IFeatureService localService = FeatureServiceFactory.GetOrCreate(scope); // scope is an IPropertyOwner

// Also have a reference to <see cref="IFeatureController"/>:
IFeatureController MyFeatureController;
// Interact with the <see cref="IFeatureService"/>:
globalService.Disable(PredefinedEditorFeatureNames.Popup, MyFeatureController);
localService.IsEnabled(PredefinedEditorFeatureNames.Completion); // returns false, because Popup is a base definition of Completion and because global scope is a superset of local scope.
Clone this wiki locally