File tree 7 files changed +47
-5
lines changed
7 files changed +47
-5
lines changed Original file line number Diff line number Diff line change 1
-
Original file line number Diff line number Diff line change 1
- [package ]
1
+ [package ]
2
2
name = " $safeprojectname$"
3
3
version = " 0.1.0"
4
4
authors = [" $username$" ]
Original file line number Diff line number Diff line change 1
- fn main ( ) {
1
+ fn main ( ) {
2
2
println ! ( "Hello, world!" ) ;
3
3
}
Original file line number Diff line number Diff line change 1
- [package ]
1
+ [package ]
2
2
name = " $safeprojectname$"
3
3
version = " 0.1.0"
4
4
authors = [" $username$" ]
Original file line number Diff line number Diff line change 1
- #[ cfg( test) ]
1
+ #[ cfg( test) ]
2
2
mod tests {
3
3
#[ test]
4
4
fn it_works ( ) {
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 95
95
</ItemGroup >
96
96
<ItemGroup >
97
97
<Compile Include =" ProjectSystem\DummyLogger.cs" />
98
+ <Compile Include =" ProjectSystem\EncodingController.cs" />
98
99
<Compile Include =" ProjectSystem\GnuDebugLaunchSettingsProvider.cs" />
99
100
<Compile Include =" ProjectSystem\IDebugLaunchSettingsProvider.cs" />
100
101
<Compile Include =" ProjectSystem\MsvcDebugLaunchSettingsProvider.cs" />
You can’t perform that action at this time.
0 commit comments