Editor Imports
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Editor Imports.
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.
For more information about the Managed Extensibility Framework, see Managed Extensibility Framework (MEF). |
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:
Walkthrough: Creating a Margin Glyph
Walkthrough: Customizing the Text View
Walkthrough: Highlighting Text
Walkthrough: Displaying QuickInfo Tooltips
Walkthrough: Displaying Signature Help
Walkthrough: Displaying Statement Completion
Walkthrough: Displaying SmartTags
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: Accessing the DTE Object from an Editor Extension for more information.
Editor services are generally single entities that provide a service and are shared across multiple components.
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. |