支援語言服務的 EditorConfig

EditorConfig 檔案能讓您根據每個專案描述一般文字編輯器選項 (如縮排大小)。 若要深入了解 Visual Studio 對 EditorConfig 檔案的支援,請參閱使用 EditorConfig 建立可攜式編輯器設定

在大部分情況下,當您實作 Visual Studio 語言服務時,並不需要進行任何額外的作業即可支援 EditorConfig 通用屬性。 當使用者開啟檔案時,核心編輯器會自動探索並讀取 .editorconfig 檔案,然後設定適當的文字緩衝區和檢視選項。 然而對於使用定位點和空格這類項目,有些語言服務會選擇適當的內容文字檢視選項,而不使用全域設定。 在這種情況下,您必須更新語言服務才能支援 EditorConfig 檔案。

以下是更新語言服務以支援 EditorConfig 檔案所需的變更,方法是將全域 [特定語言] 選項取代為 [內容] 選項:

縮排樣式

語言特定規格 關聯式選項
Microsoft.VisualStudio.TextManager.Interop.LANGPREFERENCES.fInsertTabs
Microsoft.VisualStudio.Package.LanguagePreferences.InsertTabs
!textBufferOptions.GetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId)
!textView.Options.GetOptionValue(DefaultOptions.ConvertTabsToSpacesOptionId)

縮排大小

語言特定規格 關聯式選項
Microsoft.VisualStudio.TextManager.Interop.LANGPREFERENCES.uIndentSize
Microsoft.VisualStudio.Package.LanguagePreferences.InsertTabs.IndentSize
textBufferOptions.GetOptionValue(DefaultOptions.IndentSizeOptionId)
textView.Options.GetOptionValue(DefaultOptions.IndentSizeOptionId)

定位點大小

語言特定規格 關聯式選項
Microsoft.VisualStudio.TextManager.Interop.LANGPREFERENCES.uTabSize
Microsoft.VisualStudio.Package.LanguagePreferences.InsertTabs.TabSize
textBufferOptions.GetOptionValue(DefaultOptions.TabSizeOptionId)
textView.Options.GetOptionValue(DefaultOptions.TabSizeOptionId)