BT

Syntax Highlighting and IntelliSense support for CMake

| by Jonathan Allen Follow 552 Followers on Oct 10, 2014. Estimated reading time: 4 minutes |

Visual Studio’s support for new languages is quite powerful, but few people have the skill and determination to take advantage of it. David Golub, who brought CMake support to Visual Studio, is one such person.

The feature list for CMake Tools for Visual Studio includes

  • Syntax highlighting for CMake code
  • Member selection list boxes for CMake commands and variables
  • Tool tips giving the parameters to CMake commands
  • Brace matching for CMake code
  • Support for CMake code snippets
  • Context-sensitive help, available by pressing F1 in the Visual Studio editor while the insertion point is over a standard CMake command or variable
  • Access to the CMake GUI and documentation from the Tools menu in Visual Studio

InfoQ: For our readers who don’t know what CMake is, you can tell us what you use it for?

David Golub: CMake is a cross-platform makefile generation tool, used primarily for C/C++ programming. There are a variety of tools used to build C/C++ code on various operating systems, each using its own makefile or project file format. For example, a project may use Visual Studio project files on Windows or GNU makefiles on Linux. CMake provides a language that developers can use to specify the structure of their projects, as well as any configuration steps that must be performed, in a cross-platform manner. The CMake utility is then run to process this code and generate the appropriate makefiles or project files for the platform on which the program is being built.

At the time that I initially developed CMake Tools for Visual Studio, I was working at Organic Motion, which makes, among other products, the 3D motion capture system OpenStage. Although OpenStage only runs on Windows, the source tree is built using CMake both in order to make it easier to port the code to other platforms if the company were to choose to do so in the future and in order to take advantage of CMake’s advanced configuration features, which are in some respects more powerful than raw Visual Studio project files.

InfoQ: How much work went into making your Visual Studio plugin for CMake?

David: I developed CMake Tools for Visual Studio over the course of approximately one year, with development beginning in April 2012 and the first release candidate becoming available in May 2013. I completed the project in the time I had in the evenings and on weekends, as I was available given my professional and personal obligations.

InfoQ: Were there any aspects that were significantly easier or harder than you were expecting?

David: The Visual Studio SDK is incredibly powerful, making it possible for developers to add full support for any programming language to what I believe to be the finest IDE available. However, in some cases the SDK documentation leaves a bit to be desired, and it took a certain amount of experimentation to figure out how to get certain features to work properly. For example, when implementing brace matching, the span objects that Visual Studio receives do not contain the indices of characters in the file but rather the indices of spaces between characters. If you attempt to highlight a single character by providing a span with starting and ending indices that are equal, then it will simply highlight nothing. Figuring out all the intricacies of the Visual Studio SDK was one of the trickiest parts.

InfoQ: What was the most difficult part of creating the plugin?

David: Parsing code for IntelliSense is different from parsing code in a compiler. The purpose of a compiler is to take syntactically valid source code and produce an executable. If the code being compiled has syntax errors, the compiler will produce the appropriate error messages and go no further. IntelliSense, on the other hand, must function while the programmer is typing. At any particular time that it is triggered, it is more likely than not that the code in the editor will not form a syntactically valid program. Also, IntelliSense parsing needs to be fast; developers expect it to appear instantaneously as they are typing. I addressed these challenges by writing a set of parsing functions that extract the information needed to respond to various IntelliSense triggers without constructing an abstract syntax tree.

David Golub is a software engineer at MongoDB, where he is a member of the MongoDB Management Service team and serves as its Windows specialist. Prior to starting at MongoDB, he studied computer science at Yale and Columbia and then worked at Organic Motion from 2012 to 2013. He also runs the web site Greater New York Roads and enjoys walking and exploring interesting places that are off the beaten path.

CMake Tools for Visual Studio is offered under the Microsoft Reciprocal License (Ms-RL).

To suggest other open source projects that should be highlighted on InfoQ, contact Jonathan Allen at jonathan@infoq.com.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT