提交 2d39a70f 编写于 作者: V vepanimas

Fixed review concerns for CS8345 code fix

上级 856be78a
......@@ -800,7 +800,7 @@ internal class CSharpFeaturesResources {
}
/// <summary>
/// Looks up a localized string similar to Make ref struct.
/// Looks up a localized string similar to Make &apos;ref struct&apos;.
/// </summary>
internal static string Make_ref_struct {
get {
......
......@@ -587,6 +587,7 @@
<comment>{Locked="using"} "using" is a C# keyword and should not be localized.</comment>
</data>
<data name="Make_ref_struct" xml:space="preserve">
<value>Make ref struct</value>
<value>Make 'ref struct'</value>
<comment>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</comment>
</data>
</root>
......@@ -34,27 +34,27 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
var structDeclaration = FindContainingStruct(root, span);
// CS8345 could be triggered when struct is already marked with `ref` but a property is static
if (structDeclaration != null && !structDeclaration.Modifiers.Any(m => m.IsKind(SyntaxKind.RefKeyword)))
if (structDeclaration != null && !structDeclaration.Modifiers.Any(SyntaxKind.RefKeyword))
{
context.RegisterCodeFix(
new MyCodeAction(
CSharpFeaturesResources.Make_ref_struct,
c => FixCodeAsync(context.Document, context.Span, c)),
new MyCodeAction(c => FixCodeAsync(document, span, c)),
context.Diagnostics);
}
}
public override FixAllProvider GetFixAllProvider()
{
return WellKnownFixAllProviders.BatchFixer;
// The chance of needing fix-all in these cases is super low
return null;
}
private async Task<Document> FixCodeAsync(Document document, TextSpan span, CancellationToken c)
private async Task<Document> FixCodeAsync(Document document, TextSpan span, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(c).ConfigureAwait(false);
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var gen = SyntaxGenerator.GetGenerator(document);
var structDeclaration = FindContainingStruct(root, span);
var newStruct = UpdateStructDeclaration(document, structDeclaration);
var newStruct = gen.WithModifiers(structDeclaration, gen.GetModifiers(structDeclaration).WithIsRef(true));
var newRoot = root.ReplaceNode(structDeclaration, newStruct);
return document.WithSyntaxRoot(newRoot);
......@@ -68,16 +68,12 @@ private StructDeclarationSyntax FindContainingStruct(SyntaxNode root, TextSpan s
return member.GetAncestor<TypeDeclarationSyntax>() as StructDeclarationSyntax;
}
private SyntaxNode UpdateStructDeclaration(Document document, StructDeclarationSyntax decl)
{
var gen = SyntaxGenerator.GetGenerator(document);
return gen.WithModifiers(decl, gen.GetModifiers(decl).WithIsRef(true));
}
private class MyCodeAction : CodeAction.DocumentChangeAction
{
public MyCodeAction(string title, Func<CancellationToken, Task<Document>> createChangedDocument)
: base(title, createChangedDocument, title)
public MyCodeAction(Func<CancellationToken, Task<Document>> createChangedDocument)
: base(CSharpFeaturesResources.Make_ref_struct,
createChangedDocument,
CSharpFeaturesResources.Make_ref_struct)
{
}
}
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
......@@ -93,9 +93,9 @@
<note />
</trans-unit>
<trans-unit id="Make_ref_struct">
<source>Make ref struct</source>
<target state="new">Make ref struct</target>
<note />
<source>Make 'ref struct'</source>
<target state="new">Make 'ref struct'</target>
<note>{Locked="ref"}{Locked="struct"} "ref" and "struct" are C# keywords and should not be localized.</note>
</trans-unit>
<trans-unit id="Remove_unnecessary_casts">
<source>Remove unnecessary casts</source>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册