Skip to content

Commit 0e8be00

Browse files
committed
Treat all files as UTF and save it without BOM
1 parent 410a580 commit 0e8be00

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.ComponentModel.Composition;
2+
using Microsoft.VisualStudio.Text.Editor;
3+
using Microsoft.VisualStudio.Utilities;
4+
using Microsoft.VisualStudio.Text;
5+
using System.Text;
6+
7+
namespace VisualRust.ProjectSystem
8+
{
9+
/// <summary>
10+
/// Establishes an <see cref="IAdornmentLayer"/> to place the adornment on and exports the <see cref="IWpfTextViewCreationListener"/>
11+
/// that instantiates the adornment on the event of a <see cref="IWpfTextView"/>'s creation
12+
/// </summary>
13+
[Export(typeof(IWpfTextViewCreationListener))]
14+
[ContentType("text")]
15+
[TextViewRole(PredefinedTextViewRoles.Document)]
16+
internal sealed class EncodingController : IWpfTextViewCreationListener
17+
{
18+
19+
private static readonly Encoding utf8 = new UTF8Encoding(false);
20+
21+
/// <summary>
22+
/// Called when a text view having matching roles is created over a text data model having a matching content type.
23+
/// Instantiates a EncodingController manager when the textView is created.
24+
/// </summary>
25+
/// <param name="textView">The <see cref="IWpfTextView"/> upon which the adornment should be placed</param>
26+
public void TextViewCreated(IWpfTextView textView)
27+
{
28+
var properies = textView?.TextDataModel?.DocumentBuffer?.Properties;
29+
if (properies == null)
30+
return;
31+
32+
ITextDocument textDocument;
33+
bool extracted = properies.TryGetProperty(typeof(ITextDocument), out textDocument);
34+
if (!extracted || textDocument == null)
35+
return;
36+
37+
if (textDocument.FilePath.EndsWith(".rs") || textDocument.FilePath.EndsWith(".toml"))
38+
textDocument.Encoding = utf8;
39+
}
40+
41+
}
42+
}

VisualRust/VisualRust.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
</ItemGroup>
9696
<ItemGroup>
9797
<Compile Include="ProjectSystem\DummyLogger.cs" />
98+
<Compile Include="ProjectSystem\EncodingController.cs" />
9899
<Compile Include="ProjectSystem\GnuDebugLaunchSettingsProvider.cs" />
99100
<Compile Include="ProjectSystem\IDebugLaunchSettingsProvider.cs" />
100101
<Compile Include="ProjectSystem\MsvcDebugLaunchSettingsProvider.cs" />

0 commit comments

Comments
 (0)