Vsx language service series (2) -- Starting from a classic example

Source: Internet
Author: User
ArticleDirectory
    • Host package
    • Language Service
    • Language Core

 

Preparations

I plan to introduce a complete example in this article:Managedpc3This example is included in the SDK. Install the SDK before debugging. In samples of Microsoft Visual Studio 2008 SDK, find this example and open it in Visual Studio:

 

Debugging

After opening, you can compile and debug. This is an example of the integration mode. By default, the language service package is loaded in the lab environment, so you will see the following results:

In fact, our package has not been loaded yet. The package of language service is loaded only when the file with a specific suffix is opened in. The suffix registered in this example is ". py", which is a semi-finished language service in C language.

Open. ,... \ Local \ vssdk_9.0_1.1 \ example. managedmyc_f3d35f91 \ testfiles you can find this path and two test files in the project. Then open them. Now I open one of them:

After opening, it will be like this:

We can see that this is a section of CCodeIDE highlights some keywords for us and has specific colors for annotations. If you try to write some code, you will find that, it also supports matching of parentheses and even error prompts.

This example shows the power of the Language Service. The functions mentioned above are implemented by the Language Service.

 

Initial look code host package

Any one or more services can be integrated into vs in the form of packages, and language services are no exception. In fact, language services must be extended in this way. In the project, findPackage. CSThe Code is as follows:

[Microsoft. visual Studio. shell. packageregistration (usemanagedresourcesonly = true)] [Microsoft. visual Studio. shell. defaultregistryroot (@ "SOFTWARE \ Microsoft \ visualstudio \ 9.0exp")] [Microsoft. visual Studio. shell. provideservice (typeof (Babel. languageservice)] [Microsoft. visual Studio. shell. providelanguageextension (typeof (Babel. languageservice), configuration. extension)] [Microsoft. visual Studio. shell. providelanguageservice (typeof (Babel. languageservice), configuration. name, 0, codesense = true, enablecommenting = true, matchbraces = true, showcompletion = true, showmatchingbrace = true, autooutlining = true, enableasynccompletion = true, codesensedelay = 0)] [GUID ("7b98c60000ca1b-4ff4-8638-b0ba4473c68e")] class package: babelpackage {}
 

The following describes the key attributes of the class, which are omitted. If you have any questions, please do your homework:

Attribute

Description

Provideservice

Description of the class that this package provides services

Providelanguageextension

Indicates that this package is a language service and specifies the class and suffix.

Providelanguageservice

Description: This package is a language service, and describes the class and name of the Language Service. The functions provided by this language service include annotations and brackets matching.

We know that most of these attributes of a package are set registration information to be integrated into vs. The same is true for these attributes. It is worth noting that this class has no implementation at all, but inherits from a class calledBabelpackageClass, which isManagedbabelYou canManagedbabelFolderPackage. CSThis class implementsMicrosoft. visualstudio. Shell. PackageMost of them must be overwritten.

 

Language Service

After reading the package, let's see where the most important language service class is and locate it.UsersuppliedFolderLanguageservice. CSThis is the language service we registered, but it seems that the code is simple and surprising! But it inheritsBabellanguageserviceClass, so let's take a look at it.BabellanguageserviceInManagedbabelFolderLanguageservice. CSInherited fromLanguageservice. Why are you bothering me?BabelAh? In fact, to make it easier for developers to develop language services, Microsoft designedManaged package frameworkOfManaged Babel. It is a series of CS files. What you see in the managedbabel folder is the managed Babel file. Microsoft does not recommend us to modify them, but my experience is that we must modify the code to make our unique features. However, we recommend that you keep the original files when modifying them, you only need to modify the copies of them in the project.

Let's get down to the truth, thisBabellanguageserviceThe code is not very small. I don't want to explain it now. So far, we must clarify the problem that language service requires a package to carry, and the package must inherit from Microsoft. visual Studio. shell. package; language service requires a class that inherits from Microsoft. visual Studio. package. languageservice; Microsoft provides a file set called managed babel to make it easier for us to compile language services, which can be used when developing language services.

 

Language Core

You may have noticed two more files: lexer. Lex and parser. Y in the generated folder. That's right! Two very strange files are not reflected in their suffixes. When you see the code in it, you will hardly understand it (unless you have worked in a compiler or parser ). But don't worry, I will introduce the compilation of these two files in detail in the following chapters in combination with Microsoft documents, because in actual development, the time spent on these two files will account for more than 80% of the total development! The only pity is that Microsoft did not implement language services for these two files! Haha!

 

Summary

In this section, we have successfully debuggedManagedpc3And understand the basic components of the Language Service.Managed BabelIs a series of files to facilitate our integration of language services, and also a glimpse of the. Lex and. y files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.