Freigeben über


LanguageService Class

Definition

Important

This API is not CLS-compliant.

This is the base class for a language service that supplies language features including syntax highlighting, brace matching, auto-completion, IntelliSense support, and code snippet expansion.

public ref class LanguageService abstract : IDisposable, Microsoft::VisualStudio::OLE::Interop::IObjectWithSite, Microsoft::VisualStudio::OLE::Interop::IServiceProvider, Microsoft::VisualStudio::Shell::Interop::IVsDebuggerEvents, Microsoft::VisualStudio::TextManager::Interop::IVsAutoOutliningClient, Microsoft::VisualStudio::TextManager::Interop::IVsFormatFilterProvider, Microsoft::VisualStudio::TextManager::Interop::IVsLanguageContextProvider, Microsoft::VisualStudio::TextManager::Interop::IVsLanguageDebugInfo, Microsoft::VisualStudio::TextManager::Interop::IVsLanguageInfo, Microsoft::VisualStudio::TextManager::Interop::IVsProvideColorableItems, System::ComponentModel::ISynchronizeInvoke
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class LanguageService : IDisposable, Microsoft.VisualStudio.OLE.Interop.IObjectWithSite, Microsoft.VisualStudio.OLE.Interop.IServiceProvider, Microsoft.VisualStudio.Shell.Interop.IVsDebuggerEvents, Microsoft.VisualStudio.TextManager.Interop.IVsAutoOutliningClient, Microsoft.VisualStudio.TextManager.Interop.IVsFormatFilterProvider, Microsoft.VisualStudio.TextManager.Interop.IVsLanguageContextProvider, Microsoft.VisualStudio.TextManager.Interop.IVsLanguageDebugInfo, Microsoft.VisualStudio.TextManager.Interop.IVsLanguageInfo, Microsoft.VisualStudio.TextManager.Interop.IVsProvideColorableItems, System.ComponentModel.ISynchronizeInvoke
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class LanguageService : IDisposable, Microsoft.VisualStudio.OLE.Interop.IObjectWithSite, Microsoft.VisualStudio.OLE.Interop.IServiceProvider, Microsoft.VisualStudio.Shell.Interop.IVsDebuggerEvents, Microsoft.VisualStudio.TextManager.Interop.IVsAutoOutliningClient, Microsoft.VisualStudio.TextManager.Interop.IVsFormatFilterProvider, Microsoft.VisualStudio.TextManager.Interop.IVsLanguageContextProvider, Microsoft.VisualStudio.TextManager.Interop.IVsLanguageDebugInfo, Microsoft.VisualStudio.TextManager.Interop.IVsLanguageInfo, Microsoft.VisualStudio.TextManager.Interop.IVsProvideColorableItems, System.ComponentModel.ISynchronizeInvoke
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type LanguageService = class
    interface IDisposable
    interface IVsLanguageInfo
    interface IVsLanguageDebugInfo
    interface IVsProvideColorableItems
    interface IVsLanguageContextProvider
    interface IServiceProvider
    interface IObjectWithSite
    interface ISynchronizeInvoke
    interface IVsDebuggerEvents
    interface IVsFormatFilterProvider
    interface IVsAutoOutliningClient
[<System.Runtime.InteropServices.ComVisible(true)>]
type LanguageService = class
    interface IDisposable
    interface IVsLanguageInfo
    interface IVsLanguageDebugInfo
    interface IVsProvideColorableItems
    interface IVsLanguageContextProvider
    interface IServiceProvider
    interface IObjectWithSite
    interface ISynchronizeInvoke
    interface IVsDebuggerEvents
    interface IVsFormatFilterProvider
    interface IVsAutoOutliningClient
Public MustInherit Class LanguageService
Implements IDisposable, IObjectWithSite, IServiceProvider, ISynchronizeInvoke, IVsAutoOutliningClient, IVsDebuggerEvents, IVsFormatFilterProvider, IVsLanguageContextProvider, IVsLanguageDebugInfo, IVsLanguageInfo, IVsProvideColorableItems
Inheritance
LanguageService
Attributes
Implements

Examples

The following example shows how to register and initialize your language service for your package. Note: MyLanguageService is derived from the LanguageService class.

using System.ComponentModel.Design;  
using Microsoft.VisualStudio.Shell;  

namespace MyLanguagePackage  
{  
    /////////////////////////////////////////////  
    // Other package registration details go here  
    /////////////////////////////////////////////  

    // Offer a new language service  
    [ProvideServiceAttribute(typeof(MyLanguageService),  
                                       ServiceName = "My Language Service")]  

    // Register the language service with Visual Studio.  
    // "106" is the resource ID in the satellite DLL to the localized language name.  
    [ProvideLanguageServiceAttribute(typeof(MyLanguageService),"My Language",106)]  

    // Associate a file extension with our language service.  
    [ProvideLanguageExtensionAttribute(typeof(MyLanguageService), ".myext")]  

    class MyLanguagePackage : Package  
    {  
        protected override void Initialize()  
        {  
            base.Initialize();  

            IServiceContainer serviceContainer = this as IServiceContainer;  
            MyLanguageService languageService = new MyLanguageService();  
            languageService.SetSite(this);  
            serviceContainer.AddService(typeof(MyLanguageService),  
                                        languageService,  
                                        true);  
        }  
    }  
}  

Remarks

Visual Studio uses language services to provide support for code languages. A language service is registered with Visual Studio when the language service package is installed. Part of this registration process associates a file extension with a language service so any time a file with that extension is loaded, the language service is also loaded.

The LanguageService class is the base class for your language service. Visual Studio instantiates the VSPackage implementing your language service and calls the SetSite method on the VSPackage. In the implementation of this method, the Initialize method on the Package base class is called. Override the Initialize method to instantiate your language service. Remember to call the SetSite method on your language service after instantiation.

Notes to Implementers

Derive a class from this class to create your own language service. You must also, at the very least, implement a parser that implements the IScanner interface. All features of a language service are based on this parser.

The following methods and property are marked as abstract and must be implemented in a class derived tom the LanguageService class:

Method/Property to be Implemented Description
GetLanguagePreferences() A method that returns a LanguagePreferences object.
GetScanner(IVsTextLines) A method that returns an IScanner object.
ParseSource(ParseRequest) A method that parses the source.
Name A read-only property that returns the language name

If you do not intend to support the ValidateBreakpointLocation(IVsTextBuffer, Int32, Int32, TextSpan[]) but your language does support breakpoints, you must override the ValidateBreakpointLocation(IVsTextBuffer, Int32, Int32, TextSpan[]) method and return a span that contains the specified line and column; otherwise, breakpoints cannot be set anywhere except line 1. You can return E_NOTIMPL to indicate that you do not otherwise support this method but the span must always be set. The example in the ValidateBreakpointLocation(IVsTextBuffer, Int32, Int32, TextSpan[]) method shows how this can be done.

Notes to Callers

Register your language service when installing your VSPackage (this could be a package dedicated to your language service or it could be a project package that also supplies a language service). You instantiate your own language service during your package initialization. Visual Studio interacts with your language service to display code written in the language supported by your language service. See the example below for how this language registration can be done.

Constructors

LanguageService()

Initializes a new instance of the LanguageService class.

Properties

InvokeRequired

Determines if a method must be invoked across a thread boundary.

IsActive

Determines whether the language service is connected to the current view and therefore is active.

IsDebugging

Determines if the debugger is active.

IsParsing

Determines if a background parse is in progress.

LastActiveTextView

Returns the last active text view associated with this language service.

MainThreadId

Returns the id of the thread this language service is running on.

Name

Return the name of the language, such as "HTML" or "C++", and so on.

ParseThreadIsAlive

Determines whether the parse thread is alive.

ParseThreadPaused

Determines whether the parse thread is alive.

Preferences

Provides access to the language service preferences.

Site

Returns the service provider given to this language service.

Methods

AbortBackgroundParse()

Stops the parse thread.

AddCodeWindowManager(CodeWindowManager)

Adds a code window manager to the language service.

BeginInvoke(Delegate, Object[])

Invokes a method on another thread.

BeginParse(ParseRequest, ParseResultHandler)

Starts a parse operation on a background thread.

CanStopThread(Source)

Determines whether the thread can be stopped.

CreateCodeWindowManager(IVsCodeWindow, Source)

Instantiates a CodeWindowManager class.

CreateDocumentProperties(CodeWindowManager)

Instantiates a Microsoft.Office.Core.DocumentProperties class.

CreateDropDownHelper(IVsTextView)

Instantiates a TypeAndMemberDropdownBars class.

CreateExpansionFunction(ExpansionProvider, String)

Instantiates an ExpansionFunction class.

CreateExpansionProvider(Source)

Instantiates an ExpansionProvider class.

CreateParseRequest(Source, Int32, Int32, TokenInfo, String, String, ParseReason, IVsTextView)

Creates a request to satisfy the given reason for parsing that is then passed on to the parser.

CreateSource(IVsTextLines)

Instantiates a Source class.

CreateViewFilter(CodeWindowManager, IVsTextView)

Instantiates a ViewFilter class.

CurFileExtensionFormat(String)

Returns the index into the file extension list that matches the extension of the specified file name.

DispatchCommand(Guid, UInt32, IntPtr, IntPtr)

Called to execute the specified command.

DispatchCommand(Guid, UInt32, UInt32, IntPtr, IntPtr)

Executes the given command if it is enabled and supported using the current SUIHostCommandDispatcher.

Dispose()

Cleanup the sources, uiShell, shell, preferences and imageList objects and unregister this language service with VS.

EndInvoke(IAsyncResult)

Retrieves the result of an asynchronous call started by BeginInvoke(Delegate, Object[]).

GetCodeWindowManager(IVsCodeWindow, IVsCodeWindowManager)

Instantiates a CodeWindowManager class.

GetCodeWindowManagerForSource(Source)

Returns the CodeWindowManager object associated with the specified Source object.

GetCodeWindowManagerForView(IVsTextView)

Returns the CodeWindowManager associated with the specified IVsTextView object.

GetColorableItem(Int32, IVsColorableItem)

Returns the requested IVsColorableItem object.

GetColorizer(IVsTextLines, IVsColorizer)

Returns the colorizer associated with a Source object that contains the given IVsTextLines object.

GetColorizer(IVsTextLines)

Iinstantiates a Colorizer class.

GetFileExtensions(String)

Returns a string containing the file extensions associated with this language.

GetFormatFilterList()

Returns a list of file extension filters suitable for a Save As dialog box.

GetImageList()

Returns an image list containing glyphs associated with the language service.

GetItemCount(Int32)

Returns the number of custom colorable items supported by the language service.

GetIVsDebugger()

Returns an IVsDebugger object representing the currently available debugger in order to listen for debugger events.

GetIVsTextMacroHelperIfRecordingOn()

Returns an IVsTextMacroHelper object if macro recording is turned on.

GetLanguageID(IVsTextBuffer, Int32, Int32, Guid)

Returns the language GUID of the language service.

GetLanguageName(String)

Returns the name of the language this language service handles.

GetLanguagePreferences()

Returns a LanguagePreferences object for this language service.

GetLanguageServiceGuid()

Returns the GUID of the language service.

GetLocationOfName(String, String, TextSpan[])

Obsolete method that always returns E_NOTIMPL.

GetNameOfLocation(IVsTextBuffer, Int32, Int32, String, Int32)

Returns the name of the enclosing element that contains the given position.

GetOrCreateSource(IVsTextLines)

Gets the source if it is available, otherwise creates one.

GetParseResult()

Gets the result of the parse operation.

GetPrimaryViewForSource(Source)

Calls GetPrimaryView(IVsTextView) on the code window manager for the source.

GetProximityExpressions(IVsTextBuffer, Int32, Int32, Int32, IVsEnumBSTR)

Returns a list of expressions to be evaluated and shown in the Autos window, for a given span of lines.

GetScanner(IVsTextLines)

Returns a single instantiation of a parser.

GetService(Type)

Returns a service object that can be cast to a specific interface.

GetSite(Guid, IntPtr)

Returns an unmarshaled pointer to a requested interface.

GetSource(IVsTextLines)

Returns an existing Source object that contains the specified buffer of source.

GetSource(IVsTextView)

Returns an existing Source object that contains the source file shown in the specified text view.

GetSource(String)

Returns an existing Source object given a file name.

GetSources()

For enumerating all the known 'Source' objects.

Initialize()

Called to initialize the language service.

Invoke(Delegate, Object[])

Called to invoke a task specified by the given delegate.

IsMacroRecordingOn()

Called to determine if macro recording is turned on.

IsMappedLocation(IVsTextBuffer, Int32, Int32)

Called to determine if the specified location in the given source file references code in another file.

IsSourceOpen(Source)

Determines whether or not the source file is open.

OnActiveViewChanged(IVsTextView)

Called when the current view has changed to a different view.

OnCaretMoved(CodeWindowManager, IVsTextView, Int32, Int32)

Called when the caret has moved.

OnChangesCommitted(UInt32, TextSpan[])

Called when changes generated by an auto-complete or code snippet expansion operation is committed to the buffer.

OnCloseSource(Source)

Called to close the specified Source object.

OnIdle(Boolean)

Called when no other events need to be handled.

OnModeChange(DBGMODE)

Called whenever the debug mode has changed while debugging.

OnParseAborted()

Does nothing.

OnParseComplete(ParseRequest)

Override this method if you need to do any post-parse work on the main UI thread. Be sure to call this base method in order to get the dynamic help context updated.

OpenDocument(String)

Opens the specified file.

ParseSource(ParseRequest)

Parses the source based on the specified ParseRequest object.

QueryInvalidEncoding(__VSTFF, String)

Determines if the specified source format is valid or not.

QueryService(Guid, Guid, IntPtr)

Returns the request interface from the specified service.

QueryWaitForAutoOutliningCallback(Int32)

Determines whether to wait for the auto-outlining callback to finish.

RemoveCodeWindowManager(CodeWindowManager)

Called when the view associated with the specified CodeWindowManager is closed.

ResolveName(String, UInt32, IVsEnumDebugName)

Returns a list of method names that match the given name modified by the specified flags.

ScrollToEnd(IVsTextView)

Updates the specified view to show the end of the source file.

ScrollToEnd(IVsWindowFrame)

Updates the view in the specified window frame to show the end of the source file.

SetSite(Object)

Called to set or site the service provider for this language service.

SetUserContextDirty(String)

Call this method if you want UpdateLanguageContext to be called again.

SynchronizeDropdowns()

Called to update a drop-down bar based on the current caret position.

UpdateLanguageContext(LanguageContextHint, IVsTextLines, TextSpan[], IVsUserContext)

Updates the current user help context in a selected region of the given source.

ValidateBreakpointLocation(IVsTextBuffer, Int32, Int32, TextSpan[])

Called to determine if the given location can have a breakpoint applied to it.

Explicit Interface Implementations

IVsFormatFilterProvider.CurFileExtensionFormat(String, UInt32)

Returns the index into the file extension list that matches the extension of the specified file name.

IVsFormatFilterProvider.GetFormatFilterList(String)

Returns a list of file extension filters suitable for a Save As dialog box.

IVsFormatFilterProvider.QueryInvalidEncoding(UInt32, String)

Determines if the specified source format is valid or not.

IVsLanguageContextProvider.UpdateLanguageContext(UInt32, IVsTextLines, TextSpan[], Object)

Updates the current user help context given a selected region of the given source.

Extension Methods

QueryService(IServiceProvider, Guid)

Gets a service exposed by a service provider based on its service GUID.

QueryService<TService>(IServiceProvider)

Gets a service exposed by a service provider based on its service type.

Applies to