Develop your own Visual Studio plug-in-a nvelocity highlighting plugin

Source: Internet
Author: User

First of all, there is a project to use the Nvelocity template engine, but with the VS development template, there is no highlight effect, so very inconvenient, because of this, then have their own development of the idea of plug-ins, but in the development of the VS SDK, this information is really very little, There are very few articles that can be consulted online.

But after drawing on a few articles and reference MSDN, finally developed a VS plug-in, currently supports nvelocity syntax highlighting, such as nvelocity keyword #set #parse等等 and nvelocity object $xxx Such format, there are comments # # #* * #这样的, but there's a ditty here

is because we also know that nvelocity template is actually mostly HTML syntax, so if write nvelocity more is to write HTML, so we need to preserve HTML syntax highlighting and HTML smart hints, while also supporting the nvelocity syntax highlighting, If all this is achieved here, it is estimated to be a

Very large project, because I do not have a lot of time, and not so much energy and brain to develop such a tool, so smart alternative path, so this plugin has a bad place, is installed, all the files, such as CS file aspx page HTML pages and so on whenever you encounter nvelocity syntax keywords are back

is highlighted by the syntax, but does not affect the use of, I have personally tried, I estimate that the other pages rarely appear in these grammar keywords, even if there is no impediment

Here is a hint of the idea of development

First you need to install the VS SDK

And your VS needs are in English.

We are developing under Editor class template

The key step, even if the word breaker, even if you scan your code, check the grammar matches with the nvelocity to color

We used the lex participle tool.

%option Unicode, Codepage:raw%{        //User Code is all now in ScanHelper.cs%}%namespaceShane%option Verbose, summary, Noparser, Nofiles, Unicode%{     Public intNextToken () {returnYylex ();}  Public intGetPos () {returnYypos;}  Public intGetLength () {returnYyleng;}%}//=============================================================//=============================================================Number ([0-9])+chars [A-za-z]cstring [A-za-Z_]blank" "Delim [\t\n]word {chars}+singlelinecomment"##"[^\n]*multilinecomment"#*"[^*]*\*(\*| ([^*/]([^*])*\*)) *\ #velocity \$[!]? [{]? [a-za-z\d._]+[}]?Comment {multilinecomment}|{Singlelinecomment}keyword #Set|#foreach|#if| #elseif | #else | #include | #parse | #macro | #even | #odd | #each | #end | {velocity}%%{keyword}return(int) NvelocityEditor.NvelocityTokenType.Keyword; {Comment}return(int) NvelocityEditor.NvelocityTokenType.Comment;%%

At the same time, one thing to note is that

Participle, it is best not to first color all the words, this will overwrite the original HTML syntax

usingSystem.ComponentModel.Composition;usingSystem.Windows.Media;usingMicrosoft.VisualStudio.Text.Classification;usingMicrosoft.VisualStudio.Utilities;namespacenvelocityeditor{[Export (typeof(editorformatdefinition))] [Classificationtype (Classificationtypenames="Nvelocitytext")] [Name ("Nvelocitytext")] [Uservisible (true)] [Order (Before=Priority.high)]Internal Sealed classnvelocitytextformatdefinition:classificationformatdefinition { Publicnvelocitytextformatdefinition () { This. DisplayName ="nvelocity Text";  This. Foregroundcolor =Colors.brown; }} [Export (typeof(editorformatdefinition))] [Classificationtype (Classificationtypenames="nvelocitycomment")] [Name ("nvelocitycomment")] [Uservisible (true)] [Order (Before=Priority.high)]Internal Sealed classnvelocitycommentformatdefinition:classificationformatdefinition { Publicnvelocitycommentformatdefinition () { This. DisplayName ="Nvelocity Notes";  This. Foregroundcolor =Colors.green; }} [Export (typeof(editorformatdefinition))] [Classificationtype (Classificationtypenames="Nvelocitykeyword")] [Name ("Nvelocitykeyword")] [Uservisible (true)] [Order (Before=Priority.high)]Internal Sealed classnvelocitykeywordformatdefinition:classificationformatdefinition { Publicnvelocitykeywordformatdefinition () { This. DisplayName ="nvelocity Keywords";  This. Foregroundcolor =Colors.black;  This. BackgroundColor =Colors.yellow; }    }}

Plugin: Nvelocityeditor.vsix

Thank you for reading, hope to help you .....

Develop your own Visual Studio plug-in-a nvelocity highlighting plugin

Related Article

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.