Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I: Visual Studio Syntax Highlighting Extension

Tags:

I want to develop an extension for VS2010 that will allow me make some additional features to syntax-highlighting.

I installed the SDK, how do I start from?

Please give a little snippet (or a link to code) where I can see how to start.

Note: do I have to check the whole block of code, or the SDK tells me on each word what it is, how it's declared etc.?

like image 757
Shimmy Weitzhandler Avatar asked Jul 15 '10 07:07

Shimmy Weitzhandler


People also ask

Does Visual Studio have syntax highlighting?

Syntax highlighting determines the color and style of source code displayed in the Visual Studio Code editor. It is responsible for colorizing keywords like if or for in JavaScript differently than strings and comments and variable names.

How do I enable syntax highlighting?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

How do I find my Visual Studio code extension?

Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (Ctrl+Shift+X). This will show you a list of the most popular VS Code extensions on the VS Code Marketplace.


2 Answers

There's a decent bit of information out there for writing classifiers. I wrote a blog article about it awhile back.

As for samples/code, there's:

  • A project template that ships with the SDK (look under C#->Extensibility)
  • (Brian's answer mentions) The Ook language service
  • A template for writing classifiers (the link is for the source of the template, so you'll have to un-templatize the $foo$ parts)
  • A diff classifier (pretty old)
  • A couple of other classifiers in the various projects on my github page.

The answer to the other part of your question about if the SDK tells you what each word is, the answer is "no", with a few "kinda" caveats. In general, the underlying language models are not exposed, though you can do things like consume the classification information from other classifiers in the hope that they give you enough information; some, like C#, tend to give a good deal of information that may not show up in the IDE in the default fonts and colors settings (check the Tools->Options->Environment->Fonts and Colors settings to see if you want to change may already be there), and others, like VB, tend not to. You can also use things like DTE's CodeModel, but I've never heard of someone having really good experiences with it.

If you want an example of consuming classification information, you can see how this CommentTextTagger.cs (part of a spellchecker extension) does it.

like image 164
Noah Richards Avatar answered Sep 20 '22 17:09

Noah Richards


You might check out

http://code.msdn.microsoft.com/ookLanguage

which has a syntax highlighter in "OokTokenTag.cs" in the C# sample. You do have to parse a whole block of text, of course, but this is not too hard.

(Found that link from http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/657212c1-1685-4ed6-be2f-cbf34fcc5b20 )

like image 36
Brian Avatar answered Sep 20 '22 17:09

Brian