Visual Studio Spell Checker Preview Now Available

Dante Gagne

We know developers like you take pride in your code! Many of the features in Visual Studio are designed to help you write the code you want. Visual Studio helps you ensure your code compiles and can even help with code styling. Now it can even make sure your spelling is accurate. Visual Studio 17.5 preview 3 introduces the first preview of the Spell Checker for C#, C++ and Markdown files.

The Visual Studio spell checker has identified that the identifier "DetailChekkForIssues" has the word "Chekk" misspelled. A context menu offers options for the user to rename the identifier to "DetailCheckForIssues", ignore the spelling issue or disable the spell checker.
The Visual Studio Spell Checker

Getting Started

The feature will be turned on automatically when working with any C#, C++ or Markdown file. Now, when you’re working with any document supported by the spell checker, Visual Studio will mark any words that detects as misspelled words. Visual Studio will also suggest alternate spellings, and help correct them, even doing a contextual rename when those misspellings are identifiers, so your code will still compile. The spell checker can be disabled by unchecking the “Text spell checker” feature under Manage Preview Features. The spell checker can also be enabled or disabled from the menu with the Edit > Advanced > Toggle Text Spell Checker command, or from a button on the main toolbar in Visual Studio.

How do you use it?

When the caret is on a spelling error, the quick actions provide solutions for fixing the spelling mistakes. You can bring up the quick actions with either “Ctrl+.” or “Alt+Enter”. When the context menu comes up, Visual Studio provides three options to handle a spelling issue.

If any of the dictionaries provide spelling suggestions, Visual Studio will provide them. If multiple dictionaries provide suggestions, the suggestions will be grouped by dictionary. For strings and comments, choosing one of these suggestions will do a single, in-place replacement. For identifiers in a C++ or a C# document, accepting a suggestion will perform a Refactor/Rename, updating all instances of the identifier to make sure the code compiles.

The Visual Studio spell checker has detected that the word "Repressents" is incorrectly spelled. When providing suggestions, the suggestions are grouped and the image shows the suggestions provided by the fr-fr dictionary. Another context menu which is collapsed would show suggestions provided by the en-us dictionary.
Suggestions when multiple dictionaries are in use

You can also choose to ignore the spelling issue. By choosing to ignore the issue, Visual Studio will create an exclusion.dic file in your AppData directory on your local machine. Once a word has been ignored, it will be ignored across all instances of Visual Studio for you.

How does it work?

If you’re interested in the details, this section will get into the specifics of how the spell checker works. Many of these behaviors can be customized, and we’ll cover that in the next section. Since C#, C++ and Markdown all use English as the language for their keywords, Visual Studio will always use the “English (United States)” or “en-us” dictionary for spell checking. Visual Studio will also ask the instance of Windows for the display language it’s using, and if it’s not “en-us”, it will use that dictionary as well.

Feedback from early users of this feature informed us that developers wanted to know about errors in the documents they were currently working with. In direct response to this feedback, the spell checker will only scan documents that are open.

This chart below shows some of the heuristics that the spell checker looks at when scanning a code document:

What’s in the code What Visual Studio checks Why?
Hello Hello, hello Always check for both proper and common nouns
HelloWorld Hello, hello, World, world Medial capitals common are used to mark word boundaries
Hello.World Hello, hello, World, world Punctuation is used as a word boundary
_Hello123 Hello, hello Leading or trailing numbers or punctuation is stripped
Hello2World Hello, hello, World, world Medial numbers, like punctuation, is used as word boundary
btnWorld World, world Fragments of 3 characters or less are ignored
helloworld Helloworld, helloworld No indicator to identify word boundaries

Otherwise, we consider the word misspelled and flag the token as a spelling error. This will show up with a severity of “Message” in the Error List with a “SPELL” Code.

The Visual Studio error list, showing two spelling errors. The errors are shown with the "Message" severity and include descriptions of "Spelling error - xaml is not a word" and "Spelling error - jkwa is not a word". The error list also includes the file and line where the error occurs as well as indicating that the Code associated with the error is "SPELL".
Spelling Errors in the Error List

Customizing the Spell Checker

The default behavior is designed to get users started and help with the initial experience. Once users are ready to start working in a collaborative environment, the spell checker has options for customizability.

We chose editorconfig for configuration to allow users to control the spell checker behavior in their repository. By configuring .editorconfig, users can establish coding standards they expect to be followed and maintain consistency that would be difficult through other methods.

Here are the switches you can configure in editorconfig:

spelling_languages = _language_[,_language_]
(Example: = en-us,fr-fr)
  • This lists the languages for Visual Studio to use. In this example, Visual Studio would only use the en-us and fr-fr dictionaries when checking for spelling issues. Note that the fr-fr language pack must be installed on the user’s machine or Visual Studio will incorrectly flag any French words as spelling errors.
spelling_checkable_types = strings,identifiers,comments
(Example: = identifiers,comments)
  • This controls what Visual Studio should check. In this example, Visual Studio would check identifiers and comments for misspelled words but wouldn’t check inside strings.
spelling_error_severity = error OR warning OR information OR hint
(Example: = error)
  • This controls the severity Visual Studio will assign to spelling errors in the error list. In this example, spelling errors will be displayed as errors.
spelling_exclusion_path = absolute OR relative path to exclusion dictionary.
(Example: = .\exclusion.dic)
  • This allows you to create your own exclusion dictionary to specify words you consider to be correctly spelled. In this example, the first time the spell checker is run against any file in the solution, Visual Studio will check for an exclusion.dic file in the same directory as the .sln file (for a C# project) or in the root directory (for a C++ directory). If no file exists, the spell checker will create one. Then, whenever the user chooses to ignore a word, it will be added to this exclusion.dic file. Visual Studio will consider any word that appears in this exclusion.dic file as a correctly spelled word. Note that the exclusion.dic file must be UTF16 with BOM encoding to work correctly.

What do you think?

We’re really excited to hear how the spell checker is helping developers feel better about their code. Features like these come from feedback from our community and we appreciate all the feedback. We’d love to know what you think, and we invite folks to join in the conversation over on Developer Community. Let us know what improvements you feel would help make the spell checker even better. Thanks for being an important part of the Visual Studio family!