Skip to content

Commit 89f8197

Browse files
authored
Merge pull request #260 from Vbif/master
Treat all files as UTF8 and save it without BOM
2 parents 410a580 + 2598648 commit 89f8197

File tree

7 files changed

+47
-5
lines changed

7 files changed

+47
-5
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-


VisualRust.Templates/Projects/Application/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[package]
1+
[package]
22
name = "$safeprojectname$"
33
version = "0.1.0"
44
authors = ["$username$"]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
fn main() {
1+
fn main() {
22
println!("Hello, world!");
33
}

VisualRust.Templates/Projects/Library/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[package]
1+
[package]
22
name = "$safeprojectname$"
33
version = "0.1.0"
44
authors = ["$username$"]

VisualRust.Templates/Projects/Library/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(test)]
1+
#[cfg(test)]
22
mod tests {
33
#[test]
44
fn it_works() {
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)