Editor imports
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
You can import a number of editor services, factories, and brokers that provide your extension with different kinds of access to the core editor. For example, you can import the ITextStructureNavigatorSelectorService to provide you with a ITextStructureNavigator for a given content type. (This navigator allows you perform different kinds of searches on a text buffer.)
To use an editor import, you import it as a field or property of a class that exports a Managed Extensibility Framework component part.
Note
For more information about the Managed Extensibility Framework, see Managed Extensibility Framework (MEF).
Import syntax
The following example shows how to import the editor options factory service.
[Import]
internal IEditorOptionsFactoryService EditorOptions { get; set; }
If you want to import the service as a field and not a property, you should set it to null
in the declaration in order to avoid the compiler warnings about not assigning to a variable:
[Import]
internal IEditorOptionsFactoryService m_editorOptions = null;
For more examples of using imports, see the following walkthroughs:
Import the service provider
You can also import a SVsServiceProvider (found in the assembly Microsoft.VisualStudio.Shell.Immutable.10.0) in the same way to get access to Visual Studio services:
[Import]
internal SVsServiceProvider ServiceProvider = null;
See Walkthrough: Access the DTE object from an editor extension for more information.
Services
Editor services are generally single entities that provide a service and are shared across multiple components.
Other imports
Provider factories and brokers are generally entities that can have multiple instances in multiple components.
Import | Provides |
---|---|
IErrorProviderFactory | A SimpleTagger<T> of type ErrorTag) for the given buffer. |
ITextMarkerProviderFactory | A text marker tagger (a SimpleTagger<T> of type TextMarkerTag). |
IToolTipProviderFactory | An IToolTipProvider for a given ITextView. |
ICompletionBroker | An ICompletionSession. |
IQuickInfoBroker | An IQuickInfoSession. |
ISignatureHelpBroker | An ISignatureHelpSession. |