Click here to Skip to main content
13,143,008 members (54,747 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


5 bookmarked
Posted 13 Feb 2012

VS Spell Check Extension - using Roslyn

, 13 Feb 2012
Rate this:
Please Sign up or sign in to vote.
VS Spell Check Extension - using Roslyn

A couple of months ago, Microsoft published the Roslyn CTP which gives us an inside view on the Compilers view to our code. This also comes with project templates for creating CodeIssues and CodeActions (These are code suggestions/actions that are available to the coder in the IDE).

Since I read about this, it interested me a little, and wanted to play around with this. Since I've been programming in Java at home lately due to a course I'm taking at the university, I realized that one of the nice features that IntelliJ has is that it gives you suggestions on spelling mistakes you made on variable names (because this is one of the most annoying things I see in code and I truly believe makes it harder to maintain), so I thought I'd try to implement this in VS as an extension.

It was really simple to do so.

I just created a CodeIssue project:

With the ExportSyntaxNodeCodeIssueProvider attribute, you can tell it to execute the code only on variable declarations:

Split each variable name into separate words (most variables, at least when I write code looks like this "var myReceivedFilesList" so I separate them by case):

public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxNode node, 
                                        CancellationToken cancellationToken = new CancellationToken())
    var variable = node as VariableDeclarationSyntax;
    if (variable != null)
        var nodes = variable.ChildNodes().Where(x => x.Kind == SyntaxKind.VariableDeclarator);

        foreach (var syntaxNode in nodes)
            var fullVariableName = syntaxNode.GetFirstToken().ValueText;

            var wordsInVariableName = fullVariableName.SplitToWords();
            if (wordsInVariableName != null)
                var correctSpelling = CheckAndCorrectSpelling(wordsInVariableName);

                if (correctSpelling != null)
                    yield return new CodeIssue(CodeIssue.Severity.Info, 
                    "Possible Typo ?\nMaybe you meant : " + correctSpelling);

And viola! You have the spell check feature on variable names in your VS IDE:

For the spell check, I used the NHunspell project (This is the .NET wrapper to the OpenOffice dictionary).

I put the code up on Google code so you can take a look at it, and who knows, maybe even contribute to it... :)

I don't know if this is production-worthy code, I didn't even check performance or if it slows down the IDE. This was just a small learning experience for me. Maybe if I have some more free time, and good ideas, I'll add to it more features in the future...


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Gilly Barr
Web Developer
Israel Israel
Started programming e-commerce sites with PHP & MySQL at the age of 14. Worked for me well for about 5 years.

Transfered to C# &, while serving in the IDF.
Worked on the 'Core Performance' Team at (Sears Israel)
Currently working at

Check out my blog!
or my twitter

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 13 Feb 2012
Article Copyright 2012 by Gilly Barr
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid