How to create a new language for use in Visual Studio

こ雲淡風輕ζ 提交于 2019-11-26 23:30:30
James Kovacs

I would take a look at another language that has already done the legwork of integrating with Visual Studio. A great example is Boo. The language and Visual Studio integration are open source. So you can take a look at exactly what they had to do.

The Boo Syntax Highlighting for VS2010 includes some recommended links on its homepage, which I'll copy for easy reference:

Brian

Regarding the Visual Studio aspects, what you need is a "language service", which is the entity that handles colorizing, intellisense, etc. for a given file extension/type.

For an intro, see this article
And for a code sample see here

Regarding parsing, there are lots of technologies, and I won't offer an opinion/advice.

Beware, there is a fair amount of work involved, although in my opinion it is much more straightforward in VS2010 than in previous versions of Visual Studio to provide this kind of extension.

See also

Visual Studio 2010 Extensibility, MPF and language services

I wrote a VS Language Service using this article as my basis: http://www.codeproject.com/KB/recipes/VSLanguageService.aspx

It wasn't too bad if you have a basic handle on Grammars.

There is a sample in the VS SDK that shows most of the features you are looking for.

I was using VS with own language and desperately needed a syntax highlight. I built mine based on this tutorial: https://mattduffield.wordpress.com/2012/07/31/writing-a-brightscript-syntax-highlight-extension-for-visual-studio-2010/

I know the tutorial is in VS2010. I made mine in VS2012 with no or very small hiccups. (also worked in VS2013) Recently I changed to VS2015 and the solution can be edited, built with no problem.

I found this very useful collection of recent samples for Visual Studio 2013 SDK: http://blogs.msdn.com/b/vsx/archive/2014/05/30/vs-2013-sdk-samples-released.aspx

It also contains the recent version of the OokLanguage which sounds promising.

We used ANTLR 4 to parse our language which works like a charm and allows direct interaction with C# code. Can totally recommend it.

As mentioned in other answers, the most interesting code sample is the Ook language extension for the latest version of Visual Studio (2017 at the time of writing).

For VS 2015 see the sample in the VS2015 branch.

In order to install the SDK for 2015 or later, you need to rerun the VS setup. In 2015 it's called "Visual Studio Extensibility Tools Update 3".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!