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.

Namespace:   Microsoft.VisualStudio.Package
Assembly:  Microsoft.VisualStudio.Package.LanguageService.14.0 (in Microsoft.VisualStudio.Package.LanguageService.14.0.dll)

System.Object
  Microsoft.VisualStudio.Package.LanguageService

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

NameDescription
System_CAPS_protmethodLanguageService()

Initializes a new instance of the LanguageService class.

NameDescription
System_CAPS_pubpropertyInvokeRequired

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

System_CAPS_pubpropertyIsActive

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

System_CAPS_pubpropertyIsDebugging

Determines if the debugger is active.

System_CAPS_pubpropertyIsParsing

Determines if a background parse is in progress.

System_CAPS_pubpropertyLastActiveTextView

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

System_CAPS_pubpropertyMainThreadId

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

System_CAPS_pubpropertyName

Returns the name of the language (for example, "C++" or "HTML").

System_CAPS_protpropertyParseThreadIsAlive

Determines whether the parse thread is alive.

System_CAPS_pubpropertyParseThreadPaused

Determines whether the parse thread is alive.

System_CAPS_pubpropertyPreferences

Provides access to the language service preferences.

System_CAPS_pubpropertySite

Returns the service provider given to this language service.

NameDescription
System_CAPS_pubmethodAbortBackgroundParse()

Stops the parse thread.

System_CAPS_pubmethodAddCodeWindowManager(CodeWindowManager)

Adds a code window manager to the language service.

System_CAPS_pubmethodBeginInvoke(Delegate, Object[])

Invokes a method on another thread.

System_CAPS_pubmethodBeginParse(ParseRequest, ParseResultHandler)

Starts a parse operation on a background thread.

System_CAPS_pubmethodCanStopThread(Source)

Determines whether the thread can be stopped.

System_CAPS_pubmethodCreateCodeWindowManager(IVsCodeWindow, Source)

Instantiates a CodeWindowManager class.

System_CAPS_pubmethodCreateDocumentProperties(CodeWindowManager)
System_CAPS_pubmethodCreateDropDownHelper(IVsTextView)

Instantiates a TypeAndMemberDropdownBars class.

System_CAPS_pubmethodCreateExpansionFunction(ExpansionProvider, String)

Instantiates an ExpansionFunction class.

System_CAPS_pubmethodCreateExpansionProvider(Source)

Instantiates an ExpansionProvider class.

System_CAPS_pubmethodCreateParseRequest(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.

System_CAPS_pubmethodCreateSource(IVsTextLines)

Instantiates a Source class.

System_CAPS_pubmethodCreateViewFilter(CodeWindowManager, IVsTextView)

Instantiates a ViewFilter class.

System_CAPS_pubmethodCurFileExtensionFormat(String)

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

System_CAPS_pubmethodDispatchCommand(Guid, UInt32, IntPtr, IntPtr)

Called to execute the specified command.

System_CAPS_pubmethodDispatchCommand(Guid, UInt32, UInt32, IntPtr, IntPtr)

Called to execute the specified command.

System_CAPS_pubmethodDispose()

Called when the language service object is being destroyed.

System_CAPS_pubmethodEndInvoke(IAsyncResult)

Retrieves the result of an asynchronous call started by LanguageService.BeginInvoke.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetCodeWindowManager(IVsCodeWindow, IVsCodeWindowManager)

Instantiates a CodeWindowManager class.

System_CAPS_pubmethodGetCodeWindowManagerForSource(Source)

Returns the CodeWindowManager object associated with the specified Source object.

System_CAPS_pubmethodGetCodeWindowManagerForView(IVsTextView)

Returns the CodeWindowManager associated with the specified IVsTextView object.

System_CAPS_pubmethodGetColorableItem(Int32, IVsColorableItem)

Returns the requested IVsColorableItem object.

System_CAPS_pubmethodGetColorizer(IVsTextLines)

Iinstantiates a Colorizer class.

System_CAPS_pubmethodGetColorizer(IVsTextLines, IVsColorizer)

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

System_CAPS_pubmethodGetFileExtensions(String)

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

System_CAPS_pubmethodGetFormatFilterList()

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

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetImageList()

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

System_CAPS_pubmethodGetItemCount(Int32)

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

System_CAPS_pubmethodGetIVsDebugger()

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

System_CAPS_pubmethodGetIVsTextMacroHelperIfRecordingOn()

Returns an IVsTextMacroHelper object if macro recording is turned on.

System_CAPS_pubmethodGetLanguageID(IVsTextBuffer, Int32, Int32, Guid)

Returns the language GUID of the language service.

System_CAPS_pubmethodGetLanguageName(String)

Returns the name of the language this language service handles.

System_CAPS_pubmethodGetLanguagePreferences()

Returns a LanguagePreferences object for this language service.

System_CAPS_pubmethodGetLanguageServiceGuid()

Returns the GUID of the language service.

System_CAPS_pubmethodGetLocationOfName(String, String, TextSpan[])

Obsolete method that always returns E_NOTIMPL.

System_CAPS_pubmethodGetNameOfLocation(IVsTextBuffer, Int32, Int32, String, Int32)

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

System_CAPS_pubmethodGetOrCreateSource(IVsTextLines)

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

System_CAPS_pubmethodGetParseResult()

Gets the result of the parse operation.

System_CAPS_pubmethodGetPrimaryViewForSource(Source)

Calls GetPrimaryView on the code window manager for the source.

System_CAPS_pubmethodGetProximityExpressions(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.

System_CAPS_pubmethodGetScanner(IVsTextLines)

Returns a single instantiation of a parser.

System_CAPS_pubmethodGetService(Type)

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

System_CAPS_pubmethodGetSite(Guid, IntPtr)

Returns an unmarshaled pointer to a requested interface.

System_CAPS_pubmethodGetSource(IVsTextLines)

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

System_CAPS_pubmethodGetSource(IVsTextView)

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

System_CAPS_pubmethodGetSource(String)

Returns an existing Source object given a file name.

System_CAPS_pubmethodGetSources()

Returns a collection of Source objects maintained by the language service.

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodInitialize()

Called to initialize the language service.

System_CAPS_pubmethodInvoke(Delegate, Object[])

Called to invoke a task specified by the given delegate.

System_CAPS_pubmethodIsMacroRecordingOn()

Called to determine if macro recording is turned on.

System_CAPS_pubmethodIsMappedLocation(IVsTextBuffer, Int32, Int32)

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

System_CAPS_pubmethodIsSourceOpen(Source)

Determines whether or not the source file is open.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodOnActiveViewChanged(IVsTextView)

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

System_CAPS_pubmethodOnCaretMoved(CodeWindowManager, IVsTextView, Int32, Int32)

Called when the caret has moved.

System_CAPS_protmethodOnChangesCommitted(UInt32, TextSpan[])

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

System_CAPS_pubmethodOnCloseSource(Source)

Called to close the specified Source object.

System_CAPS_pubmethodOnIdle(Boolean)

Called when no other events need to be handled.

System_CAPS_pubmethodOnModeChange(DBGMODE)

Called whenever the debug mode has changed while debugging.

System_CAPS_pubmethodOnParseAborted()

Does nothing.

System_CAPS_pubmethodOnParseComplete(ParseRequest)

Called when a background parse has been completed.

System_CAPS_pubmethodOpenDocument(String)

Opens the specified file.

System_CAPS_pubmethodParseSource(ParseRequest)

Parses the source based on the specified ParseRequest object.

System_CAPS_pubmethodQueryInvalidEncoding(__VSTFF, String)

Determines if the specified source format is valid or not.

System_CAPS_pubmethodQueryService(Guid, Guid, IntPtr)

Returns the request interface from the specified service.

System_CAPS_pubmethodQueryWaitForAutoOutliningCallback(Int32)

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

System_CAPS_pubmethodRemoveCodeWindowManager(CodeWindowManager)

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

System_CAPS_pubmethodResolveName(String, UInt32, IVsEnumDebugName)

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

System_CAPS_pubmethodScrollToEnd(IVsTextView)

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

System_CAPS_pubmethodScrollToEnd(IVsWindowFrame)

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

System_CAPS_pubmethodSetSite(Object)

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

System_CAPS_pubmethodSetUserContextDirty(String)

Marks the user context as dirty in the specified source buffer.

System_CAPS_pubmethodSynchronizeDropdowns()

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

System_CAPS_pubmethodToString()

(Inherited from Object.)

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

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

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

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

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIVsFormatFilterProvider.CurFileExtensionFormat(String, UInt32)

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

System_CAPS_pubinterfaceSystem_CAPS_privmethodIVsFormatFilterProvider.GetFormatFilterList(String)

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

System_CAPS_pubinterfaceSystem_CAPS_privmethodIVsFormatFilterProvider.QueryInvalidEncoding(UInt32, String)

Determines if the specified source format is valid or not.

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

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

NameDescription
System_CAPS_pubmethodQueryService(Guid)

Overloaded. Gets a service exposed by a service provider based on its service type.(Defined by PackageUtilities.)

System_CAPS_pubmethodQueryService<TService>()

Overloaded. Gets a service exposed by a service provider based on its service type.(Defined by PackageUtilities.)

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.

Return to top
Show: