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.
Namespace: Microsoft.VisualStudio.Package
Assemblies: Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
Syntax
'Dichiarazione
<CLSCompliantAttribute(False)> _
<ComVisibleAttribute(True)> _
Public MustInherit Class LanguageService _
Implements IDisposable, IVsLanguageInfo, IVsLanguageDebugInfo, IVsProvideColorableItems, _
IVsLanguageContextProvider, IServiceProvider, IObjectWithSite, ISynchronizeInvoke, IVsDebuggerEvents, _
IVsFormatFilterProvider
'Utilizzo
Dim instance As LanguageService
[CLSCompliantAttribute(false)]
[ComVisibleAttribute(true)]
public abstract class LanguageService : IDisposable,
IVsLanguageInfo, IVsLanguageDebugInfo, IVsProvideColorableItems, IVsLanguageContextProvider, IServiceProvider,
IObjectWithSite, ISynchronizeInvoke, IVsDebuggerEvents, IVsFormatFilterProvider
[CLSCompliantAttribute(false)]
[ComVisibleAttribute(true)]
public ref class LanguageService abstract : IDisposable,
IVsLanguageInfo, IVsLanguageDebugInfo, IVsProvideColorableItems, IVsLanguageContextProvider, IServiceProvider,
IObjectWithSite, ISynchronizeInvoke, IVsDebuggerEvents, IVsFormatFilterProvider
[<AbstractClassAttribute>]
[<CLSCompliantAttribute(false)>]
[<ComVisibleAttribute(true)>]
type LanguageService =
class
interface IDisposable
interface IVsLanguageInfo
interface IVsLanguageDebugInfo
interface IVsProvideColorableItems
interface IVsLanguageContextProvider
interface IServiceProvider
interface IObjectWithSite
interface ISynchronizeInvoke
interface IVsDebuggerEvents
interface IVsFormatFilterProvider
end
public abstract class LanguageService implements IDisposable, IVsLanguageInfo, IVsLanguageDebugInfo, IVsProvideColorableItems, IVsLanguageContextProvider, IServiceProvider, IObjectWithSite, ISynchronizeInvoke, IVsDebuggerEvents, IVsFormatFilterProvider
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 |
---|---|
A method that returns a LanguagePreferences object. |
|
A method that returns an IScanner object. |
|
A method that parses the source. |
|
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.
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);
}
}
}
Inheritance Hierarchy
System.Object
Microsoft.VisualStudio.Package.LanguageService
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
Microsoft.VisualStudio.Package Namespace