Skip to content

Commit 6bbefac

Browse files
authored
Merge pull request #960 from MicrosoftDocs/gewarren-editorconfig
Added troubleshooting section for editorconfig files
2 parents 8b62794 + 8ccf772 commit 6bbefac

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

docs/ide/create-portable-custom-editor-options.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Create portable, custom editor settings with EditorConfig | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "10/18/2017"
4+
ms.date: "10/27/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.tgt_pltfrm: ""
@@ -24,14 +24,19 @@ Settings in EditorConfig files enable you to maintain consistent coding styles a
2424

2525
Coding conventions you use on your personal projects may differ from those used on your team's projects. For example, you might prefer that when you're coding, pressing the Tab key adds a TAB character. However, your team might prefer that indenting adds four space characters instead of a TAB character. EditorConfig files resolve this problem by enabling you to have a configuration for each scenario.
2626

27-
Because the settings are contained in a file in the codebase, they travel along with that codebase. As long as you open the code file in an EditorConfig-compliant editor, the text editor settings are implemented. For more information about EditorConfig files, see the [EditorConfig.org](http://editorconfig.org/) website. If you edit a lot of .editorconfig files, you may find the [EditorConfig Language Service](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.EditorConfig) extension helpful.
27+
Because the settings are contained in a file in the codebase, they travel along with that codebase. As long as you open the code file in an EditorConfig-compliant editor, the text editor settings are implemented. For more information about EditorConfig files, see the [EditorConfig.org](http://editorconfig.org/) website.
2828

2929
## Override EditorConfig settings
30-
When you add a .editorconfig file to a folder in your file hierarchy, its settings apply to all applicable files at that level and below. To override EditorConfig settings for a particular project or codebase and use different or overriding values than the top-level .editorconfig file, just add a .editorconfig file to the level you want to change.
30+
When you add a .editorconfig file to a folder in your file hierarchy, its settings apply to all applicable files at that level and below. To override EditorConfig settings for a particular project or codebase such that it uses different conventions than the top-level .editorconfig file, just add a .editorconfig file to the root of your codebase's repo or project directory. Make sure to put the ```root=true``` property in the file so Visual Studio doesn't look for any .editorconfig files further up the directory structure. The new .editorconfig file settings will apply to the level in which it is located and files in any subdirectories.
31+
32+
```
33+
# top-most EditorConfig file
34+
root = true
35+
```
3136

3237
![EditorConfig hierarchy](../ide/media/vside_editorconfig_hierarchy.png)
3338

34-
The new .editorconfig file settings will apply to the level in which it is located and all its subfiles.
39+
EditorConfig files are read top to bottom, and the closest EditorConfig files are read last. Conventions from matching EditorConfig sections are applied in the order they were read, so conventions in closer files take precedence.
3540

3641
## Supported settings
3742
The editor in Visual Studio supports the following from the core set of [EditorConfig properties](http://editorconfig.org/#supported-properties):
@@ -47,6 +52,9 @@ In addition, it supports the [.NET code style conventions](../ide/editorconfig-c
4752

4853
EditorConfig settings are supported in all Visual Studio-supported languages except for XML.
4954

55+
## IntelliSense
56+
Visual Studio provides limited IntelliSense for editing .editorconfig files. If you edit a lot of .editorconfig files, you may find the [EditorConfig Language Service](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.EditorConfig) extension helpful.
57+
5058
## Example
5159
Here is an example that shows the indent state of a C# code snippet before and after adding a .editorconfig file to the project. The **Tabs** setting in the **Options** dialog box for the Visual Studio text editor is set to produce space characters when you press the **Tab** key in your code.
5260

@@ -65,10 +73,26 @@ Now, when you press the **Tab** key, you get tab characters instead of spaces.
6573
![TAB adds Tab character](../ide/media/vside_editorconfig_tab.png)
6674

6775
> [!NOTE]
68-
> Adding a .editorconfig file to your project or codebase will not convert the existing styles to the new ones, it will only apply to newly-added lines. If you remove a .editorconfig file from your project or codebase, you must reload the code file(s) for the editor settings to revert back to global settings. Any errors in .editorconfig files are reported in the Error window in Visual studio.
76+
> Adding a .editorconfig file to your project or codebase will not convert the existing styles to the new ones, it will only apply to newly-added lines. If you remove a .editorconfig file from your project or codebase, you must reload the code file(s) for the editor settings to revert back to global settings. Any errors in .editorconfig files are reported in the Error List window in Visual studio.
6977
70-
## Support EditorConfig for your language service
78+
## Troubleshooting EditorConfig settings
79+
If there is an EditorConfig file anywhere in the directory structure at or above your project's location, Visual Studio will apply the editor settings in that file to your editor. In this case, you may see the following message in the status bar:
80+
81+
**"User preferences for this file type are overridden by this project's coding conventions."**
82+
83+
This means that if any editor settings in **Tools**, **Options**, **Text Editor** (such as indent size, tab size, indent style — tabs or spaces, or coding conventions such as the use of `var`) are specified in an EditorConfig file at or above the project in the directory structure, the conventions in the EditorConfig file will override the settings in Options. You can control this behavior by toggling the **Follow project coding conventions** option in **Tools**, **Options**, **Text Editor**. Unchecking the option will turn off EditorConfig support for Visual Studio.
7184

85+
![Tools Options - follow project coding conventions](media/coding_conventions_option.png)
86+
87+
You can find .editorconfig files in parent directories by opening a command prompt and running the following command from the root of the disk that contains your project:
88+
89+
```
90+
dir .editorconfig /s
91+
```
92+
93+
You can control the scope of your EditorConfig conventions by setting the ```root=true``` property in the .editorconfig file at the root of your repo or in the directory that your project resides. Visual Studio looks for a file named .editorconfig in the directory of the opened file and in every parent directory. Visual Studio stops searching if the root filepath is reached, or if a .editorconfig file with ```root=true``` is found.
94+
95+
## Support EditorConfig for your language service
7296
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, some language services opt to use an appropriate contextual text view option rather than using global settings for items such as tabs and spaces when a user edits or formats text. In these cases, the language service must be updated to support EditorConfig files.
7397

7498
Following are the changes needed to update a language service to support EditorConfig files, by replacing a global _language-specific_ option with a _contextual_ option:
@@ -112,5 +136,7 @@ textBufferOptions.GetOptionValue(DefaultOptions.TabSizeOptionId)
112136
_or_
113137
textView.Options.GetOptionValue(DefaultOptions.TabSizeOptionId)
114138

115-
## See Also
116-
[Create Portable Custom Editor Options with EditorConfig](create-portable-custom-editor-options.md)
139+
## See also
140+
[.NET code style conventions](../ide/editorconfig-code-style-settings-reference.md)
141+
[EditorConfig.org](http://editorconfig.org/)
142+
[Writing code in the editor](writing-code-in-the-code-and-text-editor.md)
18.7 KB
Loading

0 commit comments

Comments
 (0)