Visual studio (2008) integration - intellisense and colourizer - c#

So I'm now about to look at getting visual studio integration working for our port of the Less ruby library: www.dotlesscss.com. This is basically a CSS preprocessor that extends on the CSS language to give you variables, mixins, nested rules etc...
What we want is to have our .Less file type take advantage of VS's intelligence and syntax highlighting. Now as the Less language is pretty much CSS with a few extra niceties, it would seem sensible to extend on the existing VS support for CSS files.
We have started to look at VS SDK and managed to get as far as colouring all text blue (its a start). But before we start looking at the Lexer impl I really want to know if we can somehow extend whats already been done with CSS support.
Any pointers in the right direction would be appreciated.
Chris.

Regardless of whether you choose 2005, 2008, or 2010, you'll face the same choice - you can pick one or the other but in no way can pick both.
Set .less files to open in Visual Studio's CSS editor - as is.
Write a new language service for Visual Studio from the ground up, with a syntax highlighter and IntelliSense, for your language.
If you choose #2, then you'll be writing what's called a language service for Visual Studio, and there are lots of resources here and on the web (my blog has some). Be warned it's a non-trivial task once you get past simple syntax highlighting.

This is straightforward in Visual Studio 2010, which is now in beta 2. The text editor is completely new and is designed to support this scenario. If you dig into the SDK you'll find a number of related examples.
For VS 2008 and earlier, you can't extend an existing editor. You have to provide a completely new editor that happens to duplicate all the functionality of the existing editor.

Related

New / Custom Visual Studio 2013 Language Service -Very Basic

I am not looking to do anything fancy just create a bucket for our internal company Visual Studio projects etc.
I have been through the following resources and it seems the codeplex projects have the same behavior as my tutorial walk throughs which tells me I don't understand / know what to look for / learn exactly.
Said behavior is that when my code or the codeplex code compiles and runs with no issues but I don't see the new language show up??? By show up I am expecting to see it in the New Project dialog under templates.
I started here:
http://msdn.microsoft.com/en-us/library/bb165744.aspx
and though not the best tutorial I feel I got everything correct. It compiles and runs but my new "Language" doesn't show.
So I did some more searching perhaps another tutorial might fill in some gaps I missed and I watched this video for an hour.
http://channel9.msdn.com/Blogs/VSIPMarketing/VSX212-Adding-a-Language-Service-into-Visual-Studio-2010
It's for 2010 but felt 2013 and 2010 close enough that it might help....and while I did learn quite a bit it didn't give me what I was expecting.
Another Google result was this SO post (How to create a new language for use in Visual Studio) from which I downloaded OOK from codeplex. Updated references, upgraded from 2010 to 2013 etc.
It compiles and runs but again my language is not "showing"....which is the behavior I had in my tutorial guided solution.
So what am I doing wrong??
All I really want is a language bucket where we can put our internal snippets, customized project templates etc. The c# editor, intellisense, syntax highlighting, etc. are just fine so don't need to extend those at this point.
If someone could please point me in the right direction I would be grateful.
Thank You

Text file diff library (MS licensed)

Does anyone know if there a way to tap into visual studios diff libraries to extend the functionality of my projects?
I know that there are open source solutions for file diffing that I will consider if I cant find an adequate Microsoft implementation of it. Visual Studio comes with nice diff feature that it uses to compare source files.
I want to use code that is MS licensed. It seems that visual studio fulfills that requirement and has the feature I need.
It seems like this would be a useful extension library that maybe .NET should have in it, or already does?
Any ideas?
The Visual Studio diff window (new to Visual Studio 2012) uses the IDifferenceBufferFactoryService to create the IDifferenceBuffer it displays. From there it uses the ITextDifferencingSelectorService to get the appropriate ITextDifferencingService for each side. From there you'll have to do a good bit of reading to understand the API. :)
If you are creating a Visual Studio 2012 extension, the API you are interested is available in the Microsoft.VisualStudio.Text.Differencing namespace.

How to create a new language for use in Visual Studio

I want to write a new templating language, and I want Visual Studio to "support" it. What I need to know is:
How do I parse my new language?
Given some code in my new template language, how do I translate it into HTML? Right now I'm using regular expressions to parse it token by token, but I don't think this is going to scale very well as the language gets more complicated, and there's no error checking. I've heard of ANTLR but never used it. Would that be the right tool for this job, or is there perhaps something simpler? Ideally I'd like to send any syntax errors to the error window with as much information as possible (line #, type of error) like other languages do.
How do I create a new file type for Visual Studio?
How do I get syntax highlighting?
Can I use the same parser I created in step 1, or is this something entirely different?
How do I get Intellisense?
I'd prefer to write my parser in C#.
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.
Boo Language: https://github.com/boo/boo-lang
Boo Syntax Highlighting for VS2010 (VSX add-in): http://vs2010boo.codeplex.com/
Boo Language Studio (syntax highlighting for VS2008): http://boolangstudio.codeplex.com/
The Boo Syntax Highlighting for VS2010 includes some recommended links on its homepage, which I'll copy for easy reference:
Nice article about "classification" (syntax highligting) in VS 2010: http://dotneteers.net/blogs/divedeeper/archive/2008/11/04/LearnVSXNowPart38.aspx
Examples for VSX add-ins: http://blogs.msdn.com/vsxteam/archive/2009/06/17/new-editor-samples-for-visual-studio-2010-beta-1.aspx
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".

How can I get Visual Studio to error check my code (show the squiggles) without explicitly compiling?

I use Visual Studio (C# Express 2008) occasionally to work with some vendor supplied C# code. I am looking to make my experience with VS more like my experience with Eclipse. I have become accustomed to the way Eclipse handles underlining errors (in java source). When I make an error in my code in Eclipse, it will be underlined right away, and if I fix it, the underline will disappear almost immediately, or at worst, when I save the file. In Visual Studio however, the underline remains until I next build the project.
Is there a setting somewhere I can change so that VS will build every time I save, or even as I am typing? Is this hard to do with C# because it is more complex in some way than Java? Do I need to find someone to buy me the full (non express) version? Also, what is the squiggly underline feature called? I fear this question may have been asked before but I don't know the magic word to search for.
Jason's answer is fine, but a couple additional points:
is this hard to do with C# because it is more complex in some way than Java?
Yes, but that's not relevant. Yes, it is a hard problem to do on-the-fly analysis of any language in the 100 milliseconds between keystrokes. Doing it for C# is probably harder than Java, being that it supports so many more language features than Java.
But our IDE team is a bunch of buff coders who are awesome, so they can handle doing it for C#.
The real issue was that the compiler architecture of C# was not originally designed to do this sort of analysis in realtime; the VB compiler was. And therefore it took rather longer to fix up the semantic analysis engine of the C# compiler to make this feature feasible.
We're continuing to do research into how to rearchitect the compiler to expose more and more of these on-the-fly analysis services in a rich, extensible and compelling way, but this will take some time. It's a big compiler.
what is the squiggly underline feature called?
On the compiler team we call it "the squiggly red underline feature", or "squiggles" for short.
I don't know if marketing has a name for it or not. If they do, it's probably something like "Microsoft SquiggleSense .NET For The Microsoft Visual Studio Suite System 2008"; they seem to like these long names that have "Microsoft" in them twice.
Do you have Visual C# 2008 Express Edition with SP1? SP1 added exactly this feature to Visual Studio 2008 Professional and Visual C# 2008 Express Edition.
From the release notes:
This service pack adds a new Visual C# IDE feature that provides a richer set of error information about your code. Specifically, this feature presents the expression-level errors that occur in open files to you according to your code. These expression-level errors were previously reported only after a build operation.
From Scott Guthrie's release notes:
The C# code editor now identifies and displays red squiggle errors for many semantic code issues that previously required an explicit compilation to identify. For example, if you try to declare and use an unknown type in the C# code-editor today you won't see a compile error until you do a build. Now with SP1 you'll see live red squiggle errors immediately (no explicit compile required):
To turn this option on in VS 2010 use Tools > Options > Text Editor > C# > Advanced > Show live semantic errors
and
VS 2010 use Tools > Options > Text Editor > C# > Advanced >Enter outlining mode when files open
To turn this option on in VS 2010 use Tools > Options > Text Editor > C# > Advanced > Show live semantic errors

Extending the Visual Studio editor

I'm writing an add-in for extending Visual Studio 2008 (adding custom functionality). While doing that I came across a situation where it would be good if I could provide custom messages via tooltips for any line of code.
Doing this IMO requires accessing the VS editor control and by some way displaying the respective tooltip. This might also be visualized like breakpoints that on mouse hovering provide a tooltip message.
Is this implementation possible? If yes, what's the way to go? If not, what similar way do you suggest?
In a recent episode of Hanselminutes, they discussed how much more extensible the VS 2010 editor is going to be. Based on what they said, I think it will be rather difficult (although probably possible) until they introduce that extensibility.
Yes it is. You can add more customization on the code editor of VS 2008, even you can create your own language service with your own intellisense support in VS 2008.
You can do this simply by using VS 2008 SDK, and you can also quickly play with the standalone shell of Visual Studio 2008, and MS SQL Server 2008 Management Studio is one example of customized Visual Studio standalone shell.
You can visit MS Visual Studio Extensibility:
http://msdn.microsoft.com/en-us/vsx/default.aspx
And lots of videos on VS 2008 SDK:
http://msdn.microsoft.com/en-us/vsx/bb507746.aspx#extensibility
You should take a look at Resharper and work out whether your add-in would be better suited to being a Resharper Plug-In. This approach would require your users to buy Resharper, but this sort of thing is exactly what it does.
For example, check out http://stylecopforresharper.codeplex.com/ where this sort of hint/tooltip stuff in Resharper is used to highlight lines of code that have StyleCop issues.

Categories