LanguageService Class

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.

This API is not CLS-compliant. 

System.Object
  Microsoft.VisualStudio.Package.LanguageService

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)

[CLSCompliantAttribute(false)]
[ComVisibleAttribute(true)]
public abstract class LanguageService : IDisposable, 
	IVsLanguageInfo, IVsLanguageDebugInfo, IVsProvideColorableItems, IVsLanguageContextProvider, IServiceProvider, 
	IObjectWithSite, ISynchronizeInvoke, IVsDebuggerEvents, IVsFormatFilterProvider

The LanguageService type exposes the following members.

  NameDescription
Protected methodLanguageServiceInitializes a new instance of the LanguageService class.
Top

  NameDescription
Public propertyInvokeRequiredDetermines if a method must be invoked across a thread boundary.
Public propertyIsActiveDetermines whether the language service is connected to the current view and therefore is active.
Public propertyIsDebuggingDetermines if the debugger is active.
Public propertyIsParsingDetermines if a background parse is in progress.
Public propertyLastActiveTextViewReturns the last active text view associated with this language service.
Public propertyMainThreadIdReturns the id of the thread this language service is running on.
Public propertyNameReturns the name of the language (for example, "C++" or "HTML").
Protected propertyParseThreadIsAliveDetermines whether the parse thread is alive.
Public propertyParseThreadPausedDetermines whether the parse thread is alive.
Public propertyPreferencesProvides access to the language service preferences.
Public propertySiteReturns the service provider given to this language service.
Top

  NameDescription
Public methodAbortBackgroundParseStops the parse thread.
Public methodAddCodeWindowManagerAdds a code window manager to the language service.
Public methodBeginInvokeInvokes a method on another thread.
Public methodBeginParseStarts a parse operation on a background thread.
Public methodCanStopThreadDetermines whether the thread can be stopped.
Public methodCreateCodeWindowManagerInstantiates a CodeWindowManager class.
Public methodCreateDocumentPropertiesInstantiates a DocumentProperties class.
Public methodCreateDropDownHelperInstantiates a TypeAndMemberDropdownBars class.
Public methodCreateExpansionFunctionInstantiates an ExpansionFunction class.
Public methodCreateExpansionProviderInstantiates an ExpansionProvider class.
Public methodCreateParseRequestCreates a request to satisfy the given reason for parsing that is then passed on to the parser.
Public methodCreateSourceInstantiates a Source class.
Public methodCreateViewFilterInstantiates a ViewFilter class.
Public methodCurFileExtensionFormatReturns the index into the file extension list that matches the extension of the specified file name.
Public methodDispatchCommand(Guid, UInt32, IntPtr, IntPtr)Called to execute the specified command.
Public methodDispatchCommand(Guid, UInt32, UInt32, IntPtr, IntPtr)Called to execute the specified command.
Public methodDisposeCalled when the language service object is being destroyed.
Public methodEndInvokeRetrieves the result of an asynchronous call started by LanguageService.BeginInvoke.
Public methodEqualsDetermines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetCodeWindowManagerInstantiates a CodeWindowManager class.
Public methodGetCodeWindowManagerForSourceReturns the CodeWindowManager object associated with the specified Source object.
Public methodGetCodeWindowManagerForViewReturns the CodeWindowManager associated with the specified IVsTextView object.
Public methodGetColorableItemReturns the requested IVsColorableItem object.
Public methodGetColorizer(IVsTextLines)Iinstantiates a Colorizer class.
Public methodGetColorizer(IVsTextLines, IVsColorizer)Returns the colorizer associated with a Source object that contains the given IVsTextLines object.
Public methodGetFileExtensionsReturns a string containing the file extensions associated with this language.
Public methodGetFormatFilterListReturns a list of file extension filters suitable for a Save As dialog box.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetImageListReturns an image list containing glyphs associated with the language service.
Public methodGetItemCountReturns the number of custom colorable items supported by the language service.
Public methodGetIVsDebuggerReturns an IVsDebugger object representing the currently available debugger in order to listen for debugger events.
Public methodGetIVsTextMacroHelperIfRecordingOnReturns an IVsTextMacroHelper object if macro recording is turned on.
Public methodGetLanguageIDReturns the language GUID of the language service.
Public methodGetLanguageNameReturns the name of the language this language service handles.
Public methodGetLanguagePreferencesReturns a LanguagePreferences object for this language service.
Public methodGetLanguageServiceGuidReturns the GUID of the language service.
Public methodGetLocationOfNameObsolete method that always returns E_NOTIMPL.
Public methodGetNameOfLocationReturns the name of the enclosing element that contains the given position.
Public methodGetOrCreateSourceGets the source if it is available, otherwise creates one.
Public methodGetParseResultGets the result of the parse operation.
Public methodGetPrimaryViewForSourceCalls GetPrimaryView on the code window manager for the source.
Public methodGetProximityExpressionsReturns a list of expressions to be evaluated and shown in the Autos window, for a given span of lines.
Public methodGetScannerReturns a single instantiation of a parser.
Public methodGetServiceReturns a service object that can be cast to a specific interface.
Public methodGetSiteReturns an unmarshaled pointer to a requested interface.
Public methodGetSource(IVsTextLines)Returns an existing Source object that contains the specified buffer of source.
Public methodGetSource(IVsTextView)Returns an existing Source object that contains the source file shown in the specified text view.
Public methodGetSource(String)Returns an existing Source object given a file name.
Public methodGetSourcesReturns a collection of Source objects maintained by the language service.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeCalled to initialize the language service.
Public methodInvokeCalled to invoke a task specified by the given delegate.
Public methodIsMacroRecordingOnCalled to determine if macro recording is turned on.
Public methodIsMappedLocationCalled to determine if the specified location in the given source file references code in another file.
Public methodIsSourceOpenDetermines whether or not the source file is open.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOnActiveViewChangedCalled when the current view has changed to a different view.
Public methodOnCaretMovedCalled when the caret has moved.
Protected methodOnChangesCommittedCalled when changes generated by an auto-complete or code snippet expansion operation is committed to the buffer.
Public methodOnCloseSourceCalled to close the specified Source object.
Public methodOnIdleCalled when no other events need to be handled.
Public methodOnModeChangeCalled whenever the debug mode has changed while debugging.
Public methodOnParseAbortedDoes nothing.
Public methodOnParseCompleteCalled when a background parse has been completed.
Public methodOpenDocumentOpens the specified file.
Public methodParseSourceParses the source based on the specified ParseRequest object.
Public methodQueryInvalidEncodingDetermines if the specified source format is valid or not.
Public methodQueryServiceReturns the request interface from the specified service.
Public methodQueryWaitForAutoOutliningCallbackDetermines whether to wait for the auto-outlining callback to finish.
Public methodRemoveCodeWindowManagerCalled when the view associated with the specified CodeWindowManager is closed.
Public methodResolveNameReturns a list of method names that match the given name modified by the specified flags.
Public methodScrollToEnd(IVsTextView)Updates the specified view to show the end of the source file.
Public methodScrollToEnd(IVsWindowFrame)Updates the view in the specified window frame to show the end of the source file.
Public methodSetSiteCalled to set or site the service provider for this language service.
Public methodSetUserContextDirtyMarks the user context as dirty in the specified source buffer.
Public methodSynchronizeDropdownsCalled to update a drop-down bar based on the current caret position.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodUpdateLanguageContextUpdates the current user help context in a selected region of the given source.
Public methodValidateBreakpointLocationCalled to determine if the given location can have a breakpoint applied to it.
Top

  NameDescription
Explicit interface implemetationPrivate methodIVsFormatFilterProvider.CurFileExtensionFormatReturns the index into the file extension list that matches the extension of the specified file name.
Explicit interface implemetationPrivate methodIVsFormatFilterProvider.GetFormatFilterListReturns a list of file extension filters suitable for a Save As dialog box.
Explicit interface implemetationPrivate methodIVsFormatFilterProvider.QueryInvalidEncodingDetermines if the specified source format is valid or not.
Explicit interface implemetationPrivate methodIVsLanguageContextProvider.UpdateLanguageContextUpdates the current user help context given a selected region of the given source.
Top

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

A method that returns an IScanner object.

ParseSource

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 but your language does support breakpoints, you must override the ValidateBreakpointLocation 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 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.

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);
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft