Compartir a través de


Supporting EditorConfig for your language service

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

EditorConfig files enable you to describe common text editor options, such as indent size, on a per-project basis. To learn more about Visual Studio's support for EditorConfig files, see Create portable editor settings using EditorConfig.

In most cases when you implement a Visual Studio language service, no additional work is needed to support EditorConfig universal properties. The core editor automatically discovers and reads the .editorconfig file when users open files, and it sets the appropriate text buffer and view options. However, for edits such as tabs and spaces, some language services opt to use an appropriate contextual text view option rather than using global settings. In these cases, the language service must be updated to support EditorConfig files.

Following are the changes that are needed to update a language service to support EditorConfig files, by replacing a global language-specific option with a contextual option:

Indent style

Language-specific options Contextual options
Microsoft.VisualStudio.TextManager.Interop.LANGPREFERENCES.fInsertTabs
Microsoft.VisualStudio.Package.LanguagePreferences.InsertTabs
!textBufferOptions.GetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId)
!textView.Options.GetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId)

Indent size

Language-specific options Contextual options
Microsoft.VisualStudio.TextManager.Interop.LANGPREFERENCES.uIndentSize
Microsoft.VisualStudio.Package.LanguagePreferences.InsertTabs.IndentSize
textBufferOptions.GetOptionValue(DefaultOptions.IndentSizeOptionId)
textView.Options.GetOptionValue(DefaultOptions.IndentSizeOptionId)

Tab size

Language-specific options Contextual options
Microsoft.VisualStudio.TextManager.Interop.LANGPREFERENCES.uTabSize
Microsoft.VisualStudio.Package.LanguagePreferences.InsertTabs.TabSize
textBufferOptions.GetOptionValue(DefaultOptions.TabSizeOptionId)
textView.Options.GetOptionValue(DefaultOptions.TabSizeOptionId)

See also